Simple JavaScript utility library with respect to FP
Library can be installed via downloading a git repo:
git clone https://github.com/happyCoda/purrjs.gitor from npm:
npm i purrjs- _checkType(thing) ⇒
Boolean Checks entity's type
- _throwIfNotObjectOrArrayOrString(thing)
Throws if entity is not Object, Array or String. Wrapper method over _throwIfNotOneOfTypes
- _throwIfNotObjectOrArray(thing)
Throws if entity is not Object or Array. Wrapper method over _throwIfNotOneOfTypes
- _throwIfNotOneOfTypes(thing, types)
Throws if entity is not of one of types provided
- _throwWrongType(expected, given)
Throws exception with given explanations
- _checkArity(args, arity) ⇒
Boolean Checks if args given fits arity provided
- _expose(global, item, name)
Makes any object available in global scope
- _inspect(collection, deeper) ⇒
String Inspects objects
- _setRecursionMaxDepth(value)
Sets maximum recursion depth (useful for walk method)
- isObject(thing) ⇒
Boolean Checks if entity is an Object
- isArray(thing) ⇒
Boolean Checks if entity is an Array
- isFunction(thing) ⇒
Boolean Checks if entity is an Function
- isBoolean(thing) ⇒
Boolean Checks if entity is an Boolean
- isNumber(thing) ⇒
Boolean Checks if entity is an Number
- isString(thing) ⇒
Boolean Checks if entity is an String
- isNull(thing) ⇒
Boolean Checks if entity is an Null
- isUndefined(thing) ⇒
Boolean Checks if entity is an Undefined
- isSymbol(thing) ⇒
Boolean Checks if entity is an Symbol
- is(thing, type) ⇒
Boolean Checks if entity has a given type
- isOneOfTypes(thing, types) ⇒
Boolean Checks if entity has one of the given types
- isTruthy(thing) ⇒
Boolean Checks if entity has a truthy value
- isEmpty(thing) ⇒
Boolean Checks if entity has an empty value ('', [], {})
- curry(func, arity, context) ⇒
function|Any Performs function currying
- compose(...args) ⇒
function Composed functions
- noop(thing) ⇒
Any Function placeholder in case you need some callback. Simply returns given value
- each(collection, func)
Iterates over collection and calls callback on every iteration
- map(collection, func) ⇒
Arrray|Object|String Iterates over collection and calls callback on every iteration
- reduce(collection, func, acc) ⇒
Any Reduces collection to single value
- filter(collection, func, reverse) ⇒
Arrray|Object|String Filter collection by criteria
- reject(collection, func) ⇒
Arrray|Object|String Reject collection's items by criteria
- all(collection, func) ⇒
Arrray|Object|String Checks if all collection's items fit criteria
- any(collection, func) ⇒
Arrray|Object|String Checks if any collection's items fit criteria
- times(num, func)
Calls the function a specified number of times
- find(collection, func) ⇒
Arrray|Object|Undefined Searches element in collection
- contains(collection, valOrKey) ⇒
Boolean Checks if element is in collection
- destroy(collection, key) ⇒
Boolean Deletes property from collection
- groupBy(collection, criteria) ⇒
Object Group collection's elements by given criteria
- orderBy(collection, criteria, direction) ⇒
Array Order collection's elements by given criteria and direction
- uniq(collection) ⇒
Object Drops all collection's duplicates
- toArray(arrayLike) ⇒
Array Converts array like structures to array
- debounce(fn, wait, asap) ⇒
function Creates debounced version of the function given
- pluck(collection, key) ⇒
Array Creates new collection from the old one by the given key
- omit(collection, key) ⇒
Object Drops values from collection
- extend(collection, source) ⇒
Object Extends collection
- clone(collection) ⇒
Object Clones collection
- mixin(collection, ...sources) ⇒
Object Ads mixin's props to the collection
- chunk(collection, size, start) ⇒
Object Gets collection chunk
- size(collection) ⇒
Number Calculates collection size
- walk(collection, func, parent, depth)
Walks collection recursively
- flatten(collection, flatArr)
Makes multidimensional arrays flat
- inject(obj, stuff) ⇒
Object Injects logic from purr to given object
- namespace(parent, nsstring) ⇒
Object Creates namespace on the given object or new object
- ensureImplements(obj, methods) ⇒
Boolean Ensures than object implements given interface
- randomNum(min, max) ⇒
Number Generates random number
Checks entity's type
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Throws if entity is not Object, Array or String. Wrapper method over _throwIfNotOneOfTypes
Kind: global function
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Throws if entity is not Object or Array. Wrapper method over _throwIfNotOneOfTypes
Kind: global function
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Throws if entity is not of one of types provided
Kind: global function
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
| types | Array |
Array of types to check against |
Throws exception with given explanations
Kind: global function
| Param | Type | Description |
|---|---|---|
| expected | String |
Expected type(s) |
| given | String |
Type provided |
Checks if args given fits arity provided
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| args | Array |
Arguments array |
| arity | Number |
Arity of a function |
Makes any object available in global scope
Kind: global function
| Param | Type | Description |
|---|---|---|
| global | Object |
Any global object to include exposable |
| item | Any |
Entity for expose |
| name | String |
The name of the exposed entity |
Inspects objects
Kind: global function
Returns: String - stringified Stringified collection representation
| Param | Type | Description |
|---|---|---|
| collection | Object |
Can be array or object |
| deeper | Boolean |
Wether we need trailing coma |
Sets maximum recursion depth (useful for walk method)
Kind: global function
| Param | Type | Description |
|---|---|---|
| value | Number |
New recursion depth |
Checks if entity is an Object
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity is an Array
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity is an Function
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity is an Boolean
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity is an Number
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity is an String
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity is an Null
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity is an Undefined
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity is an Symbol
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
Checks if entity has a given type
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
| type | String |
Entity's type to check against |
Checks if entity has one of the given types
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check type for |
| types | Array |
Entity's types to check against |
Checks if entity has a truthy value
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check |
Checks if entity has an empty value ('', [], {})
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| thing | Any |
Entity to check |
Performs function currying
Kind: global function
Returns: function | Any - Returns curried function
| Param | Type | Default | Description |
|---|---|---|---|
| func | function |
Function to curry | |
| arity | Number |
2 |
Number of arguments curried function expected |
| context | Object |
|
Context to apply curried function on |
Composed functions
Kind: global function
Returns: function - Curried function
| Param | Type | Description |
|---|---|---|
| ...args | * |
Functions to compose |
Function placeholder in case you need some callback. Simply returns given value
Kind: global function
Returns: Any - thing Some argument
| Param | Type | Description |
|---|---|---|
| thing | Any |
Some argument |
Iterates over collection and calls callback on every iteration
Kind: global function
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to iterate over |
| func | function |
Callback function to to call |
Iterates over collection and calls callback on every iteration
Kind: global function
Returns: Arrray | Object | String - collectionMapped New mapped collection
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to iterate over |
| func | function |
Callback function to call |
Reduces collection to single value
Kind: global function
Returns: Any - acc Reduced value
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to reduce |
| func | function |
Callback function to call |
| acc | Any |
Some initial accumulator value |
Filter collection by criteria
Kind: global function
Returns: Arrray | Object | String - result Filtered collection
| Param | Type | Default | Description |
|---|---|---|---|
| collection | Arrray | Object | String |
Collection to filter | |
| func | function | Array | Object |
Callback function to call | |
| reverse | Boolean |
false |
Determines whether filter should invert condition |
Reject collection's items by criteria
Kind: global function
Returns: Arrray | Object | String - Rejected collection
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to reject |
| func | function | Array | Object |
Callback function to call |
Checks if all collection's items fit criteria
Kind: global function
Returns: Arrray | Object | String - Checked collection
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to check |
| func | function |
Callback function to call |
Checks if any collection's items fit criteria
Kind: global function
Returns: Arrray | Object | String - Checked collection
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to check |
| func | function |
Callback function to call |
Calls the function a specified number of times
Kind: global function
| Param | Type | Description |
|---|---|---|
| num | Number |
Number of times to call the function |
| func | function |
Callback function to call |
Searches element in collection
Kind: global function
Returns: Arrray | Object | Undefined - Value found or undefined
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to check |
| func | function | Array | Object |
Iteratee for checking |
Checks if element is in collection
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to check |
| valOrKey | Number | String |
Value for checking |
Deletes property from collection
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| collection | Arrray | Object | String |
Collection to operate |
| key | String |
Property to delete |
Group collection's elements by given criteria
Kind: global function
Returns: Object - result Groupped collection
| Param | Type | Description |
|---|---|---|
| collection | Object |
Collection to operate |
| criteria | String |
Property to order collection by |
Order collection's elements by given criteria and direction
Kind: global function
Returns: Array - result Ordered collection
| Param | Type | Description |
|---|---|---|
| collection | Array |
Collection to operate |
| criteria | String |
Property to order collection by |
| direction | String |
Ascendant or Descendant |
Drops all collection's duplicates
Kind: global function
Returns: Object - result Unique collection
| Param | Type | Description |
|---|---|---|
| collection | Array |
Collection to operate |
Converts array like structures to array
Kind: global function
Returns: Array - result Converted value
| Param | Type | Description |
|---|---|---|
| arrayLike | Object |
Array like to convert |
Creates debounced version of the function given
Kind: global function
Returns: function - Debounced function
| Param | Type | Default | Description |
|---|---|---|---|
| fn | function |
The function to debounce | |
| wait | Number |
200 |
Timeout value |
| asap | Boolean |
false |
Whether function shuld be called immediately |
Creates new collection from the old one by the given key
Kind: global function
Returns: Array - result New collection of plucked values
| Param | Type | Description |
|---|---|---|
| collection | Array | Object |
The collection to pluck |
| key | String |
The key to pluck collection by |
Drops values from collection
Kind: global function
Returns: Object - obj Mutated collection
| Param | Type | Description |
|---|---|---|
| collection | Object |
The collection to omit |
| key | String |
The property to delete |
Extends collection
Kind: global function
Returns: Object - collection Extended collection
| Param | Type | Description |
|---|---|---|
| collection | Object |
The collection to extend |
| source | Object |
The extension source |
Clones collection
Kind: global function
Returns: Object - clone Clone of the collection
| Param | Type | Description |
|---|---|---|
| collection | Object |
The collection to clone |
Ads mixin's props to the collection
Kind: global function
Returns: Object - collection Mutated collection
| Param | Type | Description |
|---|---|---|
| collection | Object |
The collection to mutate |
| ...sources | * |
The mixin sources |
Gets collection chunk
Kind: global function
Returns: Object - Collection chunk
| Param | Type | Default | Description |
|---|---|---|---|
| collection | Array | String |
The collection to operate | |
| size | Number |
Chunk size | |
| start | Number |
0 |
Chunk start position |
Calculates collection size
Kind: global function
Returns: Number - Collection size
| Param | Type | Description |
|---|---|---|
| collection | Array | String |
The collection to operate |
Walks collection recursively
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| collection | Array | Object |
The collection to operate | |
| func | function |
Callback to call | |
| parent | Array | Object |
|
Parent entity |
| depth | Number |
0 |
Walk's depth |
Makes multidimensional arrays flat
Kind: global function
| Param | Type | Description |
|---|---|---|
| collection | Array |
The Array to flat |
| flatArr | Array |
New flattened array |
Injects logic from purr to given object
Kind: global function
Returns: Object - obj Mutated object
| Param | Type | Description |
|---|---|---|
| obj | Object |
Object to inject logic |
| stuff | Array | String |
Properties to inject |
Creates namespace on the given object or new object
Kind: global function
Returns: Object - parent Mutated object
| Param | Type | Description |
|---|---|---|
| parent | Object |
Object create namespace |
| nsstring | String |
String representation of namespace |
Ensures than object implements given interface
Kind: global function
Returns: Boolean - true or false
| Param | Type | Description |
|---|---|---|
| obj | Object |
Object to operate |
| methods | Array | String |
Interface to implement |
Generates random number
Kind: global function
Returns: Number - randNum Random number generated.
| Param | Type | Description |
|---|---|---|
| min | Number |
Minimum number boundary. |
| max | Number |
Maximum number boundary. |
- 2017-12-08 v1.0.0 v1.0.0 release
- 2013-08-07 v0.1.0 First release