FuncKit is a granular ES6 library for individual functional methods. This allows you to include the methods nessesary for your project with out including a wide unnecessary rage of library attachments.
$ npm install funckit -save
import assignDeep from 'funckit\object\assignDeep';
import chunk from 'funckit\array\chunk';
Splits array into chunks using the specified size.
Usage:
chunk([1,2,3,4,5,6,7,8,9, 10], 3)
Output:
=> [[1,2,3],[4,5,6],[7,8,9],[10]]
Removes and null, false and undefined values from the passed array
Usage:
compact(1,false, undefined,null,2)
Output:
=> [1,2]
Takes in multiple array types and merges into a new array accordingly
Usage:
compress([1,2,3,4],[5,6,7],[8,9,10])
Output:
=> [[1,2,3,4],[5,6,7],[8,9,10]]
Retuns the difference between two arrays
Usage:
diff([1,2,3,4],[1,2,3,4,5,6,7])
Output:
=> [5,6,7]
Returns the first value of passed array
Usage:
first([1,2,3,4])
Output:
=> 1
Flattens nested arrays
Usage:
flatten([1,[2],[[3]]])
Output:
=> [1,2,3]
Takes in multiple array types and returns all values contained in every array
Usage:
intersection([1,2,3,4],[2,3,4],[1,2,2,3,3])
Output:
=> [2,3]
Retuns the last value of the passed in array
Usage:
last([1,2,3,4,5])
Output"
=> 5
Merges all values from all passed in array arugments in to the onw array
Usage:
merge([1,2,3,4],[5,6,7,8],[9,10])
Output:
=> [1,2,3,4,5,6,7,8,9,10]
Returns the amount of occurrences of a value in the passed array
Usage"
occurrences([1,2,1,2,1,2,1],2)
Output:
=> 3
Returns the array value by index if it exists in the given array
Usage"
pick(['John', 'Is', 'King'], 2)
Output:
=> 'King'
Returns the values of an array between the start and end arguments
Usage:
range([1,2,3,4,5,6,7,8,9], 4, 9)
Output:
=> [5,6,7,8,9]
Returns all the values from the passed array in a randomised order
Usage:
shuffle([1,2,3,4,5,6])
Output:
=> [2,5,4,1,3,6]
Removes all dublicate entries from the passed array
Usage:
unique([1,1,1,2,2,3])
Output:
=> [1,2,3]
Removes all specified values from the passed array
Usage:
without(['John', 'Cambo', 'Dan', 'Tom']], 'Tom', 'Dan');
Output:
=> ['John', 'Cambo']
Joins entries from one collection to multiple others using a primary and foreign key to identify the relationship
Usage:
const people = [
{
id: 2,
name: 'steff',
age: 27,
}
]
const addresses = [
{
id: 1,
person_id: 2,
postcode: 'l12pa'
}
];
const info = [
{
id: 1,
person_id: 2,
bio: 'Steff loves his ginger locks.'
}
];
hasMany(people, 'id', 'person_id', addresses, info)
Output:
=> [{
id: 2,
name: 'steff',
age: 27,
address: {
id: 1,
person_id: 2,
postcode: 'l12pa'
},
info: {
id: 1,
person_id: 2,
bio: 'Steff loves his ginger locks.'
}
}]
Joins entries from one collection to another using a primary and foreign key to identify the relationship
Usage:
const people = [
{
id: 2,
name: 'steff',
age: 27,
}
]
const addresses = [
{
id: 1,
person_id: 2,
postcode: 'l12pa'
}
];
hasOne(people, addresses, 'id', 'person_id', 'address')
Output:
=> [{
id: 2,
name: 'steff',
age: 27,
address: {
id: 1,
person_id: 2,
postcode: 'l12pa'
}
}]
Plucks and returns all instances of the specified property in a collection of objects.
Usage:
let people = [
{
name: 'John Hopley',
height: '6ft 6"',
age 32,
}
{
name: 'Cambo',
height: '5ft 1"',
age 54
}
];
pluck(people, 'name');
Output:
=> ['John Hopley', 'Cambo']
Takes in a collection returns only the items that watch the conditions (object:param2)
Usage:
let people = [
{
name: 'John Hopley',
jobcode: 12,
office: 'Liverpool'
},
{
name: 'Lee Easeman',
jobcode: 12,
office: 'London'
},
{
name: 'Eric Jones',
jobcode: 14,
office: 'Liverpool'
}
];
where(people, {jobcode: 14, office: 'Liverpool'})
Output:
=> [{
name: 'Eric Jones',
jobcode: 14,
office: 'Liverpool'
}]
Returns a random number between the min and max given in arguments
Usage:
between(5,10)
Output:
=> 6
Returns true is the passed argument is type of number
Usage:
isNumber(5)
isNumber('5')
Output:
=> true
=> false
Extends recursively over multidimensional objects using Object.assign.
Usage:
deepAssign({
name: 'John',
age: 25,
info: {
email: null,
}
}, {
info: {
email: '[email protected]',
address: {
postcode: 'xxxx'
}
}
})
Output:
=> {
name: 'John',
age: 25,
info: {
email: '[email protected]',
address: {
postcode: 'xxxx'
}
}
Returns clone of immutable object
Usage:
clone({name: 'John Hopley'})
Output:
=> {name: 'John Hopley'}
Checks if the passed in argument is type of Object
Usage:
isObject({});
Output:
=> true
Recursively flatten multidimensional objects
Usage:
objectFlatten({
name: 'John Hopley',
address: {
postcode: 'xxxx',
city: 'Liverpool'
}
});
Output:
=> {
'/name': 'John Hopley',
'/address/postcode': 'xxxx',
'/address/city': 'Liverpool',
}
Returns an object describing the property types of passed object
Usage:
types({
doSomething: () => {},
doNothing: false,
count: 5,
trigger: 'click',
meta: {}
})
Output:
=> {
doSomething: 'function'
doNothing: 'boolean',
count: 'number',
trigger: 'string',
meta: 'object'
}