1.1.6 • Published 6 years ago
@supergeneric/utils v1.1.6
supergeneric
supergeneric helper functions
Modules
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