npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@stdlib/utils

v0.3.3

Published

Standard utilities.

Downloads

79,501

Readme

Utils

NPM version Build Status Coverage Status

Utilities.

Installation

npm install @stdlib/utils

Usage

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

utils

Namespace containing utilities.

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

The namespace has the following sub-namespaces:

  • [async][@stdlib/utils/async]: 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( arr, initial, reducer[, thisArg ] )][@stdlib/utils/reduce-right]: apply a function against an accumulator and each element in an array while iterating from right to left and return the accumulated result.
  • [reduce( arr, initial, reducer[, thisArg ] )][@stdlib/utils/reduce]: apply a function against an accumulator and each element in an array and return the accumulated result.
  • [reduce2d( arr, initial, fcn[, thisArg] )][@stdlib/utils/reduce2d]: reduce the number of dimensions by one of a two-dimensional nested array by applying a function against an accumulator and each element along the innermost dimension and returning the accumulation results as a one-dimensional array.
  • [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

  • [capitalizeKeys( obj )][@stdlib/utils/capitalize-keys]: convert the first letter of each object key to uppercase.
  • [commonKeys( obj1, obj2[, obj3[,...,objN]] )][@stdlib/utils/common-keys]: return the common own property names of two or more objects.
  • [deepGet( obj, path[, options] )][@stdlib/utils/deep-get]: get a nested property value.
  • [deepSet( obj, path, value[, options] )][@stdlib/utils/deep-set]: set a nested property value.
  • [setConfigurableReadOnlyAccessor( obj, prop, getter )][@stdlib/utils/define-configurable-read-only-accessor]: define a configurable read-only accessor.
  • [setConfigurableReadOnly( obj, prop, value )][@stdlib/utils/define-configurable-read-only-property]: define a configurable read-only property.
  • [setConfigurableReadWriteAccessor( obj, prop, getter, setter )][@stdlib/utils/define-configurable-read-write-accessor]: define a configurable read-write accessor.
  • [setConfigurableWriteOnlyAccessor( obj, prop, setter )][@stdlib/utils/define-configurable-write-only-accessor]: define a configurable write-only accessor.
  • [setMemoizedConfigurableReadOnly( obj, prop, fcn )][@stdlib/utils/define-memoized-configurable-read-only-property]: define a configurable memoized read-only object property.
  • [defineMemoizedProperty( obj, prop, descriptor )][@stdlib/utils/define-memoized-property]: define a memoized object property.
  • [setMemoizedReadOnly( obj, prop, fcn )][@stdlib/utils/define-memoized-read-only-property]: define a memoized read-only object property.
  • [setNonEnumerableProperty( obj, prop, value )][@stdlib/utils/define-nonenumerable-property]: define a non-enumerable property.
  • [setNonEnumerableReadOnlyAccessor( obj, prop, getter )][@stdlib/utils/define-nonenumerable-read-only-accessor]: define a non-enumerable read-only accessor.
  • [setNonEnumerableReadOnly( obj, prop, value )][@stdlib/utils/define-nonenumerable-read-only-property]: define a non-enumerable read-only property.
  • [setNonEnumerableReadWriteAccessor( obj, prop, getter, setter )][@stdlib/utils/define-nonenumerable-read-write-accessor]: define a non-enumerable read-write accessor.
  • [setNonEnumerableWriteOnlyAccessor( obj, prop, setter )][@stdlib/utils/define-nonenumerable-write-only-accessor]: define a non-enumerable write-only accessor.
  • [defineProperties( obj, properties )][@stdlib/utils/define-properties]: define (and/or modify) object properties.
  • [defineProperty( obj, prop, descriptor )][@stdlib/utils/define-property]: define (or modify) an object property.
  • [setReadOnlyAccessor( obj, prop, getter )][@stdlib/utils/define-read-only-accessor]: define a read-only accessor.
  • [setReadOnly( obj, prop, value )][@stdlib/utils/define-read-only-property]: define a read-only property.
  • [setReadWriteAccessor( obj, prop, getter, setter )][@stdlib/utils/define-read-write-accessor]: define a read-write accessor.
  • [setWriteOnlyAccessor( obj, prop, setter )][@stdlib/utils/define-write-only-accessor]: define a write-only accessor.
  • [objectEntriesIn( obj )][@stdlib/utils/entries-in]: return an array of an object's own and inherited enumerable property key-value pairs.
  • [objectEntries( obj )][@stdlib/utils/entries]: return an array of an object's own enumerable property key-value pairs.
  • [enumerablePropertiesIn( obj )][@stdlib/utils/enumerable-properties-in]: return an array of an object's own and inherited enumerable property names and symbols.
  • [enumerableProperties( obj )][@stdlib/utils/enumerable-properties]: return an array of an object's own enumerable property names and symbols.
  • [enumerablePropertySymbolsIn( obj )][@stdlib/utils/enumerable-property-symbols-in]: return an array of an object's own and inherited enumerable symbol properties.
  • [enumerablePropertySymbols( obj )][@stdlib/utils/enumerable-property-symbols]: return an array of an object's own enumerable symbol properties.
  • [flattenObject( obj[, options] )][@stdlib/utils/flatten-object]: flatten an object.
  • [forIn( obj, fcn[, thisArg ] )][@stdlib/utils/for-in]: invoke a function for each own and inherited enumerable property of an object.
  • [forOwn( obj, fcn[, thisArg ] )][@stdlib/utils/for-own]: invoke a function for each own enumerable property of an object.
  • [getPrototypeOf( value )][@stdlib/utils/get-prototype-of]: return the prototype of a provided object.
  • [inheritedEnumerableProperties( obj[, level] )][@stdlib/utils/inherited-enumerable-properties]: return an array of an object's inherited enumerable property names and symbols.
  • [inheritedEnumerablePropertySymbols( obj[, level] )][@stdlib/utils/inherited-enumerable-property-symbols]: return an array of an object's inherited enumerable symbol properties.
  • [inheritedKeys( obj[, level] )][@stdlib/utils/inherited-keys]: return an array of an object's inherited enumerable property names.
  • [inheritedNonEnumerableProperties( obj[, level] )][@stdlib/utils/inherited-nonenumerable-properties]: return an array of an object's inherited non-enumerable property names and symbols.
  • [inheritedNonEnumerablePropertyNames( obj[, level] )][@stdlib/utils/inherited-nonenumerable-property-names]: return an array of an object's inherited non-enumerable property names.
  • [inheritedNonEnumerablePropertySymbols( obj[, level] )][@stdlib/utils/inherited-nonenumerable-property-symbols]: return an array of an object's inherited non-enumerable symbol properties.
  • [inheritedProperties( obj[, level] )][@stdlib/utils/inherited-properties]: return an array of an object's inherited property names and symbols.
  • [inheritedPropertyDescriptor( obj, property[, level] )][@stdlib/utils/inherited-property-descriptor]: return a property descriptor for an object's inherited property.
  • [inheritedPropertyDescriptors( obj[, level] )][@stdlib/utils/inherited-property-descriptors]: return an object's inherited property descriptors.
  • [inheritedPropertyNames( obj[, level] )][@stdlib/utils/inherited-property-names]: return an array of an object's inherited enumerable and non-enumerable property names.
  • [inheritedPropertySymbols( obj[, level] )][@stdlib/utils/inherited-property-symbols]: return an array of an object's inherited symbol properties.
  • [inheritedWritableProperties( obj[, level] )][@stdlib/utils/inherited-writable-properties]: return an array of an object's inherited writable property names and symbols.
  • [inheritedWritablePropertyNames( obj[, level] )][@stdlib/utils/inherited-writable-property-names]: return an array of an object's inherited writable property names.
  • [inheritedWritablePropertySymbols( obj[, level] )][@stdlib/utils/inherited-writable-property-symbols]: return an array of an object's inherited writable symbol properties.
  • [keysIn( obj )][@stdlib/utils/keys-in]: return an array of an object's own and inherited enumerable property names.
  • [lowercaseKeys( obj )][@stdlib/utils/lowercase-keys]: convert each object key to lowercase.
  • [mapKeys( obj, transform )][@stdlib/utils/map-keys]: map keys from one object to a new object having the same values.
  • [mapValues( obj, transform )][@stdlib/utils/map-values]: map values from one object to a new object having the same keys.
  • [merge( target, source1[, source2[,...,sourceN]] )][@stdlib/utils/merge]: merge and extend objects.
  • [moveProperty( source, prop, target )][@stdlib/utils/move-property]: move a property from one object to another object.
  • [nonEnumerablePropertiesIn( obj )][@stdlib/utils/nonenumerable-properties-in]: return an array of an object's own and inherited non-enumerable property names and symbols.
  • [nonEnumerableProperties( obj )][@stdlib/utils/nonenumerable-properties]: return an array of an object's own non-enumerable property names and symbols.
  • [nonEnumerablePropertyNamesIn( obj )][@stdlib/utils/nonenumerable-property-names-in]: return an array of an object's own and inherited non-enumerable property names.
  • [nonEnumerablePropertyNames( obj )][@stdlib/utils/nonenumerable-property-names]: return an array of an object's own non-enumerable property names.
  • [nonEnumerablePropertySymbolsIn( obj )][@stdlib/utils/nonenumerable-property-symbols-in]: return an array of an object's own and inherited non-enumerable symbol properties.
  • [nonEnumerablePropertySymbols( obj )][@stdlib/utils/nonenumerable-property-symbols]: return an array of an object's own non-enumerable symbol properties.
  • [nonIndexKeys( obj )][@stdlib/utils/nonindex-keys]: return an array of an object's own enumerable property names which are not integer indices.
  • [objectInverseBy( obj, [options,] transform )][@stdlib/utils/object-inverse-by]: invert an object, such that keys become values and values become keys, according to a transform function.
  • [objectInverse( obj[, options] )][@stdlib/utils/object-inverse]: invert an object, such that keys become values and values become keys.
  • [omitBy( obj, predicate )][@stdlib/utils/omit-by]: return a partial object copy excluding properties for which a predicate (function) returns a truthy value.
  • [omit( obj, keys )][@stdlib/utils/omit]: return a partial object copy excluding specified keys.
  • [pickArguments( fcn, indices[, thisArg] )][@stdlib/utils/pick-arguments]: create a function that invokes a provided function with specified arguments.
  • [pickBy( obj, predicate )][@stdlib/utils/pick-by]: return a partial object copy containing properties for which a predicate (function) returns a truthy value.
  • [pick( obj, keys )][@stdlib/utils/pick]: return a partial object copy containing only specified keys.
  • [propertiesIn( obj )][@stdlib/utils/properties-in]: return an array of an object's own and inherited property names and symbols.
  • [properties( obj )][@stdlib/utils/properties]: return an array of an object's own enumerable and non-enumerable property names and symbols.
  • [propertyDescriptorIn( obj, property )][@stdlib/utils/property-descriptor-in]: return a property descriptor for an object's own or inherited property.
  • [propertyDescriptor( obj, property )][@stdlib/utils/property-descriptor]: return a property descriptor for an object's own property.
  • [propertyDescriptorsIn( obj )][@stdlib/utils/property-descriptors-in]: return an object's own and inherited property descriptors.
  • [propertyDescriptors( obj )][@stdlib/utils/property-descriptors]: return an object's own property descriptors.
  • [propertyNamesIn( obj )][@stdlib/utils/property-names-in]: return an array of an object's own and inherited enumerable and non-enumerable property names.
  • [propertyNames( obj )][@stdlib/utils/property-names]: return an array of an object's own enumerable and non-enumerable property names.
  • [propertySymbolsIn( obj )][@stdlib/utils/property-symbols-in]: return an array of an object's own and inherited symbol properties.
  • [propertySymbols( obj )][@stdlib/utils/property-symbols]: return an array of an object's own symbol properties.
  • [uncapitalizeKeys( obj )][@stdlib/utils/uncapitalize-keys]: convert the first letter of each object key to lowercase.
  • [uppercaseKeys( obj )][@stdlib/utils/uppercase-keys]: convert each object key to uppercase.
  • [objectValuesIn( obj )][@stdlib/utils/values-in]: return an array of an object's own and inherited enumerable property values.
  • [objectValues( obj )][@stdlib/utils/values]: return an array of an object's own enumerable property values.
  • [writablePropertiesIn( obj )][@stdlib/utils/writable-properties-in]: return an array of an object's own and inherited writable property names and symbols.
  • [writableProperties( obj )][@stdlib/utils/writable-properties]: return an array of an object's own writable property names and symbols.
  • [writablePropertyNamesIn( obj )][@stdlib/utils/writable-property-names-in]: return an array of an object's own and inherited writable property names.
  • [writablePropertyNames( obj )][@stdlib/utils/writable-property-names]: return an array of an object's own writable property names.
  • [writablePropertySymbolsIn( obj )][@stdlib/utils/writable-property-symbols-in]: return an array of an object's own and inherited writable symbol properties.
  • [writablePropertySymbols( obj )][@stdlib/utils/writable-property-symbols]: return an array of an object's own writable symbol properties.

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-2024. The Stdlib Authors.