Lightweight JavaScript/TypeScript utilities with async helpers, array and string operations
npm install jsn-utils- noop(): void - A no-operation function that does nothing
- ignorePromise(promise: Promise - Helps to suppress unhandled promise rejections
- chunk - Splits array into chunks of the specified size
- chunkStr(str: string, chunkSize: number): string[] - Splits a string into chunks of a specified size
- isObjectEmpty(obj: object): boolean - Checks if the given object is empty (contains no own properties)
- wait(ms: number, signal?: AbortSignal): Promise - Returns a promise that resolves after the specified amount of time in milliseconds or when signal is aborted
- createPromisesCache - deprecated; use createInFlightDeduper instead
- createInFlightDeduper - Creates a deduplicator for in-flight promises or sync functions. Prevents duplicate executions for the same key while a promise is pending. Clears the entry after settlement
- resultify - Executes a function and returns its result as a tuple [value, error]. Works with both sync and async functions. Never throws.
- Monitor class - provides simple methods to monitor execution time of functions:
- static measureFunctionTime(fn: Function): number | Promise
- static autoStart(label: string): Monitor - Creates a new Monitor instance and calls .start(label) on it
- start(label: string)
- mark(label: string, description?: string)
- stop(label: string): MonitorResult
number - mark timestampnumber - difference in milliseconds between start timestamp and mark timestampstring - an optional description of a mark#### MonitorResult
- startTs: number - start timestamp
- stopTs: number - stop timestamp
- totalTime: number - difference between stopTs and startTs
- marks: MonitorMark[] - array of marks (if any)