argbToRgb | color | Converts a 32-bit packed ARGB integer (as used by e.g. Chromium’s Local State profile background_color field) into a CSS rgb() string. The alpha byte (top 8 bits) is read but discarded — the result is always opaque. |
Brand | type | Brands a base type T with a phantom tag B to create a nominal type. Two Brand<string, 'UserId'> and Brand<string, 'Email'> are structurally identical strings at runtime, but TypeScript treats them as distinct types at the call site — preventing accidental mix-ups. Use a const-assertion cast at the creation boundary: ts type UserId = Brand<string, 'UserId'>; const toUserId = (s: string): UserId => s as UserId; |
clone | object | Creates a shallow copy of a value — one level deep, unlike cloneDeep. Unlike a plain { ...value } spread, this correctly reconstructs Date, Map, Set, and arrays instead of producing an empty (or wrong-shaped) plain object for them. Primitives are returned as-is. Any other object (including class instances not listed above) has its own enumerable string keys shallow-copied into a plain object — the same fallback cloneDeep uses, so the two stay consistent for types neither one special-cases. |
combineSortFns | array | Chains multiple sort functions into a single comparator: the first function decides the order unless it reports a tie (0), in which case the next function is tried, and so on. Lets you compose comparators of different kinds — e.g. a boolean-property comparator from createSortByBooleanFn followed by a string-property comparator from createSortByStringFn — which a single multi-key call cannot express, since that coerces every key to the same comparison type. |
createSortByBooleanFn | array | Creates a sort function for objects by a boolean property. Values are coerced with Boolean() before comparing, so null, undefined, 0, and '' behave as false, and any other truthy value behaves as true. |
dedent | string | Strips the common leading whitespace from every line of a multi-line string, and trims a single leading/trailing blank line if present. Lets you write readable, indented multi-line strings in source code (typically template literals) without that indentation leaking into the output. |
DeepGet | type | Resolves the value type at a given Path within T. Returns unknown when any key in Path is not present in the corresponding level of T. An empty path resolves to T itself. A path segment that goes through an optional property keeps the result nullable (V | undefined) instead of degrading to unknown. |
DeepSet | type | Produces the type of T after replacing the value at Path with V. When a key in Path is absent from the corresponding level of T, that level (and everything below it) is added as a new field instead of resolving to never — mirroring how set() creates intermediate objects at runtime. |
escapeRegExp | string | Escapes regular expression metacharacters (. * + ? ^ $ { } ( ) | [ ] \\) in a string so it can be safely embedded in a RegExp pattern. Use this before building a RegExp from untrusted or dynamic input — without it, characters like . or ( change the pattern’s meaning instead of being matched literally. |
flatten | object | Flattens a nested object into a single-level object whose keys are the dot-notation path to each leaf value. The inverse of unflatten. Only plain objects are recursed into — arrays, Date, Map, RegExp, class instances, and empty plain objects {} are kept as opaque leaf values. This keeps flatten/unflatten a clean, invertible pair: arrays can’t be losslessly told apart from plain objects once reduced to dotted keys, so this implementation doesn’t attempt it. Caveat shared by every dotted-path flattening scheme: a key that itself contains a literal . is indistinguishable from real nesting once flattened ({ 'a.b': 1 } and { a: { b: 1 } } both produce { 'a.b': 1 }). |
hexToRgb | color | Parses a hex color string (#rgb, #rgba, #rrggbb, #rrggbbaa — the leading # is optional) into its RGB(A) channels. |
hslToRgb | color | Converts an HSL(A) color into RGB(A). |
isCssColor | guard | Checks whether a value is a syntactically-safe, plain CSS color: a hex color (#rgb, #rgba, #rrggbb, #rrggbbaa), a functional notation (rgb(), rgba(), hsl(), hsla()), or a single-word named color (red, rebeccapurple). Intended to sanitize a color value before interpolating it into inline style/cssText — it does not implement the full CSS color grammar or validate named colors against the real keyword list, it only rejects characters ({, }, ;, “) or shapes that could smuggle extra CSS declarations into the surrounding rule. |
isSet | guard | Checks if a value is a Set instance. |
isWeakMap | guard | Checks if a value is a WeakMap instance. |
isWeakSet | guard | Checks if a value is a WeakSet instance. |
KeysOfType | type | Extracts the keys of T whose values extend V. Optional properties are matched by their non-nullable value type, so an optional string property still counts as a string key. |
Nullable | type | Adds null to a type (T | null). Useful as a shorthand when explicit nullability should be expressed in function signatures or generic constraints. |
Nullish | type | Adds null and undefined to a type (T | null | undefined). Alias of Maybe. |
omitBy | object | Creates a new object without the own enumerable entries for which predicate returns true. Complements omit for when the keys to remove aren’t known ahead of time — omit takes an explicit key list, omitBy takes a predicate. |
OmitByValue | type | Constructs a type by omitting all entries of T whose values extend V. Optional properties are matched by their non-nullable value type, so an optional string property is omitted the same as a required one. |
OptionalKeys | type | Extracts the optional keys of an object type T. |
parseDuration | date | Parses a compact duration string (as produced by formatDuration, e.g. "1h 23m 45s") back into milliseconds. Accepts any combination/order of h/m/s segments, with or without spaces between them ("1h30m" and "1h 30m" both work). A single leading - negates the whole duration, matching formatDuration’s output. Returns null when no valid segment is found. |
parsePropertyPath | object | Parses a dot/bracket-notation property path into an array of string/number key segments — the same notation accepted by get and set. - Dot separators (.) split segments; each segment becomes a string key. - Bracket indices ([n]) become number keys. - A leading . is treated as “current level” and stripped before parsing, so .[0] ≡ [0] and .a.b ≡ a.b. - Empty string (or a bare .) returns [''] (addresses the '' key on the root object). - Consecutive dots (a..b) produce an empty-string segment: ['a', '', 'b']. Results are cached (up to 500 distinct path strings, oldest evicted first) since real-world callers tend to reuse a small, fixed set of literal paths. |
pickBy | object | Creates a new object with only the own enumerable entries for which predicate returns true. Complements pick for when the keys to keep aren’t known ahead of time — pick takes an explicit key list, pickBy takes a predicate. |
PickByValue | type | Constructs a type by picking all entries of T whose values extend V. Optional properties are matched by their non-nullable value type, so an optional string property is picked the same as a required one. |
Prettify | type | Flattens an intersection type into a single readable object type. IDE tooltips for intersections like A & B & C often show the raw intersection instead of the resolved shape. Wrapping with Prettify forces TypeScript to expand and display the fully-resolved type. Distributes over unions, so each member is prettified independently instead of collapsing to their shared keys. |
removeDiacritics | string | Removes diacritical marks (accents) from a string, e.g. 'café' → 'cafe'. Works by Unicode-decomposing each character into its base letter plus combining marks ('é' → 'e' + a combining acute accent), then stripping the marks. Same technique already used internally by slugify. |
replaceOrAppend | array | Returns a new array with the first item matching predicate replaced by item — or item appended at the end if no match is found. The common “upsert into a list” pattern. |
RequiredKeys | type | Extracts the required (non-optional) keys of an object type T. |
rgbToHex | color | Converts an RGB(A) color into a hex color string. r/g/b are clamped to 0-255 and rounded to the nearest integer before formatting. The alpha channel is only appended (as #rrggbbaa) when it is below 1 — fully opaque colors format as the plain 6-digit #rrggbb. |
rgbToHsl | color | Converts an RGB(A) color into HSL(A). h/s/l are rounded to 1 decimal place to avoid floating-point noise. |
settle | promise | Runs an array of promises concurrently and partitions the outcomes instead of rejecting on the first failure, unlike Promise.all. Built on top of Promise.allSettled, but returns fulfilled values and rejection reasons already split apart so callers don’t need to inspect status themselves. |
symmetricDifference | array | Returns the symmetric difference between two arrays: items present in exactly one of the two arrays (in either, but not both). null and undefined are treated as empty arrays. |
toggle | array | Returns a new array with item removed if present, or appended if absent — the common “toggle a selection” pattern. By default, presence is checked with SameValueZero equality (like Array.prototype.includes). Pass key to compare by a derived identity instead — useful for toggling objects by id rather than by reference. |
unary | function | Creates a function that calls fn with only its first argument, discarding any others. Prevents the classic footgun where a callback expecting extra positional arguments is passed directly to Array.prototype.map: ['1', '2', '3'].map(parseInt) silently passes the array index as parseInt’s radix argument, producing [1, NaN, NaN]. |
unescapeHtml | string | Unescapes the HTML entities &, <, >, ", and ' back to &, <, >, ", and '. This is the exact inverse of escapeHtml — it only recognizes the five entities that function produces, not the full HTML entity set (no , no numeric code points beyond ', etc.). |
unflatten | object | Rebuilds a nested object from a single-level object whose keys are dot-notation paths. The inverse of flatten. Uses set internally, so intermediate nodes are always created as plain objects (never arrays — see flatten’s doc for why), and any key segment equal to __proto__, constructor, or prototype is silently rejected (same prototype-pollution guard as set). |
UnionToIntersection | type | Converts a union type to an intersection type: A | B | C → A & B & C. Uses conditional-type distribution and the contravariant position of a function parameter to collapse the union into an intersection. |
unset | object | Removes the value at a dot/bracket-notation path or explicit key array, mutating the object in place. Uses the same path syntax as get/set. A missing intermediate segment is a no-op (nothing to remove), not an error. As with set, any path containing a string segment equal to __proto__, constructor, or prototype is rejected and the object is returned unchanged. The removed key stops appearing in Object.keys/for...in — unlike setting it to undefined, which would keep the key present. |
update | object | Updates the value at a path by applying a function to its current value, creating intermediate objects as needed. Equivalent to set(obj, path, updater(get(obj, path))) in a single call. Uses the same path syntax and type-inference rules as get and set — see those for the full behavior (string vs. PropertyKey[] paths, prototype-pollution guarding, etc.). |
ValueOf | type | Produces a union of all value types of an object type T. |