Socket
Socket
Sign inDemoInstall

js-select

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-select

Traverse and modify objects with JSONSelect selectors


Version published
Weekly downloads
7.7K
increased by25.91%
Maintainers
0
Weekly downloads
 
Created
Source

js-select

js-select uses js-traverse to traverse and modify JavaScript object nodes that match JSONSelect selectors:

var select = require("js-select");

var people = {
   george: {
      age : 35,
      movie: "Repo Man"
   },
   mary: {
      age: 15,
      movie: "Twilight"
   }
}

select(people, ".age").forEach(function(age) {
   this.update(age - 5);
})

select(people, ".age").nodes();  // [30, 10]

See js-traverse for all the things you can do to modify the node. The forEach() callback will get the same this context as the forEach() callback from js-traverse, plus a this.matches() which will test if the node matches a selector:

select(obj).forEach(function(node) {
   if (this.matches(".mary > .movie")) {
      this.update(node.toLowerCase());
   }
}

selectors

js-select supports the following JSONSelect selectors so far:

"*"
".key"
".ancestor .key"
".parent > .key"
":root"
":nth-child(n)"
":nth-child(even)"
":nth-child(odd)"
":first-child"

install

Download the code, then with npm:

npm install js-select

Get a browser file after npm-installing using browserify

Keywords

FAQs

Package last updated on 24 Jul 2011

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc