@stdlib/utils

Standard utilities.

Usage no npm install needed!

<script type="module">
  import stdlibUtils from 'https://cdn.skypack.dev/@stdlib/utils';
</script>

README

Utils

NPM version Build Status Coverage Status dependencies

Standard library utilities.

Installation

npm install @stdlib/utils

Usage

var utils = require( '@stdlib/utils' );

utils

Standard library utilities.

var o = utils;
// returns {...}

The package contains the following sub-namespaces:

  • [async][@stdlib/utils/async]: standard library async utilities.

Data Structures

  • [CircularBuffer( buffer )][@stdlib/utils/circular-buffer]: circular buffer constructor.
  • [CompactAdjacencyMatrix( N )][@stdlib/utils/compact-adjacency-matrix]: compact adjacency matrix constructor.
  • [DoublyLinkedList()][@stdlib/utils/doubly-linked-list]: doubly linked list constructor.
  • [FIFO()][@stdlib/utils/fifo]: first-in-first-out (FIFO) queue.
  • [LinkedList()][@stdlib/utils/linked-list]: singly linked list.
  • [namedtypedtuple( fields[, options] )][@stdlib/utils/named-typed-tuple]: create a factory for generating named typed tuples.
  • [Stack()][@stdlib/utils/stack]: stack data structure.

Collections

  • [anyByRight( collection, predicate[, thisArg ] )][@stdlib/utils/any-by-right]: test whether at least one element in a collection passes a test implemented by a predicate function, iterating from right to left.
  • [anyBy( collection, predicate[, thisArg ] )][@stdlib/utils/any-by]: test whether at least one element in a collection passes a test implemented by a predicate function.
  • [any( collection )][@stdlib/utils/any]: test whether at least one element in a collection is truthy.
  • [append( collection1, collection2 )][@stdlib/utils/append]: add elements from one collection to the end of another collection.
  • [bifurcateBy( collection, [options,] predicate )][@stdlib/utils/bifurcate-by]: split values into two groups according to a predicate function.
  • [bifurcateIn( obj, [options,] predicate )][@stdlib/utils/bifurcate-in]: split an object's own and inherited property values into two groups according to a predicate function.
  • [bifurcateOwn( obj, [options,] predicate )][@stdlib/utils/bifurcate-own]: split an object's own property values into two groups according to a predicate function.
  • [bifurcate( collection, [options,] filter )][@stdlib/utils/bifurcate]: split values into two groups.
  • [countBy( collection, [options,] indicator )][@stdlib/utils/count-by]: group values according to an indicator function and return group counts.
  • [everyByRight( collection, predicate[, thisArg ] )][@stdlib/utils/every-by-right]: test whether all elements in a collection pass a test implemented by a predicate function, iterating from right to left.
  • [everyBy( collection, predicate[, thisArg ] )][@stdlib/utils/every-by]: test whether all elements in a collection pass a test implemented by a predicate function.
  • [every( collection )][@stdlib/utils/every]: test whether all elements in a collection are truthy.
  • [forEachRight( collection, fcn[, thisArg ] )][@stdlib/utils/for-each-right]: invoke a function for each element in a collection, iterating from the right to left.
  • [forEach( collection, fcn[, thisArg ] )][@stdlib/utils/for-each]: invoke a function for each element in a collection.
  • [groupBy( collection, [options,] indicator )][@stdlib/utils/group-by]: group values according to an indicator function.
  • [groupIn( obj, [options,] indicator )][@stdlib/utils/group-in]: group an object's own and inherited property values according to an indicator function.
  • [groupOwn( obj, [options,] indicator )][@stdlib/utils/group-own]: group an object's own property values according to an indicator function.
  • [group( collection, [options,] groups )][@stdlib/utils/group]: group values as arrays associated with distinct keys.
  • [inmapRight( collection, fcn[, thisArg ] )][@stdlib/utils/inmap-right]: invoke a function for each element in a collection and update the collection in-place, iterating from right to left.
  • [inmap( collection, fcn[, thisArg ] )][@stdlib/utils/inmap]: invoke a function for each element in a collection and update the collection in-place.
  • [keyByRight( collection, fcn[, thisArg ] )][@stdlib/utils/key-by-right]: convert a collection to an object whose keys are determined by a provided function and whose values are the collection values, iterating from right to left.
  • [keyBy( collection, fcn[, thisArg ] )][@stdlib/utils/key-by]: convert a collection to an object whose keys are determined by a provided function and whose values are the collection values.
  • [noneByRight( collection, predicate[, thisArg ] )][@stdlib/utils/none-by-right]: test whether all elements in a collection fail a test implemented by a predicate function, iterating from right to left.
  • [noneBy( collection, predicate[, thisArg ] )][@stdlib/utils/none-by]: test whether all elements in a collection fail a test implemented by a predicate function.
  • [none( collection )][@stdlib/utils/none]: test whether all elements in a collection are falsy.
  • [pop( collection )][@stdlib/utils/pop]: remove and return the last element of a collection.
  • [prepend( collection1, collection2 )][@stdlib/utils/prepend]: add elements from one collection to the beginning of another collection.
  • [push( collection, ...items )][@stdlib/utils/push]: add one or more elements to the end of a collection.
  • [reduceRight( collection, initial, reducer[, thisArg ] )][@stdlib/utils/reduce-right]: apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.
  • [reduce( collection, initial, reducer[, thisArg ] )][@stdlib/utils/reduce]: apply a function against an accumulator and each element in a collection and return the accumulated result.
  • [shift( collection )][@stdlib/utils/shift]: remove and return the first element of a collection.
  • [someByRight( collection, n, predicate[, thisArg ] )][@stdlib/utils/some-by-right]: test whether a collection contains at least n elements which pass a test implemented by a predicate function, iterating from right to left.
  • [someBy( collection, n, predicate[, thisArg ] )][@stdlib/utils/some-by]: test whether a collection contains at least n elements which pass a test implemented by a predicate function.
  • [some( collection, n )][@stdlib/utils/some]: test whether a collection contains at least n elements which are truthy.
  • [tabulateBy( collection[, options,] indicator )][@stdlib/utils/tabulate-by]: generate a frequency table according to an indicator function.
  • [tabulate( collection )][@stdlib/utils/tabulate]: generate a frequency table.
  • [unshift( collection, ...items )][@stdlib/utils/unshift]: add one or more elements to the beginning of a collection.
  • [untilEachRight( collection, predicate, fcn[, thisArg ] )][@stdlib/utils/until-each-right]: until a test condition is true, invoke a function for each element in a collection, iterating from right to left.
  • [untilEach( collection, predicate, fcn[, thisArg ] )][@stdlib/utils/until-each]: until a test condition is true, invoke a function for each element in a collection.
  • [whileEachRight( collection, predicate, fcn[, thisArg ] )][@stdlib/utils/while-each-right]: while a test condition is true, invoke a function for each element in a collection, iterating from right to left.
  • [whileEach( collection, predicate, fcn[, thisArg ] )][@stdlib/utils/while-each]: while a test condition is true, invoke a function for each element in a collection.

Arrays

  • [deepPluck( arr, path[, options] )][@stdlib/utils/deep-pluck]: extract a nested property value from each element of an object array.
  • [find( arr, [opts,] clbk )][@stdlib/utils/find]: find elements in an array-like object that satisfy a test condition.
  • [flattenArray( arr[, options] )][@stdlib/utils/flatten-array]: flatten an array.
  • [objectFromEntries( entries )][@stdlib/utils/from-entries]: create an object from key-value pairs.
  • [indexOf( arr, searchElement[, fromIndex] )][@stdlib/utils/index-of]: return the first index at which a given element can be found.
  • [pluck( arr, prop[, options] )][@stdlib/utils/pluck]: extract a property value from each element of an object array.
  • [unzip( arr[, idx] )][@stdlib/utils/unzip]: unzip a zipped array (i.e., a nested array of tuples).
  • [zip( arr1, arr2,...[, opts] )][@stdlib/utils/zip]: generate array tuples from input arrays.

Objects

Functions

Error Handling

  • trycatch( x, y ): if a function does not throw, return the function return value; otherwise, return y.
  • tryFunction( fcn ): wrap a function in a try/catch block.
  • tryRequire( id ): wrap require in a try/catch block.
  • trythen( x, y ): if a function does not throw, return the function return value; otherwise, return the return value of a second function.

General Utilities

Examples

var objectKeys = require( '@stdlib/utils/keys' );
var utils = require( '@stdlib/utils' );

console.log( objectKeys( utils ) );

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2021. The Stdlib Authors.