Repository navigation
utilery@0.3.0
Minor Changes
-
2ffeb62- Added newpathExists,readJsonFileSafeandreadFilesInDirectorySafeserver utilities: check whether a path exists, and read a JSON file or all files of a directory, gettingnullwhen it does not exist -
07e9ad8- Added new string utilities:levenshteinDistanceandfindClosestString(levenandclosestMatchfromleven)substringBefore,substringAfter,substringBeforeLastandsubstringAfterLastunquoteandstringByteLengthdecodeUriComponentSafe(decodeUriComponentfromdecode-uri-component) andsplitOutsideQuotes(splitfromsplit-string)
-
02db2b7- Added newfindExecutableandfindExecutableSyncutilities (whichfromwhich, givingundefinedinstead of throwing), a newquoteShellArgumentutility (quoteForShellfrompuka) and a newisProcessAliveutility -
1d699b1-colorsreturns plain text when colors are not supported (output that is not a terminal,NO_COLOR,FORCE_COLOR=0), and a newisColorSupportedutility tells whether they are -
5c043e8- Added a newsemvergroup for semantic versions:compareSemver,isSemverInRange,isValidSemverandparseSemver(compare,satisfies,isValidandtryParsefromverkit), and theParsedSemvertype -
14f9bbc- Added a newbitwisegroup for bit flags and other bit manipulation of 32-bit integers. Bit indexes are typed asBitIndex(an integer from 0 to 31), so out-of-range literals and enum members fail at compile time, andisBitIndexchecks dynamic numbers:BitIndex,isBitIndex,isBitSetandindexesOfSetBits- from
@thi.ng/binary:setBit(bitSet, orbitClearwhenfalseis passed)clearBit(bitClear)toggleBit(bitFlip)countSetBits(popCount)countTrailingZeroBits(ctz32)rotateBitsLeft(rotateLeft) androtateBitsRight(rotateRight)toInt32(u32i32) andtoUint32(i32u32)
-
54f7fff- Added a newcreateSeededRandomutility: a seededMath.randomreplacement from a number or a string seed, for reproducible results -
9db3b5c- Added a newglobgroup:globToRegex,isGlobMatchandisGlobPattern(makeRe,isMatchandscanfrompicomatch), andcreatePathFilter, a filter fromincludeandexcludepatterns -
161bee0- Added a newgetBuiltinModuleutility: a typedprocess.getBuiltinModulethat givesundefinedoutside Node.js -
80150d3- Renamed the package from@andreww2012/unutilstoutilery, so install it and import fromutileryinstead -
a6d367d-arrayShuffle,arraySample,random,randomIntInclusiveandrandomIntExclusiveget arandomoption for another generator, like one fromcreateSeededRandom -
d8b0c25- Added a newparseNpmPackageSpecifierutility (parsefromparse-package-name) that splits a specifier like@scope/package@1.2.3/sub/pathinto the name, the version and the path -
2eb3659-createSingletonPromiseno longer keeps a rejection by default, so the next call tries again (pass{cacheRejections: true}for the old behavior), and gets attlMsoption -
8de06c0- Added new utilities:downloadFilein a newbrowsergroup: saves a string, bytes, aBlob, afetchresponse or a stream as a file, like a download link, or through a "Save as" dialog in browsers that support itformatDateForFileName: formats a date and time for file names, like2026-10-25_14-30-05, with a choice of precision, UTC and separators
-
42e7cec- Added newfindUpandfindUpSyncutilities (findUpandfindUpSyncfromfind-up-simple) that find a file or directory in parent directories, and a newisPathInsideutility -
60b94fa- Added a newsleepAbortableutility: likesleep, but rejects with the reason of the aborted signal and has anunrefoption to not keep the Node.js process alive -
83b38c1- Added newgetErrorMessageandinteropDefaultutilities: get a message from a caught value of any type, and resolve a module (or a dynamicimport()) to its default export when it has one -
32e6ccc- Updatedremedafrom v2.51.0 to v2.53.0, which affected:arrayMapWithAccumulator:- BREAKING: the callback now gets the source array as its fourth argument instead of the elements processed so far
-
5951301- Added newstripAnsi,getStringWidthandwrapTextutilities (stripAnsi,stringWidthandwrapAnsifromstrip-ansi,string-widthandwrap-ansi): remove ANSI escape codes, measure the terminal width of a string and wrap styled text -
22b4cae- Added a newMaybeReadonlyArraytype: a value or a readonly array of it.generateMailtoLinknow uses it, so its recipient options also accept readonly arrays -
22b4cae- Added a newisArrayutility fromremeda: unlikeArray.isArray, it also narrows readonly arrays -
23be320-omit: a*deep path segment now matches every element of an array or property of an object, e.g.users.*.passwordremovespasswordfrom every user. Deep paths also no longer mutate the input when they go through an array, e.g.omit(object, ['users.0.password']) -
4d59645- Added a newpathgroup for file paths on any platform, withisSafeRelativePathandparseNodeModulesPath.toForwardSlashesmoved there fromstring, so import it fromutilery/pathinstead ofutilery/string -
03565c6- Added newisPromiseLike,isValidDateandisUnsafeObjectKeyutilities -
5d9e54f- Added a newtopologicalSortutility (toposort.arrayfromtoposort) and theCyclicDependencyErrorit throws for a dependency cycle -
c818297- Added a newwithAbortSignalutility that makes a promise reject with the reason of anAbortSignalas soon as it is aborted -
bce739b- Utilities with a newer native counterpart now call it where it is available, with the same results everywhere:mapGetOrInsertandmapGetOrInsertComputedcallMap#getOrInsertandMap#getOrInsertComputed:- BREAKING: so the
has,getandsetmethods of aMapsubclass are not called there
- BREAKING: so the
promiseTrycallsPromise.tryregexEscapecallsRegExp.escape:- BREAKING: now escapes the same characters as
RegExp.escape: also/, the other ASCII punctuation except_, whitespace, line terminators, lone surrogates and a leading ASCII letter or digit. This fixes aSyntaxErroror a wrong match inside[...]with thevflag (like[${regexEscape('a/b')}]or[${regexEscape('a&&b')}]) and right after an escape like\1or\0
- BREAKING: now escapes the same characters as
uint8ArrayToBase64andstringToBase64callUint8Array#toBase64uint8ArrayToHexcallsUint8Array#toHexbase64ToUint8Arrayandbase64ToStringcallUint8Array.fromBase64:- BREAKING: now throw a
SyntaxErrorinstead of aDOMException - BREAKING: now reject incomplete padding (
SGVsbA=), and always ignore ASCII whitespace (some valid strings with it were rejected)
- BREAKING: now throw a
hexToUint8ArraycallsUint8Array.fromHex:- BREAKING: now throws a
SyntaxErrorinstead of anError
- BREAKING: now throws a
-
edc0141- Added newwriteJsonFileandwriteJsonFileSyncutilities (writeJsonFileandwriteJsonFileSyncfromwrite-json-file) that write JSON atomically and keep the indentation of an existing file, and a newgetAppPathsutility (envPathsfromenv-paths) for the data, config and cache directories of an app -
3f4c756-truncategets apositionoption to cut the start or the middle -
6833f78- Added a newisNodeErrorutility that tells whether a caught value is a Node.js system error, optionally with one of the given codes, and narrows its type -
8768aab- Fixed the types ofobjectEntriesUnsafe,objectKeysUnsafeandobjectValuesUnsafe:- BREAKING: the values of optional properties given by
objectEntriesUnsafeandobjectValuesUnsafeincludeundefined, as such a property may be set to it, unless theexactOptionalPropertyTypescompiler option is on - a union of objects gives the keys, entries and values of each member instead of
never - in generic code, the keys can index the object when its type parameter has known keys or an index signature, like
T extends {a: number} - the keys of string enums keep their enum type
- arrays give their index strings and other own keys, like
indexof a regex match, withoutlengthand method names
- BREAKING: the values of optional properties given by
-
10964e7- Added newformatTerminalLink,formatTerminalFileLinkandisTerminalLinkSupportedutilities (hyperlink,linkandsupportsHyperlinksfromclickable-path) for clickable links in terminals -
e3a9fc0- Added newisFile,isDirectoryandisSymlinkutilities and their*Syncversions (isFile,isDirectory,isSymlink, etc. frompath-type), which givefalsefor a missing path, and a newpathExistsSyncutility -
0d9e353- Added newslugifyandcreateUniqueSlugifyutilities, based onslugifyfrom@sindresorhus/slugifyand onany-ascii: URL slugs that are always ASCII, for text in any script, including Chinese, Japanese and Korean, and slugs that never repeat -
5f36e56- Added new utilities:formatBytes(prettyBytesfrompretty-bytes) andformatRelativeTimeparseBoolean(ynfromyn)sanitizeUrl(sanitizeUrlfrom@braintree/sanitize-url) andredactUrlCredentials
-
34e077d- Added newisAbortErrorandisTimeoutErrorutilities: check whether a caught value is an error namedAbortErrororTimeoutError -
6d0acc3- Updatedes-toolkitfrom v1.52.0 to v1.53.0, which affected:assignDefaults:- with
{copy: true}, copies the target like it does with{copy: true, deep: true}, so a target with anullprototype keeps it
- with
ceildeburr:- BREAKING: keeps letters of scripts other than Latin, like Cyrillic, Greek and Hangul, as they are, even with diacritical marks:
deburr('й')gives'й'instead of'и'
- BREAKING: keeps letters of scripts other than Latin, like Cyrillic, Greek and Hangul, as they are, even with diacritical marks:
findObjectKey:- types keys as
Object.keysgives them: numeric keys as strings, without symbol keys
- types keys as
floorfreezeDeepinterpolate:- returns exactly
maxwhentis1, which rounding errors could break before
- returns exactly
isObjectMatchingmapKeysmapRange:- maps the end of the input range to exactly the end of the output range
mergeDeepomit:- shares the other values with the input when it removes a key whose name looks like a path (like
'a.b'), as it does for other keys, instead of copying them
- shares the other values with the input when it removes a key whose name looks like a path (like
onceorderBypicksortBytruncate
Added utilities from the new release:
toSentenceCase(sentenceCase)interpolateInverse(inverseLerp)serializeStable(serialize), which escapes quotes in strings, so they can't make different values give the same stringQueue(Queue)formatQueryString(stringify)
-
52f68c9-withTimeoutpasses anAbortSignalto the function and aborts it on timeout; it rejects with aDOMExceptionnamedTimeoutError, and with the abort reason when itssignalis aborted (instead of only stopping the timer) -
bade937- Added a newfindClosestNumberutility -
63cbf31- Updatedsafe-stable-stringifyfrom v2.5.0 to v3.0.0, which affected:jsonStringifyStable:- BREAKING: now replaces circular references with
"[Circular: N]"instead of"[Circular]", whereNis the depth of the referenced ancestor (0for the root)
- BREAKING: now replaces circular references with
-
17ed0f2- Added a newbytesgroup ofUint8Arrayconversions, Base64 and hex encoding, fromuint8array-extras: -
e11e7f6- Added a newhttpgroup for parsing and formatting HTTP headers:parseRetryAfterparseLinkHeader(Link.parsefromhttp-link-header)parseCacheControlandformatCacheControl(parseandformatfrom@tusbar/cache-control)parseRangeHeader(rangeParserfromrange-parser)getPreferredEncoding(encodingfromnegotiator)
-
18ef481- Added a newnetgroup for IP addresses, based onipaddr.js:isIpv4andisIpv6(IPv4.isValidFourPartDecimalandIPv6.isValid, strict about embedded IPv4 addresses too) andisIpgetIpRange(based onprocess), which tells whether an address is private, loopback, link-local, etc.isLocalhost
-
01f111d- Added a newformatDurationutility frompretty-ms(prettyMilliseconds) that formats milliseconds like'1h 2m 3s'or, in colon notation,'1:02:03', and a newparseColonDurationutility that parses the colon notation back into milliseconds -
1b1f8d3- Added a newpromiseTryutility: likePromise.try, it calls a function and always gives a promise, turning a synchronous throw into a rejection -
bee52e6- Added a newjsonStringifyForHtmlutility (htmlEscapefromhtmlescape) that turns a value into JSON safe to embed in an HTML<script> -
758f540- Added newmemoizeAsync(pMemoizefromp-memoize) andcallAllutilities: memoize an async function without caching rejections, and combine functions into one that calls all of them -
6dabc8e-arrayChunksnow also accepts an array of sizes, making one chunk per size.Infinityas a size collects the rest of the elements, and a literal tuple of sizes gives a tuple of chunks -
4f6604a- Added newarrayIsUnique,arrayFindDuplicatesandarrayToggleutilities: check whether an array has repeated elements, find them, and add or remove a value likeclassList.toggledoes -
49c57d1- Updatedms-tsfrom v1.1.0 to v1.2.0, which affected:ms:- BREAKING: calling it without the duration string as the generic parameter is now an error
Ms
Patch Changes
-
3c88f4a- Updatedarkregexfrom v0.0.12 to v0.0.14, which affected:regexTyped
-
4be25e6- Updatedremedafrom v2.53.0 to v2.54.1 -
057879f- Updatedlossless-jsonfrom v4.3.1 to v4.3.3, which affected:jsonParseLosslessjsonStringifyLosslessNumberLossless
-
75bf10b- Updatedp-memoizefrom v8.0.0 to v9.0.0, which affected:memoizeAsyncMemoizeAsyncOptions
-
676ca73-jsonStringifyAsyncnow matchesJSON.stringifyin more cases:- circular structures are rejected at any depth, instead of resolving with
[object Object]in the output or crashing the process (circular arrays) - functions and symbols are skipped, and
undefined, functions and symbols in arrays becomenull
- circular structures are rejected at any depth, instead of resolving with
-
e8ba0c7- ExportedTruncateOptions, the options type oftruncate -
3423c17- Updatedpretty-msfrom v9.3.1 to v10.0.0, which affected:formatDuration
-
3bdc0f0-regexEscapenow usesescape-string-regexpand also escapes-, so its result is safe inside a character class -
6c8c77b- Updateddevaluefrom v6.0.2 to v6.0.3 -
51d85f2- Rewrote the docs of re-exported utilities, types and their options: they now name our utilities and types instead of the upstream ones, don't mention bundled packages, and show up at call sites, also in parameter hints. Documented the overloads and errors of more utilities -
57ce269-arrayify: a union mixing arrays with other values is now typed member by member, so its tuples keep their own types instead of becoming array elements -
2f0a434- Added the missing license text oftyped-query-selector, whose types the published package includes, toTHIRD_PARTY_NOTICES.md -
e42cff7- Updatedms-tsfrom v1.0.0 to v1.1.0 -
ec23c95- Importing the main entry point orregexno longer adds a globalArkEnvtype to your project. WithskipLibCheck: false, it broke type checking in projects that also use ArkType -
c9c3f1c- Editor hovers now show the results of these utilities and types as single object types, instead of intersections like{a: number} & {b: number}or helper types likePick<...>:assignDefaults,mergeDeep(withmergeValues),omit,pickandswapObjectPropertiesDiscriminatedUnion,NonEmptyObject,OmitDistributed,OmitIndexSignature,PickConditional,PickDistributed,PickIndexSignature,RequireAtLeastOne,RequireExactlyOne,SetNonNullable,StringifiedValuesandTruncateOptions
-
a3d2793- Fixed keys from data or callbacks changing prototypes:deleteByPath:- refuses with
falsea path that steps through an inheritedconstructoror__proto__, or into theprototypeof a function, also with a key that only converts to these names, like["constructor"]:deleteByPath({}, 'constructor.keys')deletedObject.keys, anddeleteByPath({}, 'constructor.prototype.toString')deletedObject.prototype.toString, for the whole program - goes through and deletes own
constructorand__proto__keys like other keys, while it refused an own__proto__key before
- refuses with
- these utilities no longer replace the prototype of the object they build or update with the value of a
__proto__key (or a key that converts to it, like["__proto__"]), whichJSON.parsecan create and a callback can return, but keep the key as an own property:allKeyedassignDefaultswith{deep: true}, or with{copy: true}and such a key in the targetcloneDeepandcloneShallowflattenObjectjsonParseAsyncmapKeys,mapKeysAsync,mapValuesandmapValuesAsyncmergeDeepwith{copy: true}and such a key in the targetobjectAssignandobjectUpdateobjectFromKeysomit, which also removes the key when asked, andpickparseLinkHeader, which also no longer gives a parameter named like an inherited property, such asconstructor, that property as an earlier valuereplaceKeysandtransformKeysDeepsetByPathImmutable, for a__proto__segment of an arraysortKeysswapObjectKeysValues
-
c31b63c- Updateddecode-uri-componentfrom v0.5.0 to v0.5.1, which affected:decodeUriComponentSafe:- a cut-off
%C2and the byte order marks%FE%FFand%FF%FEnow become replacement characters (U+FFFD) in any case of hex digits, not only in upper case
- a cut-off
-
d31458b- Listed the exact versions of all bundled packages in the newinlinedDependenciesfield ofpackage.json -
8feeb0b- Fixed utilities for options set toundefined, which the types allow without theexactOptionalPropertyTypescompiler option, and types for users with that option:- options set to
undefinedwork like missing ones in:jsonStringifyStable.configure, which threw aTypeErrorfor themformatBytes:spaceslugifyandcreateUniqueSlugify:separator,lowercase,decamelizeandpreserveCharacterstruncate:omissionwriteJsonFileandwriteJsonFileSync:detectIndent
- with the compiler option:
undefinedcan be passed ascircularValuetojsonStringifyStable.configureand asindenttowriteJsonFileandwriteJsonFileSync, as documentedobjectUpdateaccepts an optional property of the update for a required property of the target, and rejectsundefinedfor an optional property of the target that doesn't include it
- options set to