
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Small JavaScript utility library for working with nested objects.
npm install insides --save
var buildObject = require("insides").buildObject;
var reduceKV = require("insides").reduceKV;
var getIn = require("insides").getIn;
var setIn = require("insides").setIn;
var object = buildObject([
[ [ "a", "b", "c" ], 1 ],
[ [ "a", "b", "d" ], 2 ],
[ [ "e" ], 3 ]
]);
console.log(JSON.stringify(object, null, 2));
// {
// "a": {
// "b": {
// "c": 1,
// "d": 2
// }
// },
// "e": 3
// }
var depth = 3;
var sum = reduceKV(object, depth, function(memo, key, value) {
return memo + value;
}, 0);
console.log("sum: " + sum);
// sum: 3
var abcValue = getIn(object, [ "a", "b", "c" ]);
console.log("abc value: " + abcValue);
// abc value: 1
var abgValue = getIn(object, [ "a", "b", "g" ], "not found");
console.log("abg value: " + abgValue);
// abg value: not found
var newObject = setIn(object, [ "a", "b", "g" ], 10);
var newAbgValue = getIn(newObject, [ "a", "b", "g" ], "not found");
console.log("new abg value: " + newAbgValue);
// new abg value: 10
Creates object from nestedArray:
var object = buildObject([ [ "a", 2 ] ]); // => { a: 2 }
var object = buildObject([ [ [ "a", "b" ], 2 ] ]); // => { a: { b: 2 } }
var object = buildObject([
[ [ "a", "b" ], 2 ],
[ [ "a", "c" ], 3 ]
]); // => { a: { b: 2, c: 3 } }
Argument is array of two-element arrays, first element is key map for the value, and second argument is the value;
Returns value from nested object.
Arguments
object
- object from which to return valuekeys
- keys array, could be a string or a array of keys: "a"
, [ "a", "b" ]
or "a.b"
notFound
- optional not found value, defaults to undefined
Differences from object.a.b.c
:
If object.a
does not exists this will thor a TypeError
, getIn(object, [ "a", "b", "c" ])
returns undefined
.
Sets value in object for provided keys array. Overwrites everything that was in this key and returns new object (initial one is left unchanged).
Arguments
object
- object to update valuekeys
- keys array, could be a string or a array of keys: "a"
, [ "a", "b" ]
or "a.b"
value/callback
- value or a callback to update the object:
value
- overwrites object at given keys to provided valuecallback
- calls callback(key, value)
and replaces object at given key path to return value of the callbackThe same as setIn
but updates the values instead of replacing them:
var object = { "a": { "b": 3, "c": 2 } };
var setObject = setIn(object, [ "a" ], { b: 5 });
// => { "a": { "b": 5 } }
var updateObject = setIn(object, [ "a" ], { b: 5 });
// => { "a": { "b": 5, "c": 2 } }
Iterates over object calling callback on each matching value.
Arguments
object
- object to iterate on[depth]
- optional depth argument, positive integer, defaults to 0callback
- callback to be run on every matching node: callback(key, value, object)
Same as eachKV
but returns new object instead of updating existing one, returns new object (initial one is left unchanged).
Reduces nested object using provided callback.
Arguments
object
- object to reduce[depth]
- optional depth argument, positive integer, defaults to 0callback
- callback to be run on every matching node: callback(memo, key, value, object)
[initialValue]
- optional initial value for first memo
in callback
FAQs
Small JavaScript utility library for working with nested objects.
We found that insides 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.