Skip to main content

tools-language

@rnx-kit/tools-language is a collection of supplemental JavaScript functions and types.

You can import the entire package, or, to save space, import individual categories:

import * from "@rnx-kit/tools-language";

import * from "@rnx-kit/tools-language/function";
import * from "@rnx-kit/tools-language/math";
import * from "@rnx-kit/tools-language/properties";
CategoryFunctionDescription
arrayaddRange(to, from, start, end)Add elements from one array to another, returning the resulting array.
arrayisNonEmptyArray(array)Returns whether the specified object is a non-empty array.
arraytoIndex(array, offset)Convert an array offset to an array index. An offset can be positive or negative, while an index is always positive.
functiontryInvoke(fn)Invoke the given function, returning its result or a thrown error.
mathisApproximatelyEqual(f1, f2, tolerance)Decide if two numbers, integer or decimal, are "approximately" equal. They're equal if they are close enough to be within the given tolerance.
propertiesextendObject(obj, extendedProps)Add properties to an object, changing it from its current type to an extended type.
propertiesextendObjectArray(arr, extendedProps)Add properties to each object in an array, changing the object from its current type to an extended type.
propertieshasProperty(obj, property)Returns whether property exists in obj.
propertieskeysOf(obj)Returns the names of the enumerable string properties of an object. Equivalent to calling Object.keys(), but type safe.
propertiespickValue(obj, key, name)Pick the value for property key from obj and return it in a new object. If name is given, use it in the new object, instead of key.
propertiespickValues(obj, keys, names)Pick the value for each key property from obj and return each one in a new object. If names are given, use them in the new object, instead of keys.