Skip to main content

@sapphire/utilities

Interfaces

InterfaceDescription
DebounceSettingslodash (Custom Build) https://lodash.com/
DebouncedFuncCall the original function, but applying the debounce rules.
GetDeepObjectKeysOptionsThe options for getDeepObjectKeys
PollOptionsThe options for the poll function
SleepOptions-
SyncPollOptionsThe options for the pollSync function
Thenable-
ToTitleCaseOptionsThe options to use when converting a string to title case

Type Aliases

Type aliasDescription
AbstractConstructor-
AbstractCtor-
AnyObjectAn object that can have any structure, this is an alternative to NonNullObject for situations where
ArgumentTypes-
ArrA readonly array of any values.
ArrayElementTypeGets a union type of all the keys that are in an array.
AwaitableReturnType for a function that can return either a value or a Promise with that value
Builtin-
Constructor-
Ctor-
DeepPartial-
DeepRequired-
FirstArgumentGets the first argument of any given function
MutableTransforms a readonly type to be mutable
NonNullObjectAn object that is non nullable, to bypass TypeScript not easily working with Record<PropertyKey, unknown> in various instances.
NonNullablePropertiesSimilar to the built in NonNullable, but properly removes null from all keys in the class or interface
NullishType union for the full 2 billion dollar mistake in the JavaScript ecosystem
PartialRequired-
PickByValueGets all the keys (as a string union) from a type T that match value V
Primitive-
RequiredExcept-
SecondArgumentGets the second argument of any given function
StrictRequiredTransforms every key in an object to be strictly required, essentially removing undefined and null from the type.
ThrottleFn-

Functions

FunctionDescription
arrayStrictEqualsCompare if both arrays are strictly equal
capitalizeFirstLetterTransforms the first letter to a capital then adds all the rest after it
castCasts any value to T
chunkSplits up an array into chunks
classExtendsChecks whether or not the value class extends the base class.
codeBlockWraps the content inside a codeblock with no language
cutTextSplit a text by its latest space character in a range from the character 0 to the selected one.
debounceCreates a debounced function that delays invoking func until after wait milliseconds have elapsed since
deepCloneDeep clone an object
filterNullAndUndefinedChecks whether a value is not null nor undefined.
filterNullAndUndefinedAndEmptyChecks whether a value is not null nor undefined nor '' (empty string).
filterNullAndUndefinedAndZeroChecks whether a value is not null nor undefined nor 0.
getDeepObjectKeysFlattens an object to a list of its keys, traversing deeply into nested objects and arrays of objects.
hasAtLeastOneKeyInMapChecks whether any of the keys are in the map
hasAtLeastOneKeyInObjectChecks whether any of the keys are in the obj
inlineCodeBlockWraps text in a markdown inline codeblock
isClassVerify if the input is a class constructor.
isFunctionVerify if the input is a function.
isNullOrUndefinedChecks whether or not a value is null or undefined
isNullOrUndefinedOrEmptyChecks whether or not a value is null, undefined or '', []
isNullOrUndefinedOrZeroChecks whether or not a value is null, undefined or 0
isNumberVerify if a number is a finite number.
isObjectVerify if the input is an object literal (or class).
isPrimitiveCheck whether a value is a primitive
isThenableVerify if an object is a promise.
lazyLazily creates a constant or load a module and caches it internally
makeObjectTurn a dotted path into a json object.
mergeDefaultDeep merges 2 objects. Properties from the second parameter are applied to the first.
mergeObjectsMerges two objects
noop-
objectEntries-
objectKeys-
objectToTuplesConvert an object to a tuple
objectValues-
omitKeysFromObjectClones the source object using deepClone then deletes the specified keys with Reflect.deleteProperty
partitionPartitions array into a tuple of two arrays,
pickRandomPicks a random element from an array
pollExecutes a function cb and validates the result with function cbCondition,
pollSyncExecutes a function cb and validates the result with function cbCondition,
rangeGet an array of numbers with the selected range
regExpEscCleans a string from regex injection
retryAsynchronously calls the callback function until it either succeeds or it runs out of retries.
retrySyncSynchronously calls the callback function until it either succeeds or it runs out of retries.
roundNumberProperly rounds up or down a number.
sleepSleeps for the specified number of milliseconds.
sleepSyncSleeps for the specified number of milliseconds synchronously.
snakeToCamelCaseTransforms text from snAkE_cASE to camelCase.
splitTextSplit a string by its latest space character in a range from the character 0 to the selected one.
throttleCreates a throttled function that only invokes func at most once per
toTitleCaseConverts a string to Title Case
tryParseJSONTry parse a stringified JSON string.
tryParseURLTries parse a string to a URL object

References

filterNullish

Renames and re-exports filterNullAndUndefined


filterNullishAndEmpty

Renames and re-exports filterNullAndUndefinedAndEmpty


filterNullishAndZero

Renames and re-exports filterNullAndUndefinedAndZero


filterNullishOrEmpty

Renames and re-exports filterNullAndUndefinedAndEmpty


filterNullishOrZero

Renames and re-exports filterNullAndUndefinedAndZero


isNullish

Renames and re-exports isNullOrUndefined


isNullishOrEmpty

Renames and re-exports isNullOrUndefinedOrEmpty


isNullishOrZero

Renames and re-exports isNullOrUndefinedOrZero


kebabToCamelCase

Renames and re-exports snakeToCamelCase


parseURL

Renames and re-exports tryParseURL


tryParse

Renames and re-exports tryParseJSON