Socket
Socket
Sign inDemoInstall

js-select

Package Overview
Dependencies
2
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    js-select

Traverse and modify JavaScript objects with JSONSelect selectors


Version published
Weekly downloads
13K
increased by19.69%
Maintainers
0
Install size
132 kB
Created
Weekly downloads
 

Readme

Source

js-select

js-select is a little mashup of js-traverse and a subset of JSONSelect.

It lets you 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) {
     // make everyone look younger!
    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 context (this) as the forEach() callback in js-traverse, plus a this.matches() which will test if the node matches a selector:

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

selectors

js-select supports the following JSONSelect selectors so far:

"*"
".key"
".ancestor .key"
".parent > .key"

install

Download the code, then with npm:

npm install js-select

Get a browser file after npm-installing using browserify

Keywords

FAQs

Last updated on 23 Jul 2011

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc