@stdlib/utils
Version:
Standard utilities.
1,709 lines (1,657 loc) • 184 kB
TypeScript
/*
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TypeScript Version: 4.1
/* eslint-disable max-lines */
import any = require( './../../any' );
import anyBy = require( './../../any-by' );
import anyByRight = require( './../../any-by-right' );
import append = require( './../../append' );
import argumentFunction = require( './../../argument-function' );
import async = require( './../../async' );
import bifurcate = require( './../../bifurcate' );
import bifurcateBy = require( './../../bifurcate-by' );
import bifurcateIn = require( './../../bifurcate-in' );
import bifurcateOwn = require( './../../bifurcate-own' );
import capitalizeKeys = require( './../../capitalize-keys' );
import CircularBuffer = require( './../../circular-buffer' );
import commonKeys = require( './../../common-keys' );
import commonKeysIn = require( './../../common-keys-in' );
import CompactAdjacencyMatrix = require( './../../compact-adjacency-matrix' );
import compose = require( './../../compose' );
import constantFunction = require( './../../constant-function' );
import constructorName = require( './../../constructor-name' );
import convertPath = require( './../../convert-path' );
import copy = require( './../../copy' );
import countBy = require( './../../count-by' );
import curry = require( './../../curry' );
import curryRight = require( './../../curry-right' );
import decorateAfter = require( './../../decorate-after' );
import deepGet = require( './../../deep-get' );
import deepPluck = require( './../../deep-pluck' );
import deepSet = require( './../../deep-set' );
import setConfigurableReadOnlyAccessor = require( './../../define-configurable-read-only-accessor' );
import setConfigurableReadOnly = require( './../../define-configurable-read-only-property' );
import setConfigurableReadWriteAccessor = require( './../../define-configurable-read-write-accessor' );
import setConfigurableWriteOnlyAccessor = require( './../../define-configurable-write-only-accessor' );
import setMemoizedConfigurableReadOnly = require( './../../define-memoized-configurable-read-only-property' );
import defineMemoizedProperty = require( './../../define-memoized-property' );
import setMemoizedReadOnly = require( './../../define-memoized-read-only-property' );
import setNonEnumerableProperty = require( './../../define-nonenumerable-property' );
import setNonEnumerableReadOnlyAccessor = require( './../../define-nonenumerable-read-only-accessor' );
import setNonEnumerableReadOnly = require( './../../define-nonenumerable-read-only-property' );
import setNonEnumerableReadWriteAccessor = require( './../../define-nonenumerable-read-write-accessor' );
import setNonEnumerableWriteOnlyAccessor = require( './../../define-nonenumerable-write-only-accessor' );
import defineProperties = require( './../../define-properties' );
import defineProperty = require( './../../define-property' );
import setReadOnlyAccessor = require( './../../define-read-only-accessor' );
import setReadOnly = require( './../../define-read-only-property' );
import setReadWriteAccessor = require( './../../define-read-write-accessor' );
import setWriteOnlyAccessor = require( './../../define-write-only-accessor' );
import dirname = require( './../../dirname' );
import doUntil = require( './../../do-until' );
import doUntilEach = require( './../../do-until-each' );
import doUntilEachRight = require( './../../do-until-each-right' );
import doWhile = require( './../../do-while' );
import doWhileEach = require( './../../do-while-each' );
import doWhileEachRight = require( './../../do-while-each-right' );
import DoublyLinkedList = require( './../../doubly-linked-list' );
import dsv = require( './../../dsv' );
import objectEntries = require( './../../entries' );
import objectEntriesIn = require( './../../entries-in' );
import enumerableProperties = require( './../../enumerable-properties' );
import enumerablePropertiesIn = require( './../../enumerable-properties-in' );
import enumerablePropertySymbols = require( './../../enumerable-property-symbols' );
import enumerablePropertySymbolsIn = require( './../../enumerable-property-symbols-in' );
import rescape = require( './../../escape-regexp-string' );
import evil = require( './../../eval' );
import every = require( './../../every' );
import everyBy = require( './../../every-by' );
import everyByRight = require( './../../every-by-right' );
import extname = require( './../../extname' );
import FIFO = require( './../../fifo' );
import filterArguments = require( './../../filter-arguments' );
import find = require( './../../find' );
import flattenArray = require( './../../flatten-array' );
import flattenObject = require( './../../flatten-object' );
import forEach = require( './../../for-each' );
import forEachRight = require( './../../for-each-right' );
import forIn = require( './../../for-in' );
import forOwn = require( './../../for-own' );
import objectFromEntries = require( './../../from-entries' );
import functionName = require( './../../function-name' );
import functionSequence = require( './../../function-sequence' );
import getPrototypeOf = require( './../../get-prototype-of' );
import getGlobal = require( './../../global' );
import group = require( './../../group' );
import groupBy = require( './../../group-by' );
import groupIn = require( './../../group-in' );
import groupOwn = require( './../../group-own' );
import identity = require( './../../identity-function' );
import ifelse = require( './../../if-else' );
import ifthen = require( './../../if-then' );
import indexOf = require( './../../index-of' );
import inherit = require( './../../inherit' );
import inheritedEnumerableProperties = require( './../../inherited-enumerable-properties' );
import inheritedEnumerablePropertySymbols = require( './../../inherited-enumerable-property-symbols' );
import inheritedKeys = require( './../../inherited-keys' );
import inheritedNonEnumerableProperties = require( './../../inherited-nonenumerable-properties' );
import inheritedNonEnumerablePropertyNames = require( './../../inherited-nonenumerable-property-names' );
import inheritedNonEnumerablePropertySymbols = require( './../../inherited-nonenumerable-property-symbols' );
import inheritedProperties = require( './../../inherited-properties' );
import inheritedPropertyDescriptor = require( './../../inherited-property-descriptor' );
import inheritedPropertyDescriptors = require( './../../inherited-property-descriptors' );
import inheritedPropertyNames = require( './../../inherited-property-names' );
import inheritedPropertySymbols = require( './../../inherited-property-symbols' );
import inheritedWritableProperties = require( './../../inherited-writable-properties' );
import inheritedWritablePropertyNames = require( './../../inherited-writable-property-names' );
import inheritedWritablePropertySymbols = require( './../../inherited-writable-property-symbols' );
import inmap = require( './../../inmap' );
import inmapRight = require( './../../inmap-right' );
import keyBy = require( './../../key-by' );
import keyByRight = require( './../../key-by-right' );
import objectKeys = require( './../../keys' );
import keysIn = require( './../../keys-in' );
import LinkedList = require( './../../linked-list' );
import lowercaseKeys = require( './../../lowercase-keys' );
import map = require( './../../map' );
import mapArguments = require( './../../map-arguments' );
import mapFun = require( './../../map-function' );
import mapKeys = require( './../../map-keys' );
import mapReduce = require( './../../map-reduce' );
import mapReduceRight = require( './../../map-reduce-right' );
import mapRight = require( './../../map-right' );
import mapValues = require( './../../map-values' );
import map2 = require( './../../map2' );
import map2Right = require( './../../map2-right' );
import map2d = require( './../../map2d' );
import map3d = require( './../../map3d' );
import map4d = require( './../../map4d' );
import map5d = require( './../../map5d' );
import maskArguments = require( './../../mask-arguments' );
import memoize = require( './../../memoize' );
import merge = require( './../../merge' );
import moveProperty = require( './../../move-property' );
import namedtypedtuple = require( './../../named-typed-tuple' );
import naryFunction = require( './../../nary-function' );
import nativeClass = require( './../../native-class' );
import nextTick = require( './../../next-tick' );
import none = require( './../../none' );
import noneBy = require( './../../none-by' );
import noneByRight = require( './../../none-by-right' );
import nonEnumerableProperties = require( './../../nonenumerable-properties' );
import nonEnumerablePropertiesIn = require( './../../nonenumerable-properties-in' );
import nonEnumerablePropertyNames = require( './../../nonenumerable-property-names' );
import nonEnumerablePropertyNamesIn = require( './../../nonenumerable-property-names-in' );
import nonEnumerablePropertySymbols = require( './../../nonenumerable-property-symbols' );
import nonEnumerablePropertySymbolsIn = require( './../../nonenumerable-property-symbols-in' );
import nonIndexKeys = require( './../../nonindex-keys' );
import noop = require( './../../noop' );
import objectInverse = require( './../../object-inverse' );
import objectInverseBy = require( './../../object-inverse-by' );
import omit = require( './../../omit' );
import omitBy = require( './../../omit-by' );
import openURL = require( './../../open-url' );
import papply = require( './../../papply' );
import papplyRight = require( './../../papply-right' );
import parallel = require( './../../parallel' );
import parseJSON = require( './../../parse-json' );
import pick = require( './../../pick' );
import pickArguments = require( './../../pick-arguments' );
import pickBy = require( './../../pick-by' );
import pluck = require( './../../pluck' );
import pop = require( './../../pop' );
import prepend = require( './../../prepend' );
import properties = require( './../../properties' );
import propertiesIn = require( './../../properties-in' );
import propertyDescriptor = require( './../../property-descriptor' );
import propertyDescriptorIn = require( './../../property-descriptor-in' );
import propertyDescriptors = require( './../../property-descriptors' );
import propertyDescriptorsIn = require( './../../property-descriptors-in' );
import propertyNames = require( './../../property-names' );
import propertyNamesIn = require( './../../property-names-in' );
import propertySymbols = require( './../../property-symbols' );
import propertySymbolsIn = require( './../../property-symbols-in' );
import push = require( './../../push' );
import realmax = require( './../../real-max' );
import realmin = require( './../../real-min' );
import reduce = require( './../../reduce' );
import reduceRight = require( './../../reduce-right' );
import reduce2d = require( './../../reduce2d' );
import reFromString = require( './../../regexp-from-string' );
import rejectArguments = require( './../../reject-arguments' );
import reorderArguments = require( './../../reorder-arguments' );
import reverseArguments = require( './../../reverse-arguments' );
import safeintmax = require( './../../safe-int-max' );
import safeintmin = require( './../../safe-int-min' );
import shift = require( './../../shift' );
import sizeOf = require( './../../size-of' );
import some = require( './../../some' );
import someBy = require( './../../some-by' );
import someByRight = require( './../../some-by-right' );
import Stack = require( './../../stack' );
import tabulate = require( './../../tabulate' );
import tabulateBy = require( './../../tabulate-by' );
import thunk = require( './../../thunk' );
import timeit = require( './../../timeit' );
import trycatch = require( './../../try-catch' );
import tryFunction = require( './../../try-function' );
import tryRequire = require( './../../try-require' );
import trythen = require( './../../try-then' );
import typemax = require( './../../type-max' );
import typemin = require( './../../type-min' );
import typeOf = require( './../../type-of' );
import uncapitalizeKeys = require( './../../uncapitalize-keys' );
import uncurry = require( './../../uncurry' );
import uncurryRight = require( './../../uncurry-right' );
import unshift = require( './../../unshift' );
import until = require( './../../until' );
import untilEach = require( './../../until-each' );
import untilEachRight = require( './../../until-each-right' );
import unzip = require( './../../unzip' );
import uppercaseKeys = require( './../../uppercase-keys' );
import objectValues = require( './../../values' );
import objectValuesIn = require( './../../values-in' );
import whilst = require( './../../while' );
import whileEach = require( './../../while-each' );
import whileEachRight = require( './../../while-each-right' );
import writableProperties = require( './../../writable-properties' );
import writablePropertiesIn = require( './../../writable-properties-in' );
import writablePropertyNames = require( './../../writable-property-names' );
import writablePropertyNamesIn = require( './../../writable-property-names-in' );
import writablePropertySymbols = require( './../../writable-property-symbols' );
import writablePropertySymbolsIn = require( './../../writable-property-symbols-in' );
import zip = require( './../../zip' );
/**
* Interface describing the `utils` namespace.
*/
interface Namespace {
/**
* Tests whether at least one element in a collection is truthy.
*
* ## Notes
*
* - The function immediately returns upon encountering a truthy value.
* - If provided an empty collection, the function returns `false`.
*
* @param collection - input collection
* @returns boolean indicating whether at least one element is truthy
*
* @example
* var arr = [ 0, 0, 0, 0, 1 ];
*
* var bool = ns.any( arr );
* // returns true
*/
any: typeof any;
/**
* Tests whether at least one element in a collection passes a test implemented by a predicate function, iterating from right to left.
*
* ## Notes
*
* - The predicate function is provided three arguments:
*
* - `value`: collection value
* - `index`: collection index
* - `collection`: the input collection
*
* - The function immediately returns upon encountering a truthy return value.
*
* - If provided an empty collection, the function returns `false`.
*
* @param collection - input collection
* @param predicate - test function
* @param thisArg - execution context
* @returns boolean indicating whether at least one element passes a test
*
* @example
* function isNegative( v ) {
* return ( v < 0 );
* }
*
* var arr = [ 1, 2, 3, 4, -1 ];
*
* var bool = ns.anyBy( arr, isNegative );
* // returns true
*/
anyBy: typeof anyBy;
/**
* Tests whether at least one element in a collection passes a test implemented by a predicate function.
*
* ## Notes
*
* - The predicate function is provided three arguments:
*
* - `value`: collection value
* - `index`: collection index
* - `collection`: the input collection
*
* - The function immediately returns upon encountering a truthy return value.
*
* - If provided an empty collection, the function returns `false`.
*
* @param collection - input collection
* @param predicate - test function
* @param thisArg - execution context
* @returns boolean indicating whether at least one element passes a test
*
* @example
* function isNegative( v ) {
* return ( v < 0 );
* }
*
* var arr = [ -1, 1, 2, 3, 4 ];
*
* var bool = ns.anyByRight( arr, isNegative );
* // returns true
*/
anyByRight: typeof anyByRight;
/**
* Adds elements from one collection to the end of another collection.
*
* @param collection1 - collection
* @param collection2 - collection containing elements to add
* @returns updated collection
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
*
* arr = ns.append( arr, [ 6.0, 7.0 ] );
* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
*
* arr = ns.append( arr, [ 6.0, 7.0 ] );
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
*/
append: typeof append;
/**
* Returns a function which always returns a specified argument.
*
* ## Notes
*
* - The input argument corresponds to the zero-based index of the argument to return.
*
* @param idx - argument index
* @throws must provide a nonnegative integer
* @returns argument function
*
* @example
* var argn = ns.argumentFunction( 1 );
*
* var v = argn( 1.0, 2.0, 3.0 );
* // returns 2.0
*
* v = argn( 'a', 'b', 'c' );
* // returns 'b'
*
* v = argn( null );
* // returns undefined
*/
argumentFunction: typeof argumentFunction;
/**
* Standard async utilities.
*/
async: typeof async;
/**
* Splits values into two groups.
*
* ## Notes
*
* - If an element in `filter` is truthy, then the corresponding element in the input collection belongs to the first group; otherwise, the collection element belongs to the second group.
* - If provided an empty collection, the function returns an empty array.
*
* @param collection - input collection
* @param options - function options
* @param options.returns - if `values`, values are returned; if `indices`, indices are returned; if `*`, both indices and values are returned (default: 'values')
* @param filter - collection indicating which group an element in the input collection belongs to
* @throws first and last arguments must be the same length
* @returns results
*
* @example
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
* var filter = [ true, true, false, true ];
*
* var opts = {
* 'returns': 'indices'
* };
*
* var out = ns.bifurcate( arr, opts, filter );
* // returns [ [ 0, 1, 3 ], [ 2 ] ]
*
* @example
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
* var filter = [ true, true, false, true ];
*
* var opts = {
* 'returns': '*'
* };
*
* var out = ns.bifurcate( arr, opts, filter );
* // returns [ [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], [ [ 2, 'foo' ] ] ]
*/
bifurcate: typeof bifurcate;
/**
* Splits values into two groups according to a predicate function.
*
* ## Notes
*
* - When invoked, the predicate function is provided two arguments:
*
* - `value`: collection value
* - `index`: collection index
*
* - If a predicate function returns a truthy value, a collection value is placed in the first group; otherwise, a collection value is placed in the second group.
*
* - If provided an empty collection, the function returns an empty array.
*
* @param collection - input collection
* @param options - function options
* @param options.thisArg - execution context
* @param options.returns - if `'values'`, values are returned; if `'indices'`, indices are returned; if `'*'`, both indices and values are returned (default: 'values')
* @param predicate - predicate function indicating which group an element in the input collection belongs to
* @returns group results
*
* @example
* function predicate( v ) {
* return v[ 0 ] === 'b';
* }
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
*
* var opts = {
* 'returns': '*'
* };
* var out = ns.bifurcateBy( arr, opts, predicate );
* // returns [ [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], [ [ 2, 'foo' ] ] ]
*/
bifurcateBy: typeof bifurcateBy;
/**
* Splits an object's own and inherited property values into two groups according to a predicate function.
*
* ## Notes
*
* - When invoked, the predicate function is provided two arguments:
*
* - `value`: object value
* - `key`: object key
*
* - If a predicate function returns a truthy value, a value is placed in the first group; otherwise, a value is placed in the second group.
*
* - If provided an empty object with no prototype, the function returns an empty array.
*
* - The function iterates over an object's own and inherited properties.
*
* - Key iteration order is *not* guaranteed, and, thus, result order is *not* guaranteed.
*
* @param obj - input object
* @param options - function options
* @param options.thisArg - execution context
* @param options.returns - if `'values'`, values are returned; if `'keys'`, keys are returned; if `'*'`, both keys and values are returned (default: 'values')
* @param predicate - predicate function indicating which group an element in the input object belongs to
* @returns group results
*
* @example
* function predicate( v ) {
* return v[ 0 ] === 'b';
* }
*
* function Foo() {
* this.a = 'beep';
* this.b = 'boop';
* return this;
* }
*
* Foo.prototype = Object.create( null );
* Foo.prototype.c = 'foo';
* Foo.prototype.d = 'bar';
*
* var obj = new Foo();
*
* var opts = {
* 'returns': 'keys'
* };
* var out = ns.bifurcateIn( obj, opts, predicate );
* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ]
*
* @example
* function predicate( v ) {
* return v[ 0 ] === 'b';
* }
*
* function Foo() {
* this.a = 'beep';
* this.b = 'boop';
* return this;
* }
*
* Foo.prototype = Object.create( null );
* Foo.prototype.c = 'foo';
* Foo.prototype.d = 'bar';
*
* var obj = new Foo();
*
* var opts = {
* 'returns': '*'
* };
* var out = ns.bifurcateIn( obj, opts, predicate );
* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ]
*/
bifurcateIn: typeof bifurcateIn;
/**
* Splits an object's own property values into two groups according to a predicate function.
*
* @param obj - input object
* @param options - function options
* @param options.thisArg - execution context
* @param options.returns - if `'values'`, values are returned; if `'keys'`, keys are returned; if `'*'`, both keys and values are returned
* @param predicate - predicate function indicating which group an element in the input object belongs to
* @returns group results
*
* @example
* function predicate( v ) {
* return v[ 0 ] === 'b';
* }
* var obj = {
* 'a': 'beep',
* 'b': 'boop',
* 'c': 'foo',
* 'd': 'bar'
* };
* var out = ns.bifurcateOwn( obj, predicate );
* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
*
* @example
* function predicate( v ) {
* return v[ 0 ] === 'b';
* }
* var obj = {
* 'a': 'beep',
* 'b': 'boop',
* 'c': 'foo',
* 'd': 'bar'
* };
* var opts = {
* 'returns': 'keys'
* };
* var out = ns.bifurcateOwn( obj, opts, predicate );
* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ]
*
* @example
* function predicate( v ) {
* return v[ 0 ] === 'b';
* }
* var obj = {
* 'a': 'beep',
* 'b': 'boop',
* 'c': 'foo',
* 'd': 'bar'
* };
* var opts = {
* 'returns': '*'
* };
* var out = ns.bifurcateOwn( obj, opts, predicate );
* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ]
*/
bifurcateOwn: typeof bifurcateOwn;
/**
* Converts the first letter of each object key to uppercase.
*
* ## Notes
*
* - The function only transforms own properties. Hence, the function does not transform inherited properties.
* - The function shallow copies key values.
*
* @param obj - source object
* @returns new object
*
* @example
* var obj1 = {
* 'aa': 1,
* 'bb': 2
* };
*
* var obj2 = ns.capitalizeKeys( obj1 );
* // returns { 'Aa': 1, 'Bb': 2 }
*/
capitalizeKeys: typeof capitalizeKeys;
/**
* Circular buffer.
*/
CircularBuffer: typeof CircularBuffer;
/**
* Returns the common own property names of two or more objects.
*
* @param obj1 - first object
* @param obj2 - second object
* @param obj - additional objects
* @returns common keys of objects
*
* @example
* var obj = {
* 'a': 1,
* 'b': 2,
* 'c': 3
* };
*
* var obj2 = {
* 'a': 1,
* 'b': 2
* };
*
* var keys = ns.commonKeys( obj, obj2 );
* // returns [ 'a', 'b' ]
*
* @example
* var obj1 = {
* 'a': 1,
* 'b': 2,
* 'c': 3
* };
*
* var obj2 = {
* 'a': 1,
* 'b': 2
* };
*
* var obj3 = {
* 'a': 1,
* };
*
* var keys = ns.commonKeys( obj1, obj2, obj3 );
* // returns [ 'a' ]
*/
commonKeys: typeof commonKeys;
/**
* Returns the common own and inherited property names of two or more objects.
*
* @param obj1 - first object
* @param obj2 - second object
* @param obj - additional objects
* @returns common keys
*
* @example
* var obj = {
* 'a': 1,
* 'b': 2,
* 'c': 3
* };
*
* var obj2 = {
* 'a': 1,
* 'b': 2
* };
*
* var keys = ns.commonKeysIn( obj, obj2 );
* // returns [ 'a', 'b' ]
*
* @example
* var obj1 = {
* 'a': 1,
* 'b': 2,
* 'c': 3
* };
*
* var obj2 = {
* 'a': 1,
* 'b': 2
* };
*
* var obj3 = {
* 'a': 1,
* };
*
* var keys = ns.commonKeysIn( obj1, obj2, obj3 );
* // returns [ 'a' ]
*/
commonKeysIn: typeof commonKeysIn;
/**
* TODO
*
* @returns TODO
*
* @example
* // TODO
*/
CompactAdjacencyMatrix: typeof CompactAdjacencyMatrix;
/**
* Function composition.
*
* ## Notes
*
* - Returns a composite function. Starting from the right, the composite function evaluates each function and passes the result as an argument to the next function. The result of the leftmost function is the result of the whole.
* - Only the rightmost function is explicitly permitted to accept multiple arguments. All other functions are evaluated as unary functions.
* - The function will throw if provided fewer than two input arguments.
*
* @param fcn - functions to compose
* @throws must provide more than one argument
* @returns composite function
*
* @example
* function a( x ) {
* return 2 * x;
* }
*
* function b( x ) {
* return x + 3;
* }
*
* function c( x ) {
* return x / 5;
* }
*
* var f = ns.compose( c, b, a );
*
* var z = f( 6 );
* // returns 3
*/
compose: typeof compose;
/**
* Creates a function which always returns the same value.
*
* ## Notes
*
* - When provided an object reference, the returned `function` always returns the same reference.
*
* @param value - value to always return
* @returns constant function
*
* @example
* var fcn = ns.constantFunction( 3.14 );
*
* var v = fcn();
* // returns 3.14
*
* v = fcn();
* // returns 3.14
*
* v = fcn();
* // returns 3.14
*/
constantFunction: typeof constantFunction;
/**
* Determines the name of a value's constructor.
*
* @param v - input value
* @returns name of a value's constructor
*
* @example
* var v = ns.constructorName( 'a' );
* // returns 'String'
*
* @example
* var v = ns.constructorName( 5 );
* // returns 'Number'
*
* @example
* var v = ns.constructorName( null );
* // returns 'Null'
*
* @example
* var v = ns.constructorName( undefined );
* // returns 'Undefined'
*
* @example
* var v = ns.constructorName( function noop() {} );
* // returns 'Function'
*/
constructorName: typeof constructorName;
/**
* Converts between POSIX and Windows paths.
*
* @param from - path to convert
* @param to - output path convention
* @throws second argument must be a recognized output path convention
* @throws cannot convert a Windows extended-length path to a non-Windows path convention
* @returns converted path
*
* @example
* var p = ns.convertPath( '/c/foo/bar/beep.c', 'win32' );
* // returns 'c:\\foo\\bar\\beep.c'
*
* @example
* var p = ns.convertPath( '/c/foo/bar/beep.c', 'mixed' );
* // returns 'c:/foo/bar/beep.c'
*
* @example
* var p = ns.convertPath( 'C:\\foo\\bar\\beep.c', 'posix' );
* // returns '/c/foo/bar/beep.c'
*
* @example
* var p = ns.convertPath( 'C:\\foo\\bar\\beep.c', 'mixed' );
* // returns 'C:/foo/bar/beep.c'
*/
convertPath: typeof convertPath;
/**
* Copies or deep clones a value to an arbitrary depth.
*
* ## Notes
*
* - The implementation can handle circular references.
* - If a `Number`, `String`, or `Boolean` object is encountered, the value is cloned as a primitive. This behavior is intentional.
* - For objects, the implementation only copies enumerable keys and their associated property descriptors.
* - The implementation only checks whether basic `Objects`, `Arrays`, and class instances are extensible, sealed, and/or frozen.
* - Functions are not cloned; their reference is copied.
* - The implementation supports custom error types which are `Error` instances (e.g., ES2015 subclasses).
* - Support for copying class instances is inherently fragile. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This stated, basic copying of class instances is supported. Provided an environment which supports ES5, the implementation is greedy and performs a deep clone of any arbitrary class instance and its properties. The implementation assumes that the concept of `level` applies only to the class instance reference, but not to its internal state.
*
* @param value - value to copy
* @param level - copy depth (default: +infinity)
* @throws `level` must be a nonnegative integer
* @returns value copy
*
* @example
* var out = ns.copy( 'beep' );
* // returns 'beep'
*
* @example
* var value = [
* {
* 'a': 1,
* 'b': true,
* 'c': [ 1, 2, 3 ]
* }
* ];
* var out = ns.copy( value );
* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]
*
* var bool = ( value[0].c === out[0].c );
* // returns false
*/
copy: typeof copy;
/**
* Groups values according to an indicator function and returns group counts.
*
* ## Notes
*
* - When invoked, the indicator function is provided two arguments:
*
* - `value`: collection value
* - `index`: collection index
*
* - The value returned by an indicator function should be a value which can be serialized as an object key.
*
* - If provided an empty collection, the function returns an empty object.
*
* @param collection - input collection
* @param options - function options
* @param options.thisArg - execution context
* @param indicator - indicator function specifying which group an element in the input collection belongs to
* @returns counts
*
* @example
* function indicator( v ) {
* return v[ 0 ];
* }
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
*
* var out = ns.countBy( arr, indicator );
* // returns { 'b': 3, 'f': 1 }
*/
countBy: typeof countBy;
/**
* Transforms a function into a sequence of functions each accepting a single argument.
*
* ## Notes
*
* - Until return value resolution, each invocation returns a new partially applied curry function.
*
* @param fcn - function to curry
* @param thisArg - evaluation context
* @returns curry function
*
* @example
* function add( x, y ) {
* return x + y;
* }
*
* var f = ns.curry( add );
*
* var sum = f( 2 )( 3 );
* // returns 5
*/
curry: typeof curry;
/**
* Transforms a function into a sequence of functions each accepting a single argument.
*
* ## Notes
*
* - Until return value resolution, each invocation returns a new partially applied curry function.
* - This function applies arguments starting from the right.
*
* @param fcn - function to curry
* @param thisArg - evaluation context
* @returns curry function
*
* @example
* function add( x, y ) {
* return x + y;
* }
*
* var f = ns.curryRight( add );
*
* var sum = f( 2 )( 3 );
* // returns 5
*/
curryRight: typeof curryRight;
/**
* Decorates a provided function such that the function's return value is provided as an argument to another function.
*
* @param fcn - function to decorate
* @param arity - number of parameters
* @param after - function to invoke with the return value of the decorated function
* @param thisArg - evaluation context for `after`
* @throws `arity` must be a nonnegative integer
* @returns decorator
*
* @example
* var abs = require( '@stdlib/math/base/special/abs' );
*
* function negate( v ) {
* return -v;
* }
*
* var f = ns.decorateAfter( abs, 1, negate );
* // returns <Function>
*
* var v = f( -5 );
* // returns -5
*
* v = f( 5 );
* // returns -5
*
* @example
* var abs = require( '@stdlib/math/base/special/abs' );
*
* function negate( v ) {
* return -v;
* }
*
* var f = ns.decorateAfter.factory( abs, 1, negate );
* // returns <Function>
*
* var v = f( -5 );
* // returns -5
*
* v = f( 5 );
* // returns -5
*/
decorateAfter: typeof decorateAfter;
/**
* Returns a nested property value.
*
* @param obj - input object
* @param path - key path
* @param options - function options
* @param options.sep - key path separator (default: '.')
* @returns nested property value
*
* @example
* var obj = { 'a': { 'b': { 'c': 'd' } } };
*
* var val = ns.deepGet( obj, 'a.b.c' );
* // returns 'd'
*
* @example
* var dget = ns.deepGet.factory( 'a/b/c', {
* 'sep': '/'
* });
*
* var obj = { 'a': { 'b': { 'c': 'd' } } };
*
* var val = dget( obj );
* // returns 'd'
*/
deepGet: typeof deepGet;
/**
* Extracts a nested property value from each element of an object array.
*
* ## Notes
*
* - If a key path does not exist, the function sets the plucked value as `undefined`.
* - Extracted values are not cloned.
*
* @param arr - source array
* @param path - key path
* @param options - function options
* @param options.copy - boolean indicating whether to return a new data structure (default: true)
* @param options.sep - key path separator (default: '.')
* @returns destination array
*
* @example
* var arr = [
* {'a':{'b':{'c':1}}},
* {'a':{'b':{'c':2}}}
* ];
*
* var out = ns.deepPluck( arr, 'a.b.c' );
* // returns [ 1, 2 ]
*
* @example
* var arr = [
* {'a':[0,1,2]},
* {'a':[3,4,5]}
* ];
*
* var out = ns.deepPluck( arr, ['a',1] );
* // returns [ 1, 4 ]
*
* @example
* var arr = [
* {'a':{'b':{'c':1}}},
* {'a':{'b':{'c':2}}}
* ];
*
* var out = ns.deepPluck( arr, 'a.b.c', {'copy':false} );
* // returns [ 1, 2 ]
*
* var bool = ( arr[ 0 ] === out[ 0 ] );
* // returns true
*
* @example
* var arr = [
* {'a':{'b':{'c':1}}},
* {'a':{'b':{'c':2}}}
* ];
*
* var out = ns.deepPluck( arr, 'a|b|c', {'sep':'|'} );
* // returns [ 1, 2 ]
*/
deepPluck: typeof deepPluck;
/**
* Sets a nested property value.
*
* @param obj - input object
* @param path - key path
* @param value - value to set
* @param options - function options
* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false)
* @param options.sep - key path separator (default: '.')
* @returns boolean indicating if the property was successfully set
*
* @example
* var obj = { 'a': { 'b': { 'c': 'd' } } };
* var bool = ns.deepSet( obj, 'a.b.c', 'woot' );
* // returns true
*
* @example
* var obj = { 'a': { 'b': { 'c': 'd' } } };
* var bool = ns.deepSet( obj, 'a.beep.c', 'boop' );
* // returns false
*
* @example
* var obj = { 'a': { 'b': { 'c': 'd' } } };
* var bool = ns.deepSet( null, 'a.beep.c', 'boop' );
* // returns false
*
* @example
* var obj = { 'a': { 'b': { 'c': 'd' } } };
* bool = ns.deepSet( 'bap', 'a.beep.c', 'boop' );
* // returns false
*
* @example
* var arr = [
* { 'a': [ {'x': 5} ] },
* { 'a': [ {'x': 10} ] }
* ];
* var bool = ns.deepSet( arr, '1.a.0.x', 25 );
* // returns true
*
* @example
* var obj = { 'a': { 'b': { 'c': 'd' } } };
* var bool = ns.deepSet( obj, 'a/b/c', 'beep', {
* 'sep': '/'
* });
* // returns true
*
* @example
* var obj = { 'a': { 'b': { 'c': 'd' } } };
* var bool = ns.deepSet( obj, 'a.e.c', 'boop', {
* 'create': true
* });
* // returns true
*/
deepSet: typeof deepSet;
/**
* Defines a configurable read-only accessor.
*
* ## Notes
*
* - Configurable read-only accessors are **enumerable**.
*
* @param obj - object on which to define property
* @param prop - property name
* @param getter - get accessor
*
* @example
* var obj = {};
*
* function getter() {
* return 'bar';
* }
*
* ns.setConfigurableReadOnlyAccessor( obj, 'foo', getter );
*
* try {
* obj.foo = 'boop';
* } catch ( err ) {
* console.error( err.message );
* }
*/
setConfigurableReadOnlyAccessor: typeof setConfigurableReadOnlyAccessor;
/**
* Defines a configurable read-only property.
*
* ## Notes
*
* - Configurable read-only properties are **enumerable**.
*
* @param obj - object on which to define property
* @param prop - property name
* @param value - value to set
*
* @example
* var obj = {};
*
* ns.setConfigurableReadOnly( obj, 'foo', 'bar' );
*
* try {
* obj.foo = 'boop';
* } catch ( err ) {
* console.error( err.message );
* }
*/
setConfigurableReadOnly: typeof setConfigurableReadOnly;
/**
* Defines a configurable read-write accessor.
*
* ## Notes
*
* - Configurable read-write accessors are **enumerable**.
*
* @param obj - object on which to define property
* @param prop - property name
* @param getter - get accessor
* @param setter - set accessor
*
* @example
* var name = 'bar';
* var obj = {};
*
* function getter() {
* return name + ' foo';
* }
*
* function setter( v ) {
* name = v;
* }
*
* ns.setConfigurableReadWriteAccessor( obj, 'foo', getter, setter );
*
* var v = obj.foo;
* // returns 'bar foo'
*
* obj.foo = 'beep';
*
* v = obj.foo;
* // returns 'beep foo'
*/
setConfigurableReadWriteAccessor: typeof setConfigurableReadWriteAccessor;
/**
* Defines a configurable write-only accessor.
*
* ## Notes
*
* - Configurable write-only accessors are **enumerable**.
*
* @param obj - object on which to define property
* @param prop - property name
* @param setter - set accessor
*
* @example
* var obj = {};
* var val = '';
*
* function setter( v ) {
* val = v;
* }
*
* ns.setConfigurableWriteOnlyAccessor( obj, 'foo', setter );
*
* obj.foo = 'beep';
*/
setConfigurableWriteOnlyAccessor: typeof setConfigurableWriteOnlyAccessor;
/**
* Defines a configurable memoized read-only object property.
*
* ## Notes
*
* - Configurable read-only properties are **enumerable**.
*
* @param obj - object on which to define property
* @param prop - property name
* @param fcn - function whose return value will be memoized and set as the property value
*
* @example
* var obj = {};
*
* function foo() {
* return 'bar';
* }
*
* ns.setMemoizedConfigurableReadOnly( obj, 'foo', foo );
*
* var v = obj.foo;
* // returns 'bar'
*/
setMemoizedConfigurableReadOnly: typeof setMemoizedConfigurableReadOnly;
/**
* Defines a memoized object property.
*
* @param obj - object on which to define property
* @param prop - property name
* @param desc - property descriptor
*
* @example
* var obj = {};
*
* function foo() {
* return 'bar';
* }
*
* ns.defineMemoizedProperty( obj, 'foo', {
* 'configurable': false,
* 'enumerable': false,
* 'writable': false,
* 'value': foo
* });
*
* var v = obj.foo;
* // returns 'bar'
*/
defineMemoizedProperty: typeof defineMemoizedProperty;
/**
* Defines a memoized read-only object property.
*
* ## Notes
*
* - Read-only properties are **enumerable** and **non-configurable**.
*
* @param obj - object on which to define property
* @param prop - property name
* @param fcn - function whose return value will be memoized and set as the property value
*
* @example
* var obj = {};
*
* function foo() {
* return 'bar';
* }
*
* ns.setMemoizedReadOnly( obj, 'foo', foo );
*
* var v = obj.foo;
* // returns 'bar'
*/
setMemoizedReadOnly: typeof setMemoizedReadOnly;
/**
* Defines a non-enumerable property.
*
* ## Notes
*
* - Non-enumerable properties are writable and configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param value - value to set
*
* @example
* var objectKeys = require( './../../keys' );
*
* var obj = {};
*
* ns.setNonEnumerableProperty( obj, 'foo', 'bar' );
*
* var v = obj.foo;
* // returns 'bar'
*
* var keys = objectKeys( obj );
* // returns []
*/
setNonEnumerableProperty: typeof setNonEnumerableProperty;
/**
* Defines a non-enumerable read-only accessor.
*
* ## Notes
*
* - Non-enumerable read-only accessors are non-configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param getter - accessor
*
* @example
* function getter() {
* return 'bar';
* }
*
* var obj = {};
*
* ns.setNonEnumerableReadOnlyAccessor( obj, 'foo', getter );
*
* try {
* obj.foo = 'boop';
* } catch ( err ) {
* console.error( err.message );
* }
*/
setNonEnumerableReadOnlyAccessor: typeof setNonEnumerableReadOnlyAccessor;
/**
* Defines a non-enumerable read-only property.
*
* ## Notes
*
* - Non-enumerable read-only properties are non-configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param value - value to set
*
* @example
* var obj = {};
*
* ns.setNonEnumerableReadOnly( obj, 'foo', 'bar' );
*
* try {
* obj.foo = 'boop';
* } catch ( err ) {
* console.error( err.message );
* }
*/
setNonEnumerableReadOnly: typeof setNonEnumerableReadOnly;
/**
* Defines a non-enumerable read-write accessor.
*
* ## Notes
*
* - Non-enumerable read-write accessors are non-configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param getter - get accessor
* @param setter - set accessor
*
* @example
* function getter() {
* return name + ' foo';
* }
*
* function setter( v ) {
* name = v;
* }
*
* var name = 'bar';
* var obj = {};
*
* ns.setNonEnumerableReadWriteAccessor( obj, 'foo', getter, setter );
*
* var v = obj.foo;
* // returns 'bar foo'
*
* obj.foo = 'beep';
*
* v = obj.foo;
* // returns 'beep foo'
*/
setNonEnumerableReadWriteAccessor: typeof setNonEnumerableReadWriteAccessor;
/**
* Defines a non-enumerable write-only accessor.
*
* ## Notes
*
* - Non-enumerable write-only accessors are non-configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param setter - accessor
*
* @example
* var obj = {};
* var val = '';
*
* function setter( v ) {
* val = v;
* }
*
* ns.setNonEnumerableWriteOnlyAccessor( obj, 'foo', setter );
*
* obj.foo = 'beep';
*/
setNonEnumerableWriteOnlyAccessor: typeof setNonEnumerableWriteOnlyAccessor;
/**
* Defines (and/or modifies) object properties.
*
* @param obj - object on which to define the properties
* @param props - object with property descriptors
* @returns object with added and/or modified properties
*
* @example
* var obj = {};
* ns.defineProperties( obj, {
* 'foo': {
* 'value': 'bar'
* },
* 'baz': {
* 'value': 13
* }
* });
*
* var val = obj.foo;
* // returns 'bar'
*
* val = obj.baz;
* // returns 13
*/
defineProperties: typeof defineProperties;
/**
* Defines (or modifies) an object property.
*
* ## Notes
*
* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param descriptor - property descriptor
* @returns object with added property
*
* @example
* var obj = {};
*
* ns.defineProperty( obj, 'foo', {
* 'value': 'bar'
* });
*
* var str = obj.foo;
* // returns 'bar'
*/
defineProperty: typeof defineProperty;
/**
* Defines a read-only accessor.
*
* ## Notes
*
* - Read-only accessors are enumerable and non-configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param getter - accessor
*
* @example
* function getter() {
* return 'bar';
* }
*
* var obj = {};
*
* ns.setReadOnlyAccessor( obj, 'foo', getter );
*
* try {
* obj.foo = 'boop';
* } catch ( err ) {
* console.error( err.message );
* }
*/
setReadOnlyAccessor: typeof setReadOnlyAccessor;
/**
* Defines a read-only property.
*
* ## Notes
*
* - Read-only properties are enumerable and non-configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param value - value to set
*
* @example
* var obj = {};
*
* ns.setReadOnly( obj, 'foo', 'bar' );
*
* try {
* obj.foo = 'boop';
* } catch ( err ) {
* console.error( err.message );
* }
*/
setReadOnly: typeof setReadOnly;
/**
* Defines a read-write accessor.
*
* ## Notes
*
* - Read-write accessors are enumerable and non-configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param getter - get accessor
* @param setter - set accessor
*
* @example
* function getter() {
* return name + ' foo';
* }
*
* function setter( v ) {
* name = v;
* }
*
* var name = 'bar';
* var obj = {};
*
* ns.setReadWriteAccessor( obj, 'foo', getter, setter );
*
* var v = obj.foo;
* // returns 'bar foo'
*
* obj.foo = 'beep';
*
* v = obj.foo;
* // returns 'beep foo'
*/
setReadWriteAccessor: typeof setReadWriteAccessor;
/**
* Defines a write-only accessor.
*
* ## Notes
*
* - Write-only accessors are enumerable and non-configurable.
*
* @param obj - object on which to define the property
* @param prop - property name
* @param setter - accessor
*
* @example
* var obj = {};
* var val = '';
*
* function setter( v ) {
* val = v;
* }
*
* ns.setWriteOnlyAccessor( obj, 'foo', setter );
*
* obj.foo = 'beep';
*/
setWriteOnlyAccessor: typeof setWriteOnlyAccessor;
/**
* Returns a path dirname.
*
* @param path - path
* @returns directory name
*
* @example
* var dir = ns.dirname( './foo/bar/index.js' );
* // returns './foo/bar'
*/
dirname: typeof dirname;
/**
* Invokes a function until a test condition is true.
*
* ## Notes
*
* - The condition is evaluated *after* executing the provided function; thus, `fcn` *always* executes at least once.
* - When invoked, both the predicate function and the function to invoke are provided a single argument:
*
* - `i`: iteration number (starting from zero)
*
* @param fcn - function to invoke
* @param predicate - function which indicates whether to stop invoking a function
* @param thisArg - execution context for the invoked function
*
* @example
* function predicate( i ) {
* return ( i <= 5 );
* }
*
* function beep( i ) {
* console.log( 'beep: %d', i );
* }
*
* ns.doUntil( beep, predicate );
*/
doUntil: typeof doUntil;
/**
* Until a test condition is true, invokes a function once for each element in a collection.
*
* ## Notes
*
* - The condition is evaluated **after** executing the function to invoke; thus, the provided function **always** executes at least once.
*
* - When invoked, both the predicate function and the function to apply are provided three arguments:
*
* - `value`: collection value
* - `index`: collection index
* - `collection`: the input collection
*
* - If provided an empty collection, the function invokes the provided function with the collection index set to `undefined`.
*
* @param collection - input collection
* @param fcn - function to invoke
* @param predicate - function which indicates whether to stop iterating over a collection
* @param thisArg - execution context for the applied function
* @returns input collection
*
* @example
* function predicate( v, index, collection ) {
* return ( v !== v );
* }
*
* function log( v, index, collection ) {
* console.log( '%s: %d', index, v );
* }
*
* var arr = [ 1, 2, 3, 4, NaN, 5 ];
*
* ns.doUntilEach( arr, log, predicate );
*/
doUntilEach: typeof doUntilEach;
/**
* Until a test condition is true, invokes a function once for each element in a collection, iterating from right to left.
*
* ## Notes
*
* - For dynamic array resizing, the only behavior made intentionally consistent with `doUntilEach` (iterating from left to right) is when elements are pushed onto the beginning (end) of an array. In other words, for `doUntilEach()`, `[].push()` behavior is consistent with `doUntilEachRight()` `[].unshift()` behavior.
*
* - The condition is evaluated **after** executing the function to invoke; thus, the provided function **always** executes at least once.
*
* - When invoked, both the predicate function and the function to apply are provided three arguments:
*
* - `value`: collection value
* - `index`: collection index
* - `collection`: the input collection
*
* - If provided an empty collection, the function invokes the provided function with the collection index set to `undefined`.
*
* @param collection - input collection
* @param fcn - function to invoke
* @param predicate - function which indicates whether to stop iterating over a collection
* @param thisArg - e