npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reduss

v3.1.0

Published

A collection of reduce utilities

Downloads

2

Readme

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

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

| Param | Type | Default | Description | | ------------ | ------------------- | ------------------- | ------------------------------------------------------------- | | path | string | | The path on which to set a new value | | data | * | | The data to set | | [baseObject] | Object | Object | The 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)

| Param | Type | Default | Description | | -------------- | ------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | obj | object | | The object on which the leafs are selected | | [previousPath] | array | array | The 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

| Param | Type | Description | | ----------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | | mappers | Object.<string, function()> | Object with keys corresponding to paths and value corresponding to maping function taking the value at objectToMap path | | objectToMap | Object | The 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

| Param | Type | Description | | ----------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | mappers | Object.<string, function()> | Object with keys corresponding to paths (or simple keys) and value corresponding to maping function taking the value at objectToMap path | | objectToMap | Object | The 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

| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------------------------ | | path | string | A string representing the path to access (e.g. 'some.prop.nested') | | objToAccess | Object | The 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

| Param | Type | Description | | --------------- | --------------------------------- | ---------------------------------------------- | | indexes | Array.<number> | An array of indexes to pick (the order matter) | | arrayOfElements | Array.<*> | 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

| Param | Type | Default | Description | | --------- | --------------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | condition | function | | Take as first argment the current value and next all the reducer argument (acumulator, index, array) and return true if the reducer should be called | | reducer | function | | Take all the reducer argument (acumulator, value, index, array), return the new accumuulator | | array | Array | | An array to reduce | | [initAcc] | * | Array | The 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

| Param | Type | Description | | --------- | --------------------------------- | -------------------------------------- | | condition | function | Retun true if the number can be summed | | numbers | Array.<number> | The array of numbers to sum |

Example

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