New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

reduss

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reduss

A collection of reduce utilities

latest
Source
npmnpm
Version
3.1.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Reduss

Build Status codecov Greenkeeper badge Commitizen friendly JavaScript Style Guide david-dm

A passionate love letter to Array.prototype.reduce()

Functions

atPathSet(path, data, [baseObject])Object
leafs(obj, [previousPath])Array.<PathValueObject>
mapKeys(mappers, objectToMap)Object
mapKeysDeep(mappers, objectToMap)Object
path(path, objToAccess)*
pickIndexes(indexes, arrayOfElements)Array.<*>
reduceIf(condition, reducer, array, [initAcc])*
sumOnly(condition, numbers)number

atPathSet(path, data, [baseObject]) ⇒ Object

Kind: global function
Returns: Object - A new object with the path provided equal to data, and optionnaly any values present in baseObject

ParamTypeDefaultDescription
pathstringThe path on which to set a new value
data*The data to set
[baseObject]ObjectObjectThe base object, serve as the initial accumulator, default {}

Example

//returns { some: { prop: { one: 1, two: 2 } } }
atPathSet('some.prop.one', 1, atPathSet('some.prop.two', 2))

leafs(obj, [previousPath]) ⇒ Array.<PathValueObject>

Kind: global function
Returns: Array.<PathValueObject> - An array with object containing the leafs information (path/value)

ParamTypeDefaultDescription
objobjectThe object on which the leafs are selected
[previousPath]arrayarrayThe accumulated path while iterating on obj properties, default to empty array, needed only for recursion, should not be a passed argument when calling the function

Example

// returns [
//   { path: ['a', 'b', 'c'], value: 4 },
//   { path: ['a', 'b', 'e'], value: 6 },
//   { path: ['a', 'd', 'l'], value: 2 }
// ]
leafs({
    a: {
      b: { c: 4, e: 6 },
      d: { l: 2 }
    }
  })

mapKeys(mappers, objectToMap) ⇒ Object

Kind: global function
Returns: Object - A new object with the mapped keys

ParamTypeDescription
mappersObject.<string, function()>Object with keys corresponding to paths and value corresponding to maping function taking the value at objectToMap path
objectToMapObjectThe source object for the mapping

Example

// returns { str: 'SOMEVALUE', num: 4 }
mapKeys(
   { str: x => x.toUpperCase(), num: n => n + 3 },
   { str: 'someValue',
     num: 1,
   }
)

mapKeysDeep(mappers, objectToMap) ⇒ Object

Kind: global function
Returns: Object - A new object with the mapped paths

ParamTypeDescription
mappersObject.<string, function()>Object with keys corresponding to paths (or simple keys) and value corresponding to maping function taking the value at objectToMap path
objectToMapObjectThe source object for the mapping

Example

// returns {
// obj: {
//     prop: {
//        last: 8
//      }
//    }
// }
mapKeysDeep(
   {
     'obj.prop.last': x => x * 2
   },
   {
     obj: {
       prop: { last: 4 }
     }
   }
 )

path(path, objToAccess) ⇒ *

Kind: global function
Returns: * - The value corresponding to the path
Throws:

  • If we try to access a non existing property on objToAccess
ParamTypeDescription
pathstringA string representing the path to access (e.g. 'some.prop.nested')
objToAccessObjectThe accessed object

Example

// returns 6
path('a.b.c', { a: { b: { c: 6 } } })

pickIndexes(indexes, arrayOfElements) ⇒ Array.<*>

Kind: global function
Returns: Array.<*> - The picked elements in the order of the indexes argument
Throws:

  • Can throw an error if oyu try to pick an index which does not exist on arrayOfElements
ParamTypeDescription
indexesArray.<number>An array of indexes to pick (the order matter)
arrayOfElementsArray.<*>The array to pick values from

Example

// returns [6, 6, 2]
pickIndexes([2, 4, 1], [1, 2, 6, 1, 6])

reduceIf(condition, reducer, array, [initAcc]) ⇒ *

Kind: global function
Returns: * - The reduced value

ParamTypeDefaultDescription
conditionfunctionTake as first argment the current value and next all the reducer argument (acumulator, index, array) and return true if the reducer should be called
reducerfunctionTake all the reducer argument (acumulator, value, index, array), return the new accumuulator
arrayArrayAn array to reduce
[initAcc]*ArrayThe initial accumulator, default empty array

Example

// returns 6
reduceIf(x => x <= 3, (acc, v) => acc + v, [1,2,3,4], 0)

sumOnly(condition, numbers) ⇒ number

Kind: global function
Returns: number - The sum of matching numbers

ParamTypeDescription
conditionfunctionRetun true if the number can be summed
numbersArray.<number>The array of numbers to sum

Example

// returns 6
sumOnly(x => x <= 3, [1,2,3,4])

Keywords

reduss

FAQs

Package last updated on 15 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts