Skip to main content

@sapphire/utilities

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

Interfaces

InterfaceDescription
DebounceSettingslodash (Custom Build) https://lodash.com/ Build: lodash modularize exports="npm" -o ./ Copyright jQuery Foundation and other contributors https://jquery.org/ Released under MIT license https://lodash.com/license Based on Underscore.js 1.8.3 http://underscorejs.org/LICENSE Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
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
AbstractConstructorA generic abstract constructor without parameters
AbstractCtorA generic abstract constructor with parameters
AnyObjectAn object that can have any structure, this is an alternative to NonNullObject for situations where that leads to unexpected type resolutions.
ArgumentTypes-
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-
ConstructorA generic constructor without parameters
CtorA generic constructor with parameters
DeepPartial-
DeepReadonly-
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 This does not recurse deeply, for that use DeepRequired
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-

Variables

VariableDescription
toTitleCaseDiscordJsVariantsThe variants that will not strictly follow the toTitleCase algorithm and will instead return the value matched with the key.

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
cutText-
debounceCreates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked. The debounced function comes with a cancel method to cancel delayed invocations and a flush method to immediately invoke them. Provide an options object to indicate that func should be invoked on the leading and/or trailing edge of the wait timeout. Subsequent calls to the debounced function return the result of the last func invocation.
deepCloneDeep clone an object
filterNullAndUndefinedChecks whether a value is not null nor undefined. This can be used in Array.filter to remove null and undefined from the array type
filterNullAndUndefinedAndEmptyChecks whether a value is not null nor undefined nor '' (empty string). This can be used in Array.filter to remove null, undefined from the array type
filterNullAndUndefinedAndZeroChecks whether a value is not null nor undefined nor 0. This can be used in Array.filter to remove null, undefined from the array type
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, where one array contains all elements that satisfies predicate, and the other contains all elements that do not satisfy predicate.
pickRandomPicks a random element from an array
pollExecutes a function cb and validates the result with function cbCondition, and repeats this until cbCondition returns true or the timeout is reached.
pollSyncExecutes a function cb and validates the result with function cbCondition, and repeats this until cbCondition returns true or the timeout is reached.
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. For a synchronous variant, see retrySync.
retrySyncSynchronously calls the callback function until it either succeeds or it runs out of retries. For an asynchronous variant, see retry.
roundNumberProperly rounds up or down a number. Also supports strings using an exponent to indicate large or small numbers.
sleepSleeps for the specified number of milliseconds. For a synchronous variant, see sleepSync.
sleepSyncSleeps for the specified number of milliseconds synchronously. We should probably note that unlike sleep (which uses CPU tick times), sleepSync uses wall clock times, so the precision is near-absolute by comparison. That, and that synchronous means that nothing else in the thread will run for the length of the timer.
snakeToCamelCaseTransforms text from snAkE_cASE to camelCase.
splitText-
throttleCreates a throttled function that only invokes func at most once per every wait milliseconds. The throttled function comes with a flush method to reset the last time the throttled function was invoked.
toTitleCaseConverts a string to Title Case
tryParseJSONTry parse a stringified JSON string.
tryParseURLTries parse a string to a URL object