1.0.0 • Published 6 years ago

purrjs v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

Purr.js

Simple JavaScript utility library with respect to FP

Installation

Library can be installed via downloading a git repo:

git clone https://github.com/happyCoda/purrjs.git

or from npm:

npm i purrjs

Functions

_checkType(thing) ⇒ Boolean

Checks entity's type

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

_throwIfNotObjectOrArrayOrString(thing)

Throws if entity is not Object, Array or String. Wrapper method over _throwIfNotOneOfTypes

Kind: global function

ParamTypeDescription
thingAnyEntity to check type for

_throwIfNotObjectOrArray(thing)

Throws if entity is not Object or Array. Wrapper method over _throwIfNotOneOfTypes

Kind: global function

ParamTypeDescription
thingAnyEntity to check type for

_throwIfNotOneOfTypes(thing, types)

Throws if entity is not of one of types provided

Kind: global function

ParamTypeDescription
thingAnyEntity to check type for
typesArrayArray of types to check against

_throwWrongType(expected, given)

Throws exception with given explanations

Kind: global function

ParamTypeDescription
expectedStringExpected type(s)
givenStringType provided

_checkArity(args, arity) ⇒ Boolean

Checks if args given fits arity provided

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
argsArrayArguments array
arityNumberArity of a function

_expose(global, item, name)

Makes any object available in global scope

Kind: global function

ParamTypeDescription
globalObjectAny global object to include exposable
itemAnyEntity for expose
nameStringThe name of the exposed entity

_inspect(collection, deeper) ⇒ String

Inspects objects

Kind: global function
Returns: String - stringified Stringified collection representation

ParamTypeDescription
collectionObjectCan be array or object
deeperBooleanWether we need trailing coma

_setRecursionMaxDepth(value)

Sets maximum recursion depth (useful for walk method)

Kind: global function

ParamTypeDescription
valueNumberNew recursion depth

isObject(thing) ⇒ Boolean

Checks if entity is an Object

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

isArray(thing) ⇒ Boolean

Checks if entity is an Array

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

isFunction(thing) ⇒ Boolean

Checks if entity is an Function

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

isBoolean(thing) ⇒ Boolean

Checks if entity is an Boolean

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

isNumber(thing) ⇒ Boolean

Checks if entity is an Number

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

isString(thing) ⇒ Boolean

Checks if entity is an String

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

isNull(thing) ⇒ Boolean

Checks if entity is an Null

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

isUndefined(thing) ⇒ Boolean

Checks if entity is an Undefined

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

isSymbol(thing) ⇒ Boolean

Checks if entity is an Symbol

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for

is(thing, type) ⇒ Boolean

Checks if entity has a given type

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for
typeStringEntity's type to check against

isOneOfTypes(thing, types) ⇒ Boolean

Checks if entity has one of the given types

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check type for
typesArrayEntity's types to check against

isTruthy(thing) ⇒ Boolean

Checks if entity has a truthy value

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check

isEmpty(thing) ⇒ Boolean

Checks if entity has an empty value ('', [], {})

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
thingAnyEntity to check

curry(func, arity, context) ⇒ function | Any

Performs function currying

Kind: global function
Returns: function | Any - Returns curried function

ParamTypeDefaultDescription
funcfunctionFunction to curry
arityNumber2Number of arguments curried function expected
contextObjectContext to apply curried function on

compose(...args) ⇒ function

Composed functions

Kind: global function
Returns: function - Curried function

ParamTypeDescription
...args*Functions to compose

noop(thing) ⇒ Any

Function placeholder in case you need some callback. Simply returns given value

Kind: global function
Returns: Any - thing Some argument

ParamTypeDescription
thingAnySome argument

each(collection, func)

Iterates over collection and calls callback on every iteration

Kind: global function

ParamTypeDescription
collectionArrray | Object | StringCollection to iterate over
funcfunctionCallback function to to call

map(collection, func) ⇒ Arrray | Object | String

Iterates over collection and calls callback on every iteration

Kind: global function
Returns: Arrray | Object | String - collectionMapped New mapped collection

ParamTypeDescription
collectionArrray | Object | StringCollection to iterate over
funcfunctionCallback function to call

reduce(collection, func, acc) ⇒ Any

Reduces collection to single value

Kind: global function
Returns: Any - acc Reduced value

ParamTypeDescription
collectionArrray | Object | StringCollection to reduce
funcfunctionCallback function to call
accAnySome initial accumulator value

filter(collection, func, reverse) ⇒ Arrray | Object | String

Filter collection by criteria

Kind: global function
Returns: Arrray | Object | String - result Filtered collection

ParamTypeDefaultDescription
collectionArrray | Object | StringCollection to filter
funcfunction | Array | ObjectCallback function to call
reverseBooleanfalseDetermines whether filter should invert condition

reject(collection, func) ⇒ Arrray | Object | String

Reject collection's items by criteria

Kind: global function
Returns: Arrray | Object | String - Rejected collection

ParamTypeDescription
collectionArrray | Object | StringCollection to reject
funcfunction | Array | ObjectCallback function to call

all(collection, func) ⇒ Arrray | Object | String

Checks if all collection's items fit criteria

Kind: global function
Returns: Arrray | Object | String - Checked collection

ParamTypeDescription
collectionArrray | Object | StringCollection to check
funcfunctionCallback function to call

any(collection, func) ⇒ Arrray | Object | String

Checks if any collection's items fit criteria

Kind: global function
Returns: Arrray | Object | String - Checked collection

ParamTypeDescription
collectionArrray | Object | StringCollection to check
funcfunctionCallback function to call

times(num, func)

Calls the function a specified number of times

Kind: global function

ParamTypeDescription
numNumberNumber of times to call the function
funcfunctionCallback function to call

find(collection, func) ⇒ Arrray | Object | Undefined

Searches element in collection

Kind: global function
Returns: Arrray | Object | Undefined - Value found or undefined

ParamTypeDescription
collectionArrray | Object | StringCollection to check
funcfunction | Array | ObjectIteratee for checking

contains(collection, valOrKey) ⇒ Boolean

Checks if element is in collection

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
collectionArrray | Object | StringCollection to check
valOrKeyNumber | StringValue for checking

destroy(collection, key) ⇒ Boolean

Deletes property from collection

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
collectionArrray | Object | StringCollection to operate
keyStringProperty to delete

groupBy(collection, criteria) ⇒ Object

Group collection's elements by given criteria

Kind: global function
Returns: Object - result Groupped collection

ParamTypeDescription
collectionObjectCollection to operate
criteriaStringProperty to order collection by

orderBy(collection, criteria, direction) ⇒ Array

Order collection's elements by given criteria and direction

Kind: global function
Returns: Array - result Ordered collection

ParamTypeDescription
collectionArrayCollection to operate
criteriaStringProperty to order collection by
directionStringAscendant or Descendant

uniq(collection) ⇒ Object

Drops all collection's duplicates

Kind: global function
Returns: Object - result Unique collection

ParamTypeDescription
collectionArrayCollection to operate

toArray(arrayLike) ⇒ Array

Converts array like structures to array

Kind: global function
Returns: Array - result Converted value

ParamTypeDescription
arrayLikeObjectArray like to convert

debounce(fn, wait, asap) ⇒ function

Creates debounced version of the function given

Kind: global function
Returns: function - Debounced function

ParamTypeDefaultDescription
fnfunctionThe function to debounce
waitNumber200Timeout value
asapBooleanfalseWhether function shuld be called immediately

pluck(collection, key) ⇒ Array

Creates new collection from the old one by the given key

Kind: global function
Returns: Array - result New collection of plucked values

ParamTypeDescription
collectionArray | ObjectThe collection to pluck
keyStringThe key to pluck collection by

omit(collection, key) ⇒ Object

Drops values from collection

Kind: global function
Returns: Object - obj Mutated collection

ParamTypeDescription
collectionObjectThe collection to omit
keyStringThe property to delete

extend(collection, source) ⇒ Object

Extends collection

Kind: global function
Returns: Object - collection Extended collection

ParamTypeDescription
collectionObjectThe collection to extend
sourceObjectThe extension source

clone(collection) ⇒ Object

Clones collection

Kind: global function
Returns: Object - clone Clone of the collection

ParamTypeDescription
collectionObjectThe collection to clone

mixin(collection, ...sources) ⇒ Object

Ads mixin's props to the collection

Kind: global function
Returns: Object - collection Mutated collection

ParamTypeDescription
collectionObjectThe collection to mutate
...sources*The mixin sources

chunk(collection, size, start) ⇒ Object

Gets collection chunk

Kind: global function
Returns: Object - Collection chunk

ParamTypeDefaultDescription
collectionArray | StringThe collection to operate
sizeNumberChunk size
startNumber0Chunk start position

size(collection) ⇒ Number

Calculates collection size

Kind: global function
Returns: Number - Collection size

ParamTypeDescription
collectionArray | StringThe collection to operate

walk(collection, func, parent, depth)

Walks collection recursively

Kind: global function

ParamTypeDefaultDescription
collectionArray | ObjectThe collection to operate
funcfunctionCallback to call
parentArray | ObjectParent entity
depthNumber0Walk's depth

flatten(collection, flatArr)

Makes multidimensional arrays flat

Kind: global function

ParamTypeDescription
collectionArrayThe Array to flat
flatArrArrayNew flattened array

inject(obj, stuff) ⇒ Object

Injects logic from purr to given object

Kind: global function
Returns: Object - obj Mutated object

ParamTypeDescription
objObjectObject to inject logic
stuffArray | StringProperties to inject

namespace(parent, nsstring) ⇒ Object

Creates namespace on the given object or new object

Kind: global function
Returns: Object - parent Mutated object

ParamTypeDescription
parentObjectObject create namespace
nsstringStringString representation of namespace

ensureImplements(obj, methods) ⇒ Boolean

Ensures than object implements given interface

Kind: global function
Returns: Boolean - true or false

ParamTypeDescription
objObjectObject to operate
methodsArray | StringInterface to implement

randomNum(min, max) ⇒ Number

Generates random number

Kind: global function
Returns: Number - randNum Random number generated.

ParamTypeDescription
minNumberMinimum number boundary.
maxNumberMaximum number boundary.

Release History

  • 2017-12-08   v1.0.0   v1.0.0 release
  • 2013-08-07   v0.1.0   First release