
Product
Introducing the Alert Details Page: A Better Way to Explore Alerts
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.
Shake the tastiest fruits from your deep object tree
This module is used by the Electron team to help internationalize our documentation. We parse all of our API docs into a structured format that looks a bit like this:
{
name: 'BrowserWindow',
description: 'Create and control browser windows.',
process: {
main: true,
renderer: false
},
type: 'Class',
instanceName: 'win',
slug: 'browser-window',
websiteUrl: 'http://electron.atom.io/docs/api/browser-window',
repoUrl: 'https://github.com/electron/electron/blob/v1.4.0/docs/api/browser-window.md',
staticMethods: ['...'],
instanceMethods: ['...'],
instanceProperties: ['...'],
instanceEvents: ['...']
}
Some parts of this structured data (like method names and arguments) needs to stay in English, whereas other parts of it (like descriptions) need to extracted for translation into other languages.
That's where shake-tree comes in. It gives us a way to extract just
the content we need from this deep object.
With npm:
npm install shake-tree --save
With Yarn:
yarn add shake-tree
const shakeTree = require('shake-tree')
// Given some arbitrarily-shaped object tree:
const input = {
a: 'just a string',
b: {
description: 'this is b description'
},
c: {
title: 'this is c title',
description: 'this is c description',
descriptionExtended: 'this is the extended description'
}
}
// You can pull out just the values you want by key:
const output = shakeTree(input, 'description')
console.log(output)
// { b: { description: 'this is b description' },
// c: { description: 'this is c description' } }
// You can also specify multiple keys to match:
shakeTree(input, ['description', 'title'])
In some cases you might want the result as flat key-value object with
period-delimited strings as keys. In this case, set the flat option to true:
This is useful if you want to preserve array indexes in the shaken tree.
const input = {
a: [
{description: 'first a'},
{description: 'second a'}
]
}
const output = shakeTree(input, 'description', {flat: true})
console.log(output)
// {
// 'a.0.description': 'first a',
// 'a.1.description': 'second a'
// }
This module exports a single function.
tree - Object (required)targetKeys - String or Array of Strings (required)options - Object (optional)
flat - Boolean (defaults to false)npm install
npm test
_.set exported as a module.MIT
FAQs
Shake the tastiest fruits from your deep object tree
The npm package shake-tree receives a total of 2 weekly downloads. As such, shake-tree popularity was classified as not popular.
We found that shake-tree 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.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.