Package @reatom/utils
@reatom/utils
Interfaces
AbortError
Defined in: packages/core/src/utils.ts:658
Interface extending DOMException for abort-specific error handling. Used to represent errors triggered by AbortController signal aborts.
See
https://developer.mozilla.org/en-US/docs/Web/API/AbortController
Extends
DOMException
Properties
ABORT_ERR
readonlyABORT_ERR:20
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8622
Inherited from
DOMException.ABORT_ERR
cause?
optionalcause:unknown
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
Inherited from
DOMException.cause
code
readonlycode:number
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8590
The code read-only property of the DOMException interface returns one of the legacy error code constants, or 0 if none match.
Deprecated
Inherited from
DOMException.code
DATA_CLONE_ERR
readonlyDATA_CLONE_ERR:25
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8627
Inherited from
DOMException.DATA_CLONE_ERR
DOMSTRING_SIZE_ERR
readonlyDOMSTRING_SIZE_ERR:2
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8604
Inherited from
DOMException.DOMSTRING_SIZE_ERR
HIERARCHY_REQUEST_ERR
readonlyHIERARCHY_REQUEST_ERR:3
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8605
Inherited from
DOMException.HIERARCHY_REQUEST_ERR
INDEX_SIZE_ERR
readonlyINDEX_SIZE_ERR:1
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8603
Inherited from
DOMException.INDEX_SIZE_ERR
INUSE_ATTRIBUTE_ERR
readonlyINUSE_ATTRIBUTE_ERR:10
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8612
Inherited from
DOMException.INUSE_ATTRIBUTE_ERR
INVALID_ACCESS_ERR
readonlyINVALID_ACCESS_ERR:15
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8617
Inherited from
DOMException.INVALID_ACCESS_ERR
INVALID_CHARACTER_ERR
readonlyINVALID_CHARACTER_ERR:5
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8607
Inherited from
DOMException.INVALID_CHARACTER_ERR
INVALID_MODIFICATION_ERR
readonlyINVALID_MODIFICATION_ERR:13
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8615
Inherited from
DOMException.INVALID_MODIFICATION_ERR
INVALID_NODE_TYPE_ERR
readonlyINVALID_NODE_TYPE_ERR:24
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8626
Inherited from
DOMException.INVALID_NODE_TYPE_ERR
INVALID_STATE_ERR
readonlyINVALID_STATE_ERR:11
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8613
Inherited from
DOMException.INVALID_STATE_ERR
message
readonlymessage:string
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8596
The message read-only property of the a message or description associated with the given error name.
Inherited from
DOMException.message
name
name:
"AbortError"
Defined in: packages/core/src/utils.ts:659
The name read-only property of the one of the strings associated with an error name.
Overrides
DOMException.name
NAMESPACE_ERR
readonlyNAMESPACE_ERR:14
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8616
Inherited from
DOMException.NAMESPACE_ERR
NETWORK_ERR
readonlyNETWORK_ERR:19
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8621
Inherited from
DOMException.NETWORK_ERR
NO_DATA_ALLOWED_ERR
readonlyNO_DATA_ALLOWED_ERR:6
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8608
Inherited from
DOMException.NO_DATA_ALLOWED_ERR
NO_MODIFICATION_ALLOWED_ERR
readonlyNO_MODIFICATION_ALLOWED_ERR:7
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8609
Inherited from
DOMException.NO_MODIFICATION_ALLOWED_ERR
NOT_FOUND_ERR
readonlyNOT_FOUND_ERR:8
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8610
Inherited from
DOMException.NOT_FOUND_ERR
NOT_SUPPORTED_ERR
readonlyNOT_SUPPORTED_ERR:9
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8611
Inherited from
DOMException.NOT_SUPPORTED_ERR
QUOTA_EXCEEDED_ERR
readonlyQUOTA_EXCEEDED_ERR:22
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8624
Inherited from
DOMException.QUOTA_EXCEEDED_ERR
SECURITY_ERR
readonlySECURITY_ERR:18
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8620
Inherited from
DOMException.SECURITY_ERR
stack?
optionalstack:string
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078
Inherited from
DOMException.stack
SYNTAX_ERR
readonlySYNTAX_ERR:12
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8614
Inherited from
DOMException.SYNTAX_ERR
TIMEOUT_ERR
readonlyTIMEOUT_ERR:23
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8625
Inherited from
DOMException.TIMEOUT_ERR
TYPE_MISMATCH_ERR
readonlyTYPE_MISMATCH_ERR:17
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8619
Inherited from
DOMException.TYPE_MISMATCH_ERR
URL_MISMATCH_ERR
readonlyURL_MISMATCH_ERR:21
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8623
Inherited from
DOMException.URL_MISMATCH_ERR
VALIDATION_ERR
readonlyVALIDATION_ERR:16
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8618
Inherited from
DOMException.VALIDATION_ERR
WRONG_DOCUMENT_ERR
readonlyWRONG_DOCUMENT_ERR:4
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts:8606
Inherited from
DOMException.WRONG_DOCUMENT_ERR
Fn()
Defined in: packages/core/src/utils.ts:8
Generic function type representing any function that takes any parameters and returns any value. Used throughout Reatom for typing function parameters and callbacks.
Fn(…
params):any
Defined in: packages/core/src/utils.ts:9
Generic function type representing any function that takes any parameters and returns any value. Used throughout Reatom for typing function parameters and callbacks.
Parameters
params
…any[]
Returns
any
Newable<ReturnType>
Defined in: packages/core/src/utils.ts:99
Represents a constructor function that can be instantiated with the new operator.
Type Parameters
ReturnType
ReturnType
The type of object that will be created when instantiated
Constructors
Constructor
new Newable(…
params):ReturnType
Defined in: packages/core/src/utils.ts:100
Parameters
params
…any[]
Returns
ReturnType
Unsubscribe()
Defined in: packages/core/src/utils.ts:24
Function interface for unsubscribing from subscriptions. Used consistently throughout Reatom for cleanup functions.
Unsubscribe():
void
Defined in: packages/core/src/utils.ts:25
Function interface for unsubscribing from subscriptions. Used consistently throughout Reatom for cleanup functions.
Returns
void
Type Aliases
Assign<T1, T2, T3, T4>
Assign<
T1,T2,T3,T4> =Plain<T1extends (…params) => infer O ? (…params) =>O:object&Omit<T1, keyofT2| keyofT3| keyofT4> &Omit<T2, keyofT3| keyofT4> &Omit<T3, keyofT4> &T4>
Defined in: packages/core/src/utils.ts:380
Type utility for merging up to four types with proper type safety. Properties from later types override properties from earlier types. Preserves function signatures from T1 if it’s a function type.
Type Parameters
T1
T1
First type to merge
T2
T2
Second type to merge, overrides T1 properties
T3
T3 = { }
Optional third type to merge, overrides T1 and T2 properties
T4
T4 = { }
Optional fourth type to merge, overrides T1, T2, and T3 properties
Constructor()<T>
Constructor<
T> = (…args) =>T
Defined in: packages/core/src/utils.ts:773
Represents a constructor function that can be instantiated with the new operator.
Type Parameters
T
T
The type of object that will be created when instantiated
Parameters
args
…any[]
Returns
T
Falsy
Falsy =
false|0|""|null|undefined
Defined in: packages/core/src/utils.ts:56
Union type of all JavaScript falsy values except for NaN. Includes: false, 0, empty string, null, and undefined.
See
https://stackoverflow.com/a/51390763
MaybeUnsubscribe
MaybeUnsubscribe =
void|Unsubscribe| {unsubscribe:Unsubscribe; }
Defined in: packages/core/src/utils.ts:33
Type representing different possible return values from observable subscription methods. Supports both function-based unsubscribers and objects with unsubscribe methods.
OmitValues<T, V>
OmitValues<
T,V> ={ [K in OmitValuesKeys<T, V>]: T[K] }
Defined in: packages/core/src/utils.ts:128
Creates a type with all properties from T except those with values extending V.
Type Parameters
T
T
The object type to filter properties from
V
V
The value type to exclude
OmitValuesKeys<T, V>
OmitValuesKeys<
T,V> =Values<{ [K in keyof T]: T[K] extends V ? never : K }>
Defined in: packages/core/src/utils.ts:117
Extracts keys from type T where the corresponding value does not extend type V.
Type Parameters
T
T
The object type to extract keys from
V
V
The value type to exclude
OverloadParameters<T>
OverloadParameters<
T> =Parameters<Overloads<T>>
Defined in: packages/core/src/utils.ts:190
Extracts the parameters type from an overloaded function. Returns a union of all possible parameter tuples.
Type Parameters
T
T
The overloaded function type to extract parameters from
Overloads<T>
Overloads<
T> =Textends {(…params):Return1; (…params):Return2; (…params):Return3; (…params):Return4; (…params):Return5; } ? (…params) =>Return1|Return2|Return3|Return4|Return5:never
Defined in: packages/core/src/utils.ts:160
Flattens a function type with up to 5 overloads into a single function signature. This creates a union of the parameter types and return types.
Useful for generic type handling of overloaded functions.
Type Parameters
T
T
The overloaded function type to flatten
PickValues<T, V>
PickValues<
T,V> ={ [K in PickValuesKeys<T, V>]: T[K] }
Defined in: packages/core/src/utils.ts:148
Creates a type with only properties from T with values extending V.
Type Parameters
T
T
The object type to filter properties from
V
V
The value type to include
PickValuesKeys<T, V>
PickValuesKeys<
T,V> =Values<{ [K in keyof T]: T[K] extends V ? K : never }>
Defined in: packages/core/src/utils.ts:138
Extracts keys from type T where the corresponding value extends type V.
Type Parameters
T
T
The object type to extract keys from
V
V
The value type to include
Plain<Intersection>
Plain<
Intersection> =Intersectionextends (…params) => infer O ? (…params) =>O&{ [Key in keyof Intersection]: Intersection[Key] }:Intersectionextends (…params) =>any?Intersection:Intersectionextendsobject?{ [Key in keyof Intersection]: Intersection[Key] }:Intersection
Defined in: packages/core/src/utils.ts:68
Removes named generics to produce a plain type representation. Preserves function signatures and object structure while eliminating generic parameter names.
This is useful for presenting cleaner types in documentation and error messages.
Type Parameters
Intersection
Intersection
The type to convert to a plain representation
Rec<T>
Rec<
T> =Record<string,T>
Defined in: packages/core/src/utils.ts:18
Type alias for Record<string, T> for brevity. Represents an object with string keys and values of type T.
Type Parameters
T
T = any
The type of values in the record (defaults to any)
Shallow<T>
Shallow<
T> ={ [K in keyof T]: T[K] }&object
Defined in: packages/core/src/utils.ts:88
Creates a shallow clone type of T. Useful for creating a new type that has the same shape but is a distinct type.
Type Parameters
T
T
The type to create a shallow clone of
UndefinedToOptional<T>
UndefinedToOptional<
T> =Partial<T> &PickValues<T, { } |null>
Defined in: packages/core/src/utils.ts:47
Utility type that converts properties with undefined values to optional properties. Makes properties with object or null values required, while making other properties optional.
Type Parameters
T
T extends object
The object type to transform
Values<T>
Values<
T> =T[keyofT]
Defined in: packages/core/src/utils.ts:108
Extracts the union type of all values in an object type.
Type Parameters
T
T
The object type to extract values from
Variables
assign()
constassign: {<T1,T2>(a1,a2):Plain<T1extends (…params) =>O? (…params) =>O:object&Omit<T1, keyofT2> &Omit<T2,never> &Omit<{ },never>>; <T1,T2,T3>(a1,a2,a3?):Plain<T1extends (…params) =>O? (…params) =>O:object&Omit<T1, keyofT2| keyofT3> &Omit<T2, keyofT3> &Omit<T3,never>>; <T1,T2,T3,T4>(a1,a2,a3?,a4?):Plain<T1extends (…params) =>O? (…params) =>O:object&Omit<T1, keyofT2| keyofT3| keyofT4> &Omit<T2, keyofT3| keyofT4> &Omit<T3, keyofT4> &T4>; } =Object.assign
Defined in: packages/core/src/utils.ts:399
Type-safe version of Object.assign that properly handles type merging. Unlike standard Object.assign typing, properties with the same name are replaced rather than becoming a union type.
Call Signature
<
T1,T2>(a1,a2):Plain<T1extends (…params) =>O? (…params) =>O:object&Omit<T1, keyofT2> &Omit<T2,never> &Omit<{ },never>>
Type Parameters
T1
T1
T2
T2
Parameters
a1
T1
a2
T2
Returns
Plain<T1 extends (…params) => O ? (…params) => O : object & Omit<T1, keyof T2> & Omit<T2, never> & Omit<{ }, never>>
Call Signature
<
T1,T2,T3>(a1,a2,a3?):Plain<T1extends (…params) =>O? (…params) =>O:object&Omit<T1, keyofT2| keyofT3> &Omit<T2, keyofT3> &Omit<T3,never>>
Type Parameters
T1
T1
T2
T2
T3
T3 = { }
Parameters
a1
T1
a2
T2
a3?
T3
Returns
Plain<T1 extends (…params) => O ? (…params) => O : object & Omit<T1, keyof T2 | keyof T3> & Omit<T2, keyof T3> & Omit<T3, never>>
Call Signature
<
T1,T2,T3,T4>(a1,a2,a3?,a4?):Plain<T1extends (…params) =>O? (…params) =>O:object&Omit<T1, keyofT2| keyofT3| keyofT4> &Omit<T2, keyofT3| keyofT4> &Omit<T3, keyofT4> &T4>
Type Parameters
T1
T1
T2
T2
T3
T3 = { }
T4
T4 = { }
Parameters
a1
T1
a2
T2
a3?
T3
a4?
T4
Returns
Plain<T1 extends (…params) => O ? (…params) => O : object & Omit<T1, keyof T2 | keyof T3 | keyof T4> & Omit<T2, keyof T3 | keyof T4> & Omit<T3, keyof T4> & T4>
Template
Type of the target object
Template
Type of the first source object
Template
Type of the optional second source object
Template
Type of the optional third source object
Returns
A new object with merged properties
entries()
constentries: <T>(thing) => [keyofT,T[keyofT]][] =Object.entries
Defined in: packages/core/src/utils.ts:444
Type-safe version of Object.entries that preserves key and value type information. Returns an array of key-value pairs with correct types.
Type Parameters
T
T extends object
The object type
Parameters
thing
T
The object to get entries from
Returns
[keyof T, T[keyof T]][]
An array of [key, value] pairs with proper typing
keys()
constkeys: <T>(thing) => keyofT[] =Object.keys
Defined in: packages/core/src/utils.ts:432
Type-safe version of Object.keys that preserves the key type information. Returns an array of keys with the correct type for the object.
Type Parameters
T
T extends object
The object type
Parameters
thing
T
The object to get keys from
Returns
keyof T[]
An array of the object’s keys with proper typing
MAX_SAFE_TIMEOUT
constMAX_SAFE_TIMEOUT:number
Defined in: packages/core/src/utils.ts:765
Maximum safe integer value for setTimeout delay. Any timeout value larger than this may cause overflow issues in some browsers.
See
https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value
merge
constmerge: typeofassign
Defined in: packages/core/src/utils.ts:421
Creates a new object with merged properties from all provided objects. Similar to Object.assign but always creates a new object rather than mutating the first argument.
Example
// Creates a new object: { a: 1, b: 2, c: 3 } const obj = merge({ a: 1 }, { b: 2 }, { c: 3 })Returns
A new object with all properties from the provided objects
noop()
constnoop: (…params) =>any
Defined in: packages/core/src/utils.ts:224
No-operation function that accepts any parameters and returns undefined. Useful as a default callback or for stubbing functionality.
Parameters
params
…any[]
Returns
any
random
constrandom: typeof_random
Defined in: packages/core/src/utils.ts:522
Generates a random integer between min and max (inclusive).
Param
The minimum integer value (defaults to 0)
Param
The maximum integer value (defaults to Number.MAX_SAFE_INTEGER - 1)
Returns
A random integer between min and max
setTimeout
constsetTimeout:SetTimeout
Defined in: packages/core/src/utils.ts:747
Enhanced version of the global setTimeout function. Ensures consistent behavior across different environments by handling both numeric and object timeout IDs. Adds a toJSON method to object timeout IDs for serialization.
Param
The function to call after the timeout
Param
The time in milliseconds to wait before calling the handler
Param
Optional arguments to pass to the handler function
Returns
A timeout ID that can be used with clearTimeout
Functions
assert()
assert(
value,message,ErrorConstructor):asserts value
Defined in: packages/core/src/utils.ts:212
Asserts that a value is truthy, throwing an error if it’s falsy. This is a TypeScript type assertion function that helps with type narrowing.
Parameters
value
unknown
The value to check
message
string
The error message to use if the assertion fails
ErrorConstructor
Newable<Error> = Error
Optional custom error constructor to use (defaults to Error)
Returns
asserts value
Throws
Throws an error with the provided message if value is falsy
identity()
identity<
T>(value, …a):T
Defined in: packages/core/src/utils.ts:234
Identity function that returns the first argument unchanged. Can accept additional parameters but ignores them.
Type Parameters
T
T
The type of value being passed through
Parameters
value
T
The value to return
a
…any[]
Returns
T
The same value that was passed in
isAbort()
isAbort(
thing):thing is AbortError
Defined in: packages/core/src/utils.ts:717
Type guard that checks if a value is an AbortError.
Parameters
thing
any
The value to check
Returns
thing is AbortError
True if the value is an AbortError, false otherwise
isBrowser()
isBrowser():
boolean
Defined in: packages/core/src/utils.ts:781
Detects whether the code is running in a browser environment. Checks for the existence of window and document objects.
Returns
boolean
True if running in a browser environment, false otherwise
isDeepEqual()
isDeepEqual(
a,b):any
Defined in: packages/core/src/utils.ts:355
Performs a deep equality comparison between two values. Recursively compares nested objects and arrays while properly handling cyclic references.
Handles primitives, objects, dates, regular expressions, arrays, maps, and sets. Uses a WeakMap to track visited objects to avoid infinite recursion with circular references.
Parameters
a
any
First value to compare
b
any
Second value to compare
Returns
any
True if the values are deeply equal, false otherwise
isObject()
isObject<
T>(thing): thing is T extends Record<string | number | symbol, unknown> ? T<T> : Record<string | number | symbol, unknown>
Defined in: packages/core/src/utils.ts:258
Type guard that checks if a value is an object (non-null and typeof ‘object’). Provides advanced type narrowing to either the original object type or a generic object type.
Type Parameters
T
T
The type of value being checked
Parameters
thing
T
The value to check
Returns
thing is T extends Record<string | number | symbol, unknown> ? T<T> : Record<string | number | symbol, unknown>
True if the value is a non-null object, false otherwise
isRec()
isRec(
thing):thing is Record<string, unknown>
Defined in: packages/core/src/utils.ts:274
Type guard that checks if a value is a plain object (a simple object literal or created with Object.create(null)). Verifies that the object either has no prototype or its prototype is Object.prototype.
Parameters
thing
unknown
The value to check
Returns
thing is Record<string, unknown>
True if the value is a plain object, false otherwise
isShallowEqual()
isShallowEqual(
a,b,is):any
Defined in: packages/core/src/utils.ts:298
Performs a shallow equality comparison between two values. Handles primitives, objects, dates, regular expressions, arrays, maps, and sets.
For iterables, compares each item in sequence for equality. For objects, compares direct property values but not nested objects deeply.
Parameters
a
any
First value to compare
b
any
Second value to compare
is
(value1, value2) => boolean
Optional comparison function to use for individual values (defaults to Object.is)
Returns
any
True if the values are shallowly equal, false otherwise
jsonClone()
jsonClone<
T>(value):T
Defined in: packages/core/src/utils.ts:509
Creates a deep clone of a value using JSON serialization/deserialization.
This is a type-safe shortcut to JSON.parse(JSON.stringify(value)).
Note: This has limitations with circular references, functions, symbols, and special objects like Date (converts to string). Consider using the native structuredClone when available.
Type Parameters
T
T
The type of value being cloned
Parameters
value
T
The value to clone
Returns
T
A deep clone of the input value
See
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
mockRandom()
mockRandom(
fn): () =>void
Defined in: packages/core/src/utils.ts:538
Replaces the default random number generator with a custom implementation. Useful for testing to provide deterministic “random” values.
Parameters
fn
(min, max) => number
The custom random function to use
Returns
A restore function that reverts to the original random implementation when called
():
void
Returns
void
Example
// Set up deterministic random values for testing const restore = mockRandom(() => 42) console.log(random()) // Always returns 42 restore() // Back to normal random behaviornonNullable()
nonNullable<
T>(value,message?):NonNullable<T>
Defined in: packages/core/src/utils.ts:560
Asserts that a value is not null or undefined. Throws a TypeError if the value is null or undefined. Also serves as a type guard to narrow the type to non-nullable.
Type Parameters
T
T
The type of value to check
Parameters
value
T
The value to check
message?
string
Optional custom error message
Returns
NonNullable<T>
The input value if it’s not null or undefined
Example
const name = nonNullable(user.name) // TypeScript knows name is not null or undefinedThrows
If the value is null or undefined
omit()
omit<
T,K>(target,keys):Plain<Omit<T,K>>
Defined in: packages/core/src/utils.ts:485
Creates a new object excluding the specified keys from the original object.
Type Parameters
T
T
The source object type
K
K extends string | number | symbol
The keys to omit from the object
Parameters
target
T
The source object
keys
K[]
Array of keys to exclude from the result
Returns
Plain<Omit<T, K>>
A new object containing all keys except the specified ones
Example
const user = { id: 1, name: 'Alice', password: 'secret' } const safeUser = omit(user, ['password']) // Result: { id: 1, name: 'Alice' }pick()
pick<
T,K>(target,keys):Plain<Pick<T,K>>
Defined in: packages/core/src/utils.ts:462
Creates a new object with only the specified keys from the original object.
Type Parameters
T
T
The source object type
K
K extends string | number | symbol
The keys to pick from the object
Parameters
target
T
The source object
keys
K[]
Array of keys to include in the result
Returns
Plain<Pick<T, K>>
A new object containing only the specified keys and their values
Example
const user = { id: 1, name: 'Alice', email: 'alice@example.com' } const userInfo = pick(user, ['name', 'email']) // Result: { name: 'Alice', email: 'alice@example.com' }sleep()
sleep(
ms):Promise<unknown>
Defined in: packages/core/src/utils.ts:247
Creates a promise that resolves after the specified number of milliseconds. Useful for creating delays in async functions.
Parameters
ms
number = 0
The number of milliseconds to sleep (defaults to 0)
Returns
Promise<unknown>
A promise that resolves after the specified delay
throwAbort()
throwAbort(
message,controller?):never
Defined in: packages/core/src/utils.ts:728
Creates and throws an AbortError with the provided message. Optionally aborts the provided controller with the same error.
Parameters
message
string = ''
The error message
controller?
AbortController
Optional AbortController to abort
Returns
never
Throws
Always throws the created AbortError
throwIfAborted()
throwIfAborted(
controller?):void
Defined in: packages/core/src/utils.ts:705
Checks if an AbortController is aborted and throws an AbortError if it is. Useful for quick abort checks at the beginning of async operations.
Parameters
controller?
The AbortController to check (can be undefined, null or void)
null | void | AbortController
Returns
void
Throws
If the controller’s signal is aborted
toAbortError()
toAbortError(
reason):AbortError
Defined in: packages/core/src/utils.ts:674
Converts any value to an AbortError. If the value is already an AbortError, it will be returned as is. Otherwise, creates a new AbortError with appropriate information.
Handles different environments by using DOMException when available or falling back to regular Error with name set to ‘AbortError’.
Parameters
reason
any
The value to convert to an AbortError
Returns
An AbortError instance
toStringKey()
toStringKey(
thing,immutable):string
Defined in: packages/core/src/utils.ts:598
Converts any JavaScript value to a stable string representation. Handles complex data structures and edge cases that JSON.stringify cannot manage.
Provides special handling for:
- Circular references
- Maps and Sets
- Symbols
- Functions
- Custom class instances
- Regular objects (with sorted keys for stability)
Parameters
thing
any
The value to convert to a string
immutable
boolean = true
Whether to memoize results for complex objects (defaults to true)
Returns
string
A string representation of the value
Example
// Handles circular references const obj = { name: 'test' } obj.self = obj const key = toStringKey(obj) // No infinite recursion!
// Stable representation of objects (key order doesn't matter) toStringKey({ a: 1, b: 2 }) === toStringKey({ b: 2, a: 1 }) // truewithResolvers()
withResolvers<
T>():object
Defined in: packages/core/src/utils.ts:814
Creates a Promise and returns it along with its resolve and reject functions.
This utility is similar to the upcoming Promise.withResolvers() static
method. It allows for manual control over a Promise’s settlement from outside
its constructor.
Type Parameters
T
T
The type of the value the promise will resolve with.
Returns
object
An object containing the promise, and its resolve and reject
functions.
promise
promise:
Promise<T>
reject()
reject: (
reason?) =>void
Parameters
reason?
any
Returns
void
resolve()
resolve: (
value) =>void
Parameters
value
T
Returns
void
Example
const { promise, resolve, reject } = withResolvers<string>()
promise .then((value) => console.log('Resolved:', value)) .catch((error) => console.error('Rejected:', error))
// Sometime later, or in a different part of the code: if (Math.random() > 0.5) { resolve('Success!') } else { reject(new Error('Failed!')) }