Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Flatten/Nest Javascript objects.
var fn = require("flatnest")
var obj = {
cat: "meow",
dog: [{name: "spot"}, {name: "rover"}],
bird: {type: "parrot", age: 22.3, stats: {weight: 10, height: 15}}
}
var flat = fn.flatten(obj)
/*
{ cat: 'meow',
'dog[0].name': 'spot',
'dog[1].name': 'rover',
'bird.type': 'parrot',
'bird.age': 22.3,
'bird.stats.weight': 10,
'bird.stats.height': 15 }
*/
var nested = fn.nest(flat)
/*
{ cat: 'meow',
dog: [ { name: 'spot' }, { name: 'rover' } ],
bird:
{ type: 'parrot',
age: 22.3,
stats: { weight: 10, height: 15 } } }
*/
// An internal `seek` function is also exposed:
fn.seek(obj, "bird.stats.height") // 15
flatten(object)
Flatten an object to a javascript object with only key: value pairs where values are not complex data types. (e.g. they can be numbers, strings, booleans, but not Objects or Arrays)
Keys are named with paths to where the keys where when nested.
nest(flatObject)
Re-form a flattend object into the nested version. It parses the key paths set during flattening and should end up with the original version. This is not always true depending on what data was present and the original key names chosen.
seek(object, path)
Use the flattened key syntax (e.g. aa.bb[0].cc
) to look into a nested object.
It attempts to do the right thing in a few cases, such as circular references, and will probably not do what you want if you're using .
or []
already in your key names (why would you do that!?!)
Circular example:
var fn = require("flatnest")
var obj = {
aa: "cat",
}
obj.bb = obj
console.log(obj)
// { aa: 'cat', bb: [Circular] }
// Will insert a string value of [Circular (ref)] pointing to the location this ref was first seen while flattening.
var flat = fn.flatten(obj)
console.log(flat)
// { aa: 'cat', bb: '[Circular (this)]' }
var nested = fn.nest(obj)
// { aa: 'cat', bb: { aa: 'cat', bb: [Circular] } }
console.log(nested)
MIT
FAQs
Flatten/Nest Javascript objects.
We found that flatnest demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.