1.2.1 • Published 4 years ago
over-object v1.2.1
Over Object
Over Object is a package for adding helpful functions to objects
Installation
npm install over-object
Usage
import over from 'over-object';
const object = { Hello: 'World' }
over(object).forEach((value, key) => {console.log(key + ' ' + value)})
API
The function adds useful functions to the property of the object passed in the parameter.
forEach
import over from 'over-object'; const object = { Hello: 'World' } over(object).forEach((value, key) => {console.log(key + ' ' + value)}) // Hello World
map
import over from 'over-object'; const object = { Hello: 'World' } const mapped = over(object).map((value, key) => value + 'and Universe') console.log(mapped); // { Hello: 'World and Universe' }
filter
import over from 'over-object'; const object = { Hello: 'World', and: 'Universe' } const filtered = over(object).filter((_value, key) => key === 'and') console.log(filtered) // { and: 'Universe' }
find
import over from 'over-object'; const object = { Hello: 'World', and: 'Universe' } const finded = over(object).filter((value) => value === 'World') console.log(finded);// 'World'
You can chain function calls
import over from 'over-object'; const object = { Hello: 'World' } over(object).map((value, key) => value + 'and Universe').forEach((value, key) => {console.log(key + ' ' + value)}) // 'Hello World and Universe'
get
import over from 'over-object'; const complexObject = { first: { second: 'Hello', third: { fourth: [1,2,3,4,5] } } } over(complexObject).get('first.second'); // Hello over(complexObject).get('first.third.fourth[2]'); // 3
reduce
import over from 'over-object'; const object = { Hello: 'World', and: 'Universe' } const reduced = over(object).reduce((previous, value, key)=>`${previous}${key} ${value} `, ''); console.log(reduced);// 'Hello World and Universe'