npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-scribe

v1.2.0

Published

A collection of utility functions and types for TypeScript projects in Node.js

Downloads

844

Readme

TS-Scribe

npm Module type: ESM

TypeScript utilities for Node.js and Bun. Zero dependencies. Tree-shakeable ESM.

Installation

npm install ts-scribe
bun add ts-scribe

API

Core

| Export | Description | |---|---| | getIn(value, path) | Safely read a nested value via a path array. Supports objects, Maps, and Arrays with full type inference up to 6 levels deep. | | setIn(value, path, newValue) | Immutably set a nested value, creating missing containers along the path. | | memoize(fn, options?) | Wrap a function with an LRU cache. Supports TTL, max entry count, max entry size, error caching, and hit/miss/eviction stats. | | safeJsonParse(text, fallback?) | Parse JSON without throwing. Returns the parsed value or a fallback. | | safeJsonStringify(value, fallback?) | Stringify to JSON without throwing. Handles circular references, BigInt, and non-serializable values. | | jsonByteSize(value, accuracy?) | Measure the byte size of a value's JSON representation. Three accuracy modes: 'exact', 'fast', and 'estimate'. | | parseBoolean(value) | Coerce strings, numbers, and other values to a boolean. | | parseNumber(value) | Coerce strings and other values to a number, or undefined if not parseable. | | pipe(...fns) | Compose functions left-to-right, threading the return value of each as the argument to the next. 0 args returns identity. | | run(fn) | Immediately invoke a function. Useful for scoping inline expressions. |

Array

| Export | Description | |---|---| | arrayChunk(array, size) | Split an array into fixed-size chunks. | | arrayDifference(a, b) | Elements in a not present in b. | | arrayGroupBy(array, key) | Group an array of objects by a property or function. | | arrayIntersection(a, b) | Elements present in both arrays. | | arrayIntersectionDeep(a, b) | Deep equality intersection for arrays of objects. | | arrayPartition(array, predicate) | Split an array into two: elements that satisfy the predicate and those that don't. Supports type guard narrowing. | | arrayPluck(array, key) | Extract a property from each object in an array. | | arrayPowerset(array) | All possible subsets of an array. | | arrayShuffle(array) | Randomly shuffle an array in place using Fisher-Yates. | | arrayUnique(array) | Remove duplicate primitive values. | | arrayUniqueBy(array, key) | Remove duplicate objects by a property or function. | | toArray(value) | Normalize a value to an array. Handles iterables, array-likes, and scalar values. |

Async

| Export | Description | |---|---| | asyncFilter(array, fn, options?) | Filter an array with an async predicate. Fails fast on the first error. Supports concurrency limiting and AbortSignal. | | asyncFilterSettled(array, fn, options?) | Like asyncFilter but collects errors instead of throwing. Returns { results, errors }. | | asyncForEach(array, fn, options?) | Run an async function over each array element in parallel. Fails fast on the first error. Supports concurrency control and AbortSignal. | | asyncForEachSettled(array, fn, options?) | Like asyncForEach but collects errors instead of throwing. Returns { errors }. | | asyncMap(array, fn, options?) | Map an array through an async function. Fails fast on the first error. Supports concurrency control and AbortSignal. | | asyncMapSettled(array, fn, options?) | Like asyncMap but collects errors and replaces failed items with errorValue. Returns { results, errors }. | | asyncPipe(...fns) | Compose sync and/or async functions left-to-right. Each function may return a value or a Promise — the result is always a Promise. | | createAbortError(reason) | Create a standardized AbortError (name: 'AbortError', code: 20) from any value. | | debounce(fn, delay) | Create a debounced version of a function or promise. | | maybe(value) | Maybe monad for chaining operations on values that may be null or undefined. Supports map, filter, else, and catch. | | retry(handler, options?) | Retry a promise-returning function with configurable delays, retry count, and abort signal. | | Semaphore | Class that limits concurrent access to a resource. Acquire and release locks. | | sleep(ms) | Pause execution for a given number of milliseconds. | | timeout(promise, ms, options?) | Wrap any promise with a rejection deadline. Rejects with an AbortError after ms milliseconds. Accepts an optional AbortSignal and custom error message. | | waterfall(tasks) | Run an array of async tasks in sequence. Resolves with the result of the last task. |

Development

| Export | Description | |---|---| | benchmark(fn, options?) | Measure the execution time of a function over multiple iterations. Returns timing stats without changing function behavior. | | createPerfTimer(options?) | Create a high-resolution timer with lap support for measuring code blocks. | | traceFunction(fn, options?) | Wrap a function to log calls, arguments, return values, and execution time without altering its behavior. |

List

| Export | Description | |---|---| | SortedList | A class that maintains elements in sorted order using binary search. Supports custom comparators and duplicate policies. | | WeightedList | A class for weighted random selection. Items with higher weights are more likely to be picked. |

Math

| Export | Description | |---|---| | clamp(value, min, max) | Constrain a number to a range. | | greatestCommonDivisor(...numbers) | Compute the GCD of one or more integers. | | smallestCommonMultiple(...numbers) | Compute the LCM of one or more integers. |

Object

| Export | Description | |---|---| | objectDeepClone(value, options?) | Deep clone using structuredClone with a fallback. Handles Date, RegExp, Map, Set, and circular references. | | objectDeepEquals(a, b) | Deep equality comparison for objects and arrays. Handles circular references. | | objectDeepMerge(...objects) | Deeply merge two or more objects left-to-right into a new object. Plain objects are merged recursively; primitives, arrays (by default), and special types (Date, RegExp, Map, Set, ArrayBuffer, SharedArrayBuffer, typed arrays, Error, etc.) are overwritten by the right-hand value. Use objectDeepMerge.withOptions({ arrayMerge: 'concat' }) to concatenate arrays instead of replacing them. maxDepth (default 50) prevents stack overflow. Handles circular references safely. Fully typed with DeepMerge<A, B>. | | objectDeepFreeze(value) | Recursively Object.freeze an object and all its nested properties. | | objectFlatten(value, prefix?) | Flatten a nested object into dot-notation keys. | | objectMask(value, options) | Recursively replace sensitive values with a masking character. Supports key-based rules, custom predicates, depth limits, and custom mask functions. Handles circular references and special types. | | objectOmitKeys(value, keys) | Return a shallow copy of an object with specified keys removed. | | objectPickKeys(value, keys) | Return a shallow copy of an object with only the specified keys. | | objectPrune(value, options?) | Remove keys with undefined values from an object. Optionally remove nulls and empty values. |

Random

| Export | Description | |---|---| | randomBool(bias?) | Generate a random boolean with an optional bias from 0 to 1. | | randomInt(min, max) | Generate a random integer in a range, inclusive. | | randomSample(array, count?) | Pick one or more random items from an array without replacement. | | randomString(length, charset?) | Generate a random string of a given length with a configurable character set. |

String

| Export | Description | |---|---| | interpolateString(template, data, options?) | Replace {placeholders} in a template string with values from a data object. Supports strict mode, custom delimiters, fallbacks, and value transforms. | | slugify(input, options?) | Convert a string to a URL-friendly slug. Supports transliteration, custom separators, and character filtering. | | toCamelCase(input) | Convert a string to camelCase. | | toDotCase(input) | Convert a string to dot.case. | | toHeaderCase(input) | Convert a string to Header-Case. | | toKebabCase(input) | Convert a string to kebab-case. | | toPascalCase(input) | Convert a string to PascalCase. | | toSnakeCase(input) | Convert a string to snake_case. | | truncate(input, options?) | Truncate a string to a maximum length with configurable ellipsis and word-boundary awareness. |

System

| Export | Description | |---|---| | getEnvironment() | Detect the runtime: returns 'Browser', 'Bun', 'Node', or 'Unknown'. | | isBrowser() | Returns true when running in a browser. | | isNode() | Returns true when running in Node.js. |

Typeguards

| Export | Description | |---|---| | isDefined(value) | Type guard: value is not null, undefined, or NaN. | | isEmptyObject(value) | Type guard: value is an object with no own enumerable keys. | | isEmptyValue(value) | Returns true for null, undefined, NaN, empty strings, empty arrays, and empty objects. | | isNumber(value) | Type guard: value is a finite number or a numeric string. | | isString(value) | Type guard: value is a string primitive or String object. |

Types

Utility types are exported alongside functions and require no additional import path.

| Type | Description | |---|---| | DeepMerge<A, B> | Deeply merge two types, with B taking precedence. Objects merge recursively; arrays have element types unioned. | | DeepMergeTuple<T> | Fold DeepMerge over a tuple of types left-to-right. | | DeepPartial<T> | Recursively make all properties optional. | | DeepReadonly<T> | Recursively make all properties readonly. | | GenericFunction | Type for any callable function. | | Mandatory<T> | Strip null and undefined from all properties. | | Nestable<T> | A type that can contain itself recursively. | | NonNullish | Exclude null and undefined. | | Nullish | null \| undefined. | | OverloadUnion<T> | Convert a union of function types into a single overloaded signature. | | Primitive | Union of string \| number \| boolean \| symbol \| bigint \| null \| undefined. | | Serializable | Values that can appear in valid JSON. | | Simplify<T> | Flatten intersection types for better IDE display. | | SmartPartial<T> | Make a property optional only if its type already includes undefined. | | TypeOfString | Union of valid typeof return strings. | | TypeOfType<T> | Extract the typeof string for a value type. | | UnionToIntersection<U> | Convert a union type to an intersection type. |

Credits

The SortedList and Semaphore implementations are based on work by Shakeskeyboarde.

License

MIT

MIT