
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
A passionate love letter to Array.prototype.reduce()
ObjectArray.<PathValueObject>ObjectObject*Array.<*>*numberObjectKind: 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))
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 }
}
})
ObjectKind: 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,
}
)
ObjectKind: 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 }
}
}
)
*Kind: global function
Returns: * - The value corresponding to the path
Throws:
| 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 } } })
Array.<*>Kind: global function
Returns: Array.<*> - The picked elements in the order of the indexes argument
Throws:
| 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])
*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)
numberKind: 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])
FAQs
A collection of reduce utilities
The npm package reduss receives a total of 1 weekly downloads. As such, reduss popularity was classified as not popular.
We found that reduss demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.