Array§
Source§allElements<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): boolean
allElements<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): boolean
Source§allElements<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
allElements<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
Source§aperture<I extends any[]>(data: I, size: number): I[]
aperture<I extends any[]>(data: I, size: number): I[]
Returns an array of arrays of length size
with consecutive elements
from the original array. Returns an empty array if size
is shorter
than the array, or is not a positive integer.
Source§append<I extends string | any[]>(data: I, value: I): I
append<I extends string | any[]>(data: I, value: I): I
Returns a data
the value
array appended. To append an element
(rather than another array) to an array instead, use appendElement.
Source§appendElement<I extends any[]>(data: I, value: ElementType<I>): I
appendElement<I extends any[]>(data: I, value: ElementType<I>): I
Appends the element to the end of the data
array and returns a copy.
For strings, or to append an array to another array, use append.
Source§appendElement<I extends any[]>(value: ElementType<I>): (data: I) => I
appendElement<I extends any[]>(value: ElementType<I>): (data: I) => I
Source§chunk<I extends string | any[]>(data: I, size: number): I[]
chunk<I extends string | any[]>(data: I, size: number): I[]
Breaks data
into an array of subarrays or substrings, each of length size
.
If size
does not divide evenly into the length of data
, the last subarray
will contain fewer than size
elements. Returns an empty array if size
is invalid.
Source§contains(data: string | any[], value: any): boolean
contains(data: string | any[], value: any): boolean
Indicates whether or not the data
array contains the element value
,
or the data
string contains the substring value
.
Source§count<I extends any[]>(data: I, value: ElementType<I>): number
count<I extends any[]>(data: I, value: ElementType<I>): number
Count the number of elements (strictly) equal to value
in the array data
.
Source§count<I extends any[]>(value: ElementType<I>): (data: I) => number
count<I extends any[]>(value: ElementType<I>): (data: I) => number
Source§countWith<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): number
countWith<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): number
Counts the number of elements in the data
array that
pass the condition
predicate.
Source§countWith<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => number
countWith<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => number
Source§createArrayOf<E>(length: number, value: E): E[]
createArrayOf<E>(length: number, value: E): E[]
Creates a new array with length
elements, each filled with value
.
Creates an empty array for invalid length
(non-integer or negative).
Source§createArrayWith<E>(length: number, transform: (x: number) => E): E[]
createArrayWith<E>(length: number, transform: (x: number) => E): E[]
Creates a new array with length
elements. Element values are determined
by a transform
of the element index.
Creates an empty array for invalid length
(non-integer or negative).
Source§elementAt<I extends any[]>(data: I, index: number): undefined | ElementType<I>
elementAt<I extends any[]>(data: I, index: number): undefined | ElementType<I>
Returns the element of data
at index
, or undefined
if index
is out of bounds
or otherwise invalid.
Source§elementAt<I extends any[]>(
index: number,
): (data: I) => undefined | ElementType<I>
elementAt<I extends any[]>(
index: number,
): (data: I) => undefined | ElementType<I>
Source§elementPasses<I extends any[]>(
data: I,
index: number,
condition: Predicate<ElementType<I>>,
): boolean
elementPasses<I extends any[]>(
data: I,
index: number,
condition: Predicate<ElementType<I>>,
): boolean
Indicates whether the element of array data
at index
passes the condition
.
If index
is invalid or out of bounds, returns false.
Source§elementPasses<I extends any[]>(
index: number,
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
elementPasses<I extends any[]>(
index: number,
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
Source§filter<I extends any[]>(data: I, condition: Predicate<ElementType<I>>): I
filter<I extends any[]>(data: I, condition: Predicate<ElementType<I>>): I
Similar to Array.prototype.filter
, but with the difference that
the condition
function is not called with an index as the second parameter.
This prevents unexpected behavior when the transform
function has a second optional parameter that respresents
something other than an index. Use filterWithIndex instead if
you need the index.
Source§filter<I extends any[]>(condition: Predicate<ElementType<I>>): (data: I) => I
filter<I extends any[]>(condition: Predicate<ElementType<I>>): (data: I) => I
Source§filterWithIndex<I extends any[]>(
data: I,
condition: IndexedPredicate<ElementType<I>>,
): I
filterWithIndex<I extends any[]>(
data: I,
condition: IndexedPredicate<ElementType<I>>,
): I
Source§filterWithIndex<I extends any[]>(
condition: IndexedPredicate<ElementType<I>>,
): (data: I) => I
filterWithIndex<I extends any[]>(
condition: IndexedPredicate<ElementType<I>>,
): (data: I) => I
Source§findIndex<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): number
findIndex<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): number
Returns the index of the first element of data
that passes condition
,
or returns NaN
if no eleement passes.
Source§findIndex<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => number
findIndex<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => number
Source§findLastIndex<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): number
findLastIndex<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): number
Returns the index of the last element of data
that passes condition
,
or returns NaN
if no eleement passes.
Source§findLastIndex<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => number
findLastIndex<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => number
Source§findLastOr<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
fallback: unknown,
): unknown
findLastOr<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
fallback: unknown,
): unknown
Returns the last element in the data
array that passes the condition
, or returns
the fallback
value if no element meets the condition
.
Source§findLastOr<I extends any[]>(
condition: Predicate<ElementType<I>>,
fallback: unknown,
): (data: I) => unknown
findLastOr<I extends any[]>(
condition: Predicate<ElementType<I>>,
fallback: unknown,
): (data: I) => unknown
Source§findOr<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
fallback: unknown,
): unknown
findOr<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
fallback: unknown,
): unknown
Returns the first element in the data
array that passes the condition
, or returns
the fallback
value if no element meets the condition
.
Source§findOr<I extends any[]>(
condition: Predicate<ElementType<I>>,
fallback: unknown,
): (data: I) => unknown
findOr<I extends any[]>(
condition: Predicate<ElementType<I>>,
fallback: unknown,
): (data: I) => unknown
Source§first<I extends any[]>(data: I): undefined | ElementType<I>
first<I extends any[]>(data: I): undefined | ElementType<I>
Returns the first element of an array, or undefined
if the array is empty.
Source§flatten<I extends any[]>(data: I): ElementType<I>
flatten<I extends any[]>(data: I): ElementType<I>
Flatten an array one level.
Source§insert<I extends string | any[]>(
data: I,
index: number,
content: I extends any[] ? ElementType<I<I>> : string,
): I
insert<I extends string | any[]>(
data: I,
index: number,
content: I extends any[] ? ElementType<I<I>> : string,
): I
Inserts the content
element into the data
array, or the content
substring into the data
string
at the index
position. If index
is equal to the length of data
, then content
will be
appended to the end. Returns a shallow copy of data
if the index is invalid.
Source§insert<I extends string | any[]>(
index: number,
content: I extends any[] ? ElementType<I<I>> : string,
): (data: I) => I
insert<I extends string | any[]>(
index: number,
content: I extends any[] ? ElementType<I<I>> : string,
): (data: I) => I
Source§insertArray<I extends any[]>(data: I, index: number, content: I): I
insertArray<I extends any[]>(data: I, index: number, content: I): I
Inserts the content
array into the data
array at the index
position. If index
is equal to
the length of data
, then content
will be appended to the end. Returns a shallow copy
of data
if the index is invalid.
Source§isNotEmpty(data: string | any[]): boolean
isNotEmpty(data: string | any[]): boolean
Indicates whether a string or array has length of at least one.
Source§join(data: string[], separator: string): string
join(data: string[], separator: string): string
Concatenates the strings in the data
array, inserting the
separator
string between each.
Source§last<I extends any[]>(data: I): undefined | ElementType<I>
last<I extends any[]>(data: I): undefined | ElementType<I>
Returns the last element of an array, or undefined
if the array is empty.
Source§lengthPasses(data: string | any[], condition: Predicate<number>): boolean
lengthPasses(data: string | any[], condition: Predicate<number>): boolean
Indicates whether the length of the data
string or array passes the condition
.
Source§lengthPasses<I extends string | any[]>(
condition: Predicate<number>,
): (data: string | any[]) => boolean
lengthPasses<I extends string | any[]>(
condition: Predicate<number>,
): (data: string | any[]) => boolean
Source§map<I extends any[], O extends any[] = I>(
data: I,
transform: (x: ElementType<I>) => O[number],
): O
map<I extends any[], O extends any[] = I>(
data: I,
transform: (x: ElementType<I>) => O[number],
): O
Similar in concept Array.prototype.map
, but with
the distinction that it does not automatically call
transform
with a second argument for the index.
This prevents unexpected behavior when the transform
function has a second optional parameter that respresents
something other than an index (e.g., parseInt
). Use
mapWithIndex instead if you need the index.
Source§map<I extends any[], O extends any[] = I>(
transform: (x: ElementType<I>) => O[number],
): (data: I) => O
map<I extends any[], O extends any[] = I>(
transform: (x: ElementType<I>) => O[number],
): (data: I) => O
Source§mapWithIndex<I extends any[], O extends any[] = I>(
data: I,
transform: (x: ElementType<I>, i: number) => O[number],
): O
mapWithIndex<I extends any[], O extends any[] = I>(
data: I,
transform: (x: ElementType<I>, i: number) => O[number],
): O
Source§mapWithIndex<I extends any[], O extends any[] = I>(
transform: (x: ElementType<I>, i: number) => O[number],
): (data: I) => O
mapWithIndex<I extends any[], O extends any[] = I>(
transform: (x: ElementType<I>, i: number) => O[number],
): (data: I) => O
Source§maximum(data: number[]): number
maximum(data: number[]): number
Returns the maximum value of the array, or NaN
if the array is empty.
Source§maximumWith<I extends any[]>(
data: I,
transform: (x: ElementType<I>) => number,
): number
maximumWith<I extends any[]>(
data: I,
transform: (x: ElementType<I>) => number,
): number
Applies a transform
to each element of the array, then returns the maximum
of the transformed array. Returns NaN
if the array is empty.
Source§maximumWith<I extends any[]>(
transform: (x: ElementType<I>) => number,
): (data: I) => number
maximumWith<I extends any[]>(
transform: (x: ElementType<I>) => number,
): (data: I) => number
Source§mean(data: number[]): number
mean(data: number[]): number
Returns the mean of an array of numbers, or NaN
if the array is empty.
Source§meanWith<I extends any[]>(
data: I,
transform: Fn<ElementType<I>, number>,
): number
meanWith<I extends any[]>(
data: I,
transform: Fn<ElementType<I>, number>,
): number
Applies the transform
function to each element of an array, then returns
the mean of the result. Returns NaN
if the array is empty.
Source§meanWith<I extends any[]>(
transform: Fn<ElementType<I>, number>,
): (data: I) => number
meanWith<I extends any[]>(
transform: Fn<ElementType<I>, number>,
): (data: I) => number
Source§minimum(data: number[]): number
minimum(data: number[]): number
Returns the minimum value of the array, or NaN
if the array is empty.
Source§minimumWith<I extends any[]>(
data: I,
transform: (x: ElementType<I>) => number,
): number
minimumWith<I extends any[]>(
data: I,
transform: (x: ElementType<I>) => number,
): number
Applies a transform
to each element of the array, then returns the minimum
of the transformed array. Returns NaN
if the array is empty.
Source§minimumWith<I extends any[]>(
transform: (x: ElementType<I>) => number,
): (data: I) => number
minimumWith<I extends any[]>(
transform: (x: ElementType<I>) => number,
): (data: I) => number
Source§noElements<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): boolean
noElements<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): boolean
Returns true if no elements of the data
array pass the condition
.
Source§noElements<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
noElements<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
Source§notAllElements<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): boolean
notAllElements<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): boolean
Returns true if one or more elements of the data
array fails to pass the condition.
Source§notAllElements<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
notAllElements<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
Source§prepend<I extends string | any[]>(data: I, value: I): I
prepend<I extends string | any[]>(data: I, value: I): I
Returns a data
the value
array prepended. To prepend an element
(rather than another array) to an array instead, use prependElement.
Source§prependElement<I extends any[]>(data: I, value: ElementType<I>): I
prependElement<I extends any[]>(data: I, value: ElementType<I>): I
Prepends the element to the end of the data
array and returns a copy.
For strings, or to prepend an array to another array, use prepend.
Source§prependElement<I extends any[]>(value: ElementType<I>): (data: I) => I
prependElement<I extends any[]>(value: ElementType<I>): (data: I) => I
Source§product(data: number[]): number
product(data: number[]): number
Returns the product of an array of numbers, or if the array is empty, 1.
Source§reduce<I extends any[], O = ElementType<I>>(
data: I,
accumulator: Accumulator<I, O>,
initial: O,
): O
reduce<I extends any[], O = ElementType<I>>(
data: I,
accumulator: Accumulator<I, O>,
initial: O,
): O
A data-first counterpart to Array.prototype.reduce
, but with more permissive typing than
the TS library uses out of the box, allowing the result to have a different type from
the data
elements themselves.
Source§reduce<I extends any[], O = ElementType<I>>(
accumulator: Accumulator<I, O>,
initial: O,
): (data: I) => O
reduce<I extends any[], O = ElementType<I>>(
accumulator: Accumulator<I, O>,
initial: O,
): (data: I) => O
Source§reduceRight<I extends any[], O = ElementType<I>>(
data: I,
accumulator: Accumulator<I, O>,
initial: O,
): O
reduceRight<I extends any[], O = ElementType<I>>(
data: I,
accumulator: Accumulator<I, O>,
initial: O,
): O
A data-frst counterpart to Array.prototype.reduceRight
, but with more permissive typing than
the TS library uses out of the box, allowing the result to have a different type from
the data
elements themselves.
Source§reduceRight<I extends any[], O = ElementType<I>>(
accumulator: Accumulator<I, O>,
initial: O,
): (data: I) => O
reduceRight<I extends any[], O = ElementType<I>>(
accumulator: Accumulator<I, O>,
initial: O,
): (data: I) => O
Source§setElement<I extends any[]>(data: I, index: number, value: ElementType<I>): I
setElement<I extends any[]>(data: I, index: number, value: ElementType<I>): I
Returns a copy of the array data
with the element at index
set to value
.
A negative index
will count backward from the end of the array.
If index
is out of bounds or not an integer, returns an unaltered copy of data
.
Source§setElement<I extends any[]>(
index: number,
value: ElementType<I>,
): (data: I) => I
setElement<I extends any[]>(
index: number,
value: ElementType<I>,
): (data: I) => I
Source§slice<I extends string | any[]>(data: I, from: number, to: number): I
slice<I extends string | any[]>(data: I, from: number, to: number): I
Returns a shallow copy of the portion of the data
array or string beginning at index
from
and ending with, but not including, the index to
. Negative index values count
backward from the end of the arrry. Returns an empty array if from
or to
is not an
integer, or if from
is out of the array bounds.
Source§sliceFrom<I extends string | any[]>(data: I, from: number): I
sliceFrom<I extends string | any[]>(data: I, from: number): I
Returns a shallow copy of the data
array or string starting from index from
.
A negative index counts backwards from the end of the array.
Returns an empty array if from
is not an integer or is out of bounds.
Source§sliceTo<I extends string | any[]>(data: I, to: number): I
sliceTo<I extends string | any[]>(data: I, to: number): I
Return a shallow copy of the data
array or string up to, but not including,
the index 'to. Returns an empty array if
to` is not an integer.
Source§someElements<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): boolean
someElements<I extends any[]>(
data: I,
condition: Predicate<ElementType<I>>,
): boolean
Returns true if one or more elements of the data
array pass the condition. Returns false for an empty array.
Source§someElements<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
someElements<I extends any[]>(
condition: Predicate<ElementType<I>>,
): (data: I) => boolean
Source§sortAlphabetical(data: string[]): string[]
sortAlphabetical(data: string[]): string[]
Sorts an array of strings alphabetically, ignoring punctuation. and placing uppercase letters first.
Source§sortNumeric(data: number[]): number[]
sortNumeric(data: number[]): number[]
Sorts an array of numbers in ascending order, wiith NaN
s at the end.
Source§sum(data: number[]): number
sum(data: number[]): number
Returns the sum of an array of numbers, or sero if the array is empty.
Source§sumWith<I extends any[]>(data: I, transform: Fn<ElementType<I>, number>): number
sumWith<I extends any[]>(data: I, transform: Fn<ElementType<I>, number>): number
Applies the transform
function to each element in data
,
then returns the sum of the transformed array.
Source§sumWith<I extends any[]>(
transform: Fn<ElementType<I>, number>,
): (data: I) => number
sumWith<I extends any[]>(
transform: Fn<ElementType<I>, number>,
): (data: I) => number
Logic§
Source§all<T>(data: T, conditions: Predicate<T>[]): boolean
all<T>(data: T, conditions: Predicate<T>[]): boolean
Returns true
if and only if all conditions
are true for the data
.
Source§asIs<T>(value: T): T
asIs<T>(value: T): T
Returns its argument unchanged (similar to identity in some other libraries)
Source§equals<T>(data: T, value: T): boolean
equals<T>(data: T, value: T): boolean
Indicates whether the data
is strictly equal to (===
) value
.
Source§equalsOneOf(data: any, values: any[]): boolean
equalsOneOf(data: any, values: any[]): boolean
Returns true if data
is equal to one of the values
, false otherwise.
Source§equalsWith<I>(data: I, value: I, transform: (x: I) => any): boolean
equalsWith<I>(data: I, value: I, transform: (x: I) => any): boolean
Tells whether data
and value
are strictly equal after the transform
function is applied to each.
Source§isFunction(data: any): data is Function
isFunction(data: any): data is Function
Returns true if the data
is a function, false otherwise.
This is implemented using typeof data === "function"
.
Source§isInstanceOf(data: any, className: Object): boolean
isInstanceOf(data: any, className: Object): boolean
Tells whether data
is an instance of the class className
.
Source§none<T>(data: T, conditions: Predicate<T>[]): boolean
none<T>(data: T, conditions: Predicate<T>[]): boolean
Returns true
if and only if none of the conditions
are true for the data
.
Source§notAll<T>(data: T, conditions: Predicate<T>[]): boolean
notAll<T>(data: T, conditions: Predicate<T>[]): boolean
Returns true
if at least one of the conditions
is not true for the data
.
Source§notEqual<T>(data: T, value: T): boolean
notEqual<T>(data: T, value: T): boolean
Indicates if the data
is not strictly equal to value
.
You will likely need to use a type annotation if the types of the data
and value
are different.
§nullishTo<T>(data: undefined | null | T, value: T): T
nullishTo<T>(data: undefined | null | T, value: T): T
Returns value
if data
is null
or undefined
, otherwise returns data
unchanged.
§nullishTo<T>(value: T): (data: undefined | null | T) => T
nullishTo<T>(value: T): (data: undefined | null | T) => T
Returns value
if data
is null
or undefined
, otherwise returns data
unchanged.
§nullTo<T>(data: null | T, value: T): T
nullTo<T>(data: null | T, value: T): T
Returns value
if data
is null
, otherwise returns data
unchanged.
§nullTo<T>(value: T): (data: null | T) => T
nullTo<T>(value: T): (data: null | T) => T
Source§some<T>(data: T, conditions: Predicate<T>[]): boolean
some<T>(data: T, conditions: Predicate<T>[]): boolean
Returns true
if at least one of the conditions
is true for the data
.
§undefinedTo<T>(data: undefined | T, value: T): T
undefinedTo<T>(data: undefined | T, value: T): T
Returns value
if data
is undefined
, otherwise returns data
unchanged.
§undefinedTo<T>(value: T): (data: undefined | T) => T
undefinedTo<T>(value: T): (data: undefined | T) => T
Math§
Source§clamp(data: number, min: number, max: number): number
clamp(data: number, min: number, max: number): number
Returns min
if data
is less than min
, max
if data
is greater than max
.
If data
is already between min
and max
, then the value of data
is returned unchanged.
Source§interpolate(data: number, x1: number, x2: number): number
interpolate(data: number, x1: number, x2: number): number
Returns the value a fraction data
between the numbers x1
and x2
.
data
may be outside the range [0, 1], in which case the result will be
outside the range [x1
, x2
].
Source§isBetween(data: number, min: number, max: number): boolean
isBetween(data: number, min: number, max: number): boolean
Indicates whether data
is between the values of min
and max
(including the endpoints).
Source§isCloseTo(data: number, x: number, tolerance: number): boolean
isCloseTo(data: number, x: number, tolerance: number): boolean
Indicates whether data
is within tolerance
of x
(in either direction)
Source§isDivisibleBy(data: number, divisor: number): boolean
isDivisibleBy(data: number, divisor: number): boolean
Indicates whether data
is divislbe by divisor
. If either data
or divisor
is not an integer, then a tolerance of 1e-15 will be allowed to allow for floating
point errors.
Source§isEven(data: number): boolean
isEven(data: number): boolean
Indicates whether a number is even. Unlike isDivisibleBy(2)
, isEven
doesn't
not allow any tolerance for rounding errors in floating point numbers.
Source§isGte(data: number, value: number): boolean
isGte(data: number, value: number): boolean
Indicates whether data
is greater than or equal to value
.
Source§isLte(data: number, value: number): boolean
isLte(data: number, value: number): boolean
Indicates whether data
is less than or equal to value
Source§isNonNegative(data: number): boolean
isNonNegative(data: number): boolean
Indicates whether a number is non-negative, i.e., positive or zero.
Source§linearMap(data: number, x1: number, x2: number, y1: number, y2: number): number
linearMap(data: number, x1: number, x2: number, y1: number, y2: number): number
Maps a value data
from the range [x1
, x2
] to the range [y1
, y2
].
Source§mathModulo(data: number, modulus: number): number
mathModulo(data: number, modulus: number): number
Calculates data
mod modulus
using KKnuth's definition of modulus,
which reflects the definition of mod used in mathematics. For a function
that follows JavaScript's %
operator instead, see modulo.
Source§maximum(data: number[]): number
maximum(data: number[]): number
Returns the maximum value of the array, or NaN
if the array is empty.
Source§maximumWith<I extends any[]>(
data: I,
transform: (x: ElementType<I>) => number,
): number
maximumWith<I extends any[]>(
data: I,
transform: (x: ElementType<I>) => number,
): number
Applies a transform
to each element of the array, then returns the maximum
of the transformed array. Returns NaN
if the array is empty.
Source§maximumWith<I extends any[]>(
transform: (x: ElementType<I>) => number,
): (data: I) => number
maximumWith<I extends any[]>(
transform: (x: ElementType<I>) => number,
): (data: I) => number
Source§mean(data: number[]): number
mean(data: number[]): number
Returns the mean of an array of numbers, or NaN
if the array is empty.
Source§meanWith<I extends any[]>(
data: I,
transform: Fn<ElementType<I>, number>,
): number
meanWith<I extends any[]>(
data: I,
transform: Fn<ElementType<I>, number>,
): number
Applies the transform
function to each element of an array, then returns
the mean of the result. Returns NaN
if the array is empty.
Source§meanWith<I extends any[]>(
transform: Fn<ElementType<I>, number>,
): (data: I) => number
meanWith<I extends any[]>(
transform: Fn<ElementType<I>, number>,
): (data: I) => number
Source§minimum(data: number[]): number
minimum(data: number[]): number
Returns the minimum value of the array, or NaN
if the array is empty.
Source§minimumWith<I extends any[]>(
data: I,
transform: (x: ElementType<I>) => number,
): number
minimumWith<I extends any[]>(
data: I,
transform: (x: ElementType<I>) => number,
): number
Applies a transform
to each element of the array, then returns the minimum
of the transformed array. Returns NaN
if the array is empty.
Source§minimumWith<I extends any[]>(
transform: (x: ElementType<I>) => number,
): (data: I) => number
minimumWith<I extends any[]>(
transform: (x: ElementType<I>) => number,
): (data: I) => number
Source§modulo(data: number, modulus: number): number
modulo(data: number, modulus: number): number
Calculates data
mod modulus
. modulo
is implemented with the %
operator,
so it follows the JavaScript specification that the sign of a % b
is the sign of a
,
and values are not required to be integers. See mathModulo for a function that
follows Knuth's definition, which better reflects the use of mod in mathematics.
Source§nthRoot(data: number, n: number): number
nthRoot(data: number, n: number): number
Calculates the n
th root of data
. n
must be an integer and at least 2,
or NaN
will result.
Source§pow(data: number, exponent: number): number
pow(data: number, exponent: number): number
Raises data
to the power of exponent
. This is a thin wrapper around
the built-in Math.pow
, so it has the same limitations, such as being unable
to calculate non-integrer powers of negative bases. See nthRoot for
a function that addresses part of these limitations.
Source§product(data: number[]): number
product(data: number[]): number
Returns the product of an array of numbers, or if the array is empty, 1.
Source§round(data: number, places: number): number
round(data: number, places: number): number
Rounds a number to places
digits after the decimal. If places
is negative,
rounding will be to -places
digits before the decimal point, e.g., places
of -2
will round to the nearest hundred. places
must be an integer.
Source§sum(data: number[]): number
sum(data: number[]): number
Returns the sum of an array of numbers, or sero if the array is empty.
Source§sumWith<I extends any[]>(data: I, transform: Fn<ElementType<I>, number>): number
sumWith<I extends any[]>(data: I, transform: Fn<ElementType<I>, number>): number
Applies the transform
function to each element in data
,
then returns the sum of the transformed array.
Source§sumWith<I extends any[]>(
transform: Fn<ElementType<I>, number>,
): (data: I) => number
sumWith<I extends any[]>(
transform: Fn<ElementType<I>, number>,
): (data: I) => number
Object§
Source§allProps<I extends POJO<any>>(
data: I,
condition: Predicate<ValueType<I>>,
): boolean
allProps<I extends POJO<any>>(
data: I,
condition: Predicate<ValueType<I>>,
): boolean
Returns true if all values of the data
object pass the condition
condition,
otherwise false.
Source§hasKey<I extends POJO<any>>(data: I, key: string): boolean
hasKey<I extends POJO<any>>(data: I, key: string): boolean
Indicates whether the object data
contains a given key
.
If a key is directly to undefined
, the object is still considered to contain the key.
Implemented using hasOwnProperty
.
Source§isKeyOf(data: string, obj: POJO<any>): boolean
isKeyOf(data: string, obj: POJO<any>): boolean
Tells whether the plain object obj
has its own key named data
.
Source§mapProps<I extends POJO<any>, O extends POJO<any>>(
data: I,
transform: (x: ValueType<I>) => ValueType<O>,
): O
mapProps<I extends POJO<any>, O extends POJO<any>>(
data: I,
transform: (x: ValueType<I>) => ValueType<O>,
): O
Applies a transform function to each property value in the object.
Source§mapProps<I extends POJO<any>, O extends POJO<any>>(
transform: (x: ValueType<I>) => ValueType<O>,
): (data: I) => O
mapProps<I extends POJO<any>, O extends POJO<any>>(
transform: (x: ValueType<I>) => ValueType<O>,
): (data: I) => O
Source§noProps<I extends POJO<any>>(
data: I,
condition: Predicate<ValueType<I>>,
): boolean
noProps<I extends POJO<any>>(
data: I,
condition: Predicate<ValueType<I>>,
): boolean
Returns true if no value of the data
object passes the condition
condition, otherwise false.
Source§notAllProps<I extends POJO<any>>(
data: I,
condition: Predicate<ValueType<I>>,
): boolean
notAllProps<I extends POJO<any>>(
data: I,
condition: Predicate<ValueType<I>>,
): boolean
Returns true if at least one value of the data
object fails the condition
condition, otherwise false.
§pickKeys<I extends POJO<any>, O = Partial<I>>(data: I, keys: (keyof I)[]): O
pickKeys<I extends POJO<any>, O = Partial<I>>(data: I, keys: (keyof I)[]): O
Returns a new object consisting of only the portion of the data
object with the specified keys
.
§pickKeys<I extends POJO<any>, O = Partial<I>>(keys: string[]): (data: I) => O
pickKeys<I extends POJO<any>, O = Partial<I>>(keys: string[]): (data: I) => O
Returns a new object consisting of only the portion of the data
object with the specified keys
.
Source§propOr<I extends POJO<any>>(
data: I,
key: string,
fallback: ValueType<I>,
): ValueType<I>
propOr<I extends POJO<any>>(
data: I,
key: string,
fallback: ValueType<I>,
): ValueType<I>
Returns the value of an { x: 5 }ect property key
if it exists, or the fallback
value otherwise.
Source§propOr<I extends POJO<any>>(
key: string,
fallback: ValueType<I>,
): (data: I) => ValueType<I>
propOr<I extends POJO<any>>(
key: string,
fallback: ValueType<I>,
): (data: I) => ValueType<I>
Source§propPasses<I extends POJO<any>>(
data: I,
key: string,
condition: Predicate<ValueType<I>>,
): boolean
propPasses<I extends POJO<any>>(
data: I,
key: string,
condition: Predicate<ValueType<I>>,
): boolean
Returns true if an object property key
exists and passes the condition
, false otherwise.
Source§propPasses<I extends POJO<any>>(
key: string,
condition: Predicate<ValueType<I>>,
): (data: I) => boolean
propPasses<I extends POJO<any>>(
key: string,
condition: Predicate<ValueType<I>>,
): (data: I) => boolean
Other§
Source§createArrayRange(start: number, end: number, spacing: SpacingOption): number[]
createArrayRange(start: number, end: number, spacing: SpacingOption): number[]
Creates an array of equally spaced numbers from start
to end
. You may control
the spacing or number of points by setting any of the following:
n.intervals
e.g., [1, 2, 3] would have two intervals--1 to 2 and 2 to 3 (minimum 1).n.points
to set the total number of points (minimum 2)n.size
to set the difference between successive points. Ifend - start
does not divide evenly byn.space
, thenn.space
will automatically be adjusted to allow even spacing.
If the value of n
is not valid, then an empty array will be returned.
String§
Source§append<I extends string | any[]>(data: I, value: I): I
append<I extends string | any[]>(data: I, value: I): I
Returns a data
the value
array appended. To append an element
(rather than another array) to an array instead, use appendElement.
Source§charAt(data: string, index: number): string
charAt(data: string, index: number): string
Returns the element of data
at index
, or an empty string if index
is out of bounds
or otherwise invalid.
Source§contains(data: string | any[], value: any): boolean
contains(data: string | any[], value: any): boolean
Indicates whether or not the data
array contains the element value
,
or the data
string contains the substring value
.
Source§everyMatch(data: string, regex: RegExp): string[]
everyMatch(data: string, regex: RegExp): string[]
Returns an array containing all matches to regex
in the string
data
, or an empty array if there are no matches. The global
flag will be added automatically if not already present on regex
,
since this function is designed to get all matches. (To return
only the first match, use {@link: firstMatch} instead.)
Source§firstMatch(data: string, regex: RegExp): string
firstMatch(data: string, regex: RegExp): string
Returns the first match to regex
in data
, or an empty string if no match exists. The global flag will be removed from regex
automatically if present, since this function is designed to find
only the first match. (To return all matches, use everyMatch
instead.)
Source§insert<I extends string | any[]>(
data: I,
index: number,
content: I extends any[] ? ElementType<I<I>> : string,
): I
insert<I extends string | any[]>(
data: I,
index: number,
content: I extends any[] ? ElementType<I<I>> : string,
): I
Inserts the content
element into the data
array, or the content
substring into the data
string
at the index
position. If index
is equal to the length of data
, then content
will be
appended to the end. Returns a shallow copy of data
if the index is invalid.
Source§insert<I extends string | any[]>(
index: number,
content: I extends any[] ? ElementType<I<I>> : string,
): (data: I) => I
insert<I extends string | any[]>(
index: number,
content: I extends any[] ? ElementType<I<I>> : string,
): (data: I) => I
Source§isNotEmpty(data: string | any[]): boolean
isNotEmpty(data: string | any[]): boolean
Indicates whether a string or array has length of at least one.
Source§lengthPasses(data: string | any[], condition: Predicate<number>): boolean
lengthPasses(data: string | any[], condition: Predicate<number>): boolean
Indicates whether the length of the data
string or array passes the condition
.
Source§lengthPasses<I extends string | any[]>(
condition: Predicate<number>,
): (data: string | any[]) => boolean
lengthPasses<I extends string | any[]>(
condition: Predicate<number>,
): (data: string | any[]) => boolean
Source§lowerCase(data: string): string
lowerCase(data: string): string
Returns a copy of a string with all upper case letters changed to lower case.
Source§matchesRegex(data: string, regex: RegExp): boolean
matchesRegex(data: string, regex: RegExp): boolean
Returns true
if the string data
matches the regular expression regex
, false
otherwise.
Source§padLeft(data: string | number, length: number, chars: string): string
padLeft(data: string | number, length: number, chars: string): string
If the string data
is shorter than length
characters, then adds copies of chars
to the left of the string until the string length
is reached. If chars
is more
than one character in length, the last copy will be truncated if necessary to reach
the exact target length
.
Returns the data unchanged if length
is not an integer, or if chars
is an
empty string.
Source§padRight(data: string | number, length: number, chars: string): string
padRight(data: string | number, length: number, chars: string): string
If the string data
is shorter than length
characters, then adds copies of chars
to the right of the string until the string length
is reached. If chars
is more
than one character in length, the last copy will be truncated if necessary to reach
the exact target length
.
Returns the data unchanged if length
is not an integer, or if chars
is an
empty string.
Source§prepend<I extends string | any[]>(data: I, value: I): I
prepend<I extends string | any[]>(data: I, value: I): I
Returns a data
the value
array prepended. To prepend an element
(rather than another array) to an array instead, use prependElement.
Source§replaceSubstrings(
data: string,
target: string | RegExp,
replacement: string | ((s: string) => string),
): string
replaceSubstrings(
data: string,
target: string | RegExp,
replacement: string | ((s: string) => string),
): string
Replaces all instances of target
in data
with either a string replacement
or a
transformed string if target
is a function. If target
is aregular expression,
the global flag will be added automatically if it isn't already there, since this function
always replaces all innstances.
Source§replaceSubstrings(
target: string | RegExp,
replacement: string | ((s: string) => string),
): (data: string) => string
replaceSubstrings(
target: string | RegExp,
replacement: string | ((s: string) => string),
): (data: string) => string
Source§slice<I extends string | any[]>(data: I, from: number, to: number): I
slice<I extends string | any[]>(data: I, from: number, to: number): I
Returns a shallow copy of the portion of the data
array or string beginning at index
from
and ending with, but not including, the index to
. Negative index values count
backward from the end of the arrry. Returns an empty array if from
or to
is not an
integer, or if from
is out of the array bounds.
Source§sliceFrom<I extends string | any[]>(data: I, from: number): I
sliceFrom<I extends string | any[]>(data: I, from: number): I
Returns a shallow copy of the data
array or string starting from index from
.
A negative index counts backwards from the end of the array.
Returns an empty array if from
is not an integer or is out of bounds.
Source§sliceTo<I extends string | any[]>(data: I, to: number): I
sliceTo<I extends string | any[]>(data: I, to: number): I
Return a shallow copy of the data
array or string up to, but not including,
the index 'to. Returns an empty array if
to` is not an integer.
Source§split(data: string, separator: string | RegExp): string[]
split(data: string, separator: string | RegExp): string[]
Splits the data
string into an array of substrings based on the separator
string or regular expression. This is a wrapper around the built-in
String.prototype.split
(but without the limit
parameter), so it will exhibit
the same behavior for capturing groups, empty strings, etc. See the
MDN reference for details.
Source§stripWhiteSpace(data: string): string
stripWhiteSpace(data: string): string
Removes all white space characters (as identified by
the regular expression \s
) from the string and
returns the result.
Source§toHex(data: number): string
toHex(data: number): string
Converts a number to a string in hexadecimal form, or returns an empty string if the number is not an non-negative integer.
Source§trim(data: string): string
trim(data: string): string
A thin wrapper around the built-in String.prototype.trim
to facilitate
use in functional pipelines.
Source§trimLeft(data: string): string
trimLeft(data: string): string
A thin wrapper around the built-in String.prototype.trimStart
to facilitate
use in functional pipelines.
Returns true if all elements of the
data
array pass the condition.