@supergeneric/utils

1.1.6 • Public • Published

supergeneric

supergeneric helper functions

npm version node version support Build Status via Travis CI Coverage Status NPM downloads

Modules

collections/firstobject

returns first value in array

collections/lastobject

returns last value in array

collections/ascendingfunction

ascending sort function. Example: myArray.sort(ascending)

collections/descendingfunction

Descending sort function. Example: myArray.sort(descending)

collections/sortByarray

sorts by a predefined key.

collections/onlyNumbersarray

returns only the numeric values of an array

collections/randomItemobject

returns a random entry from an array

time/getMillisecondsnumber

converts text durations (e.g. "2 minutes") to milliseconds

collections/first ⇒ object

returns first value in array

Returns: object - first value/object in an array

Param Type Description
values array an array of values/objects

collections/last ⇒ object

returns last value in array

Returns: object - last value/object in an array

Param Type Description
values array an array of values/objects

collections/ascending ⇒ function

ascending sort function. Example: myArray.sort(ascending)

Returns: function - ascending sort function

collections/descending ⇒ function

Descending sort function. Example: myArray.sort(descending)

Returns: function - descending sort function

collections/sortBy ⇒ array

sorts by a predefined key.

Returns: array - sorted by attribute @name

Param Type Description
key string attribute name for object sorting
descending boolean set to true for descending sort

Example

people.sort(sortBy('name'))

collections/onlyNumbers ⇒ array

returns only the numeric values of an array

Returns: array - only numeric values

Param Type Description
values array an array of values

collections/randomItem ⇒ object

returns a random entry from an array

Returns: object - random value/object from array of values/objects

Param Type Description
items array an array of values/objects

time/getMilliseconds ⇒ number

converts text durations (e.g. "2 minutes") to milliseconds

Returns: number - milliseconds

Param Type Description
duration string | number will leave numeric values alone but convert string values

Example

getMilliseconds('2 minutes') // 120000

Package Sidebar

Install

npm i @supergeneric/utils

Weekly Downloads

0

Version

1.1.6

License

MIT

Unpacked Size

16.3 kB

Total Files

7

Last publish

Collaborators

  • kwhitley