Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsondom

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsondom

A DOM-like interface for querying Javascript Objects

  • 0.0.1
  • npm
  • Socket score

Version published
Weekly downloads
27
decreased by-15.62%
Maintainers
1
Weekly downloads
 
Created
Source

JSON DOM

A DOM-like interface for querying complex Javascript objects. (Also a very light wrapper around js-traverse).

Installation

npm install json-dom

Usage

> var jsd = require('json-dom');
> var complex = {
  title: "this is a test",
  articles: [
    {
      title: "sub title",
      articles: "this is an article"
    },
    {
      hello: "it is me you're looking for"
    }
  ]
};

> jsd.getValuesByKeyName(complex, 'title');
["this is a test", "sub title"]

> jsd.getValuesByKeyName(complex, 'title', 1);
["this is a test"]

> jsd.getNodesMatching(complex, 'articles');
[
  [
    {
      title: 'sub title',
      articles: 'this is an article'
    },
    {
      hello: 'it is me you\'re looking for'
    }
  ],
  'this is an article'
]

> js.getNodesMatching(complex, 'articles', true);
[ { title: 'this is a test',
    articles: [ [Object], [Object] ] },
  { title: 'sub title',
    articles: 'this is an article' } ]

Methods

getNodesMatching(tree, needle, parent)

/**
 * Returns a node of the tree if any of the keys or values in the node match the
 * provided criteria
 * @param  {Object}   tree      Object graph
 * @param  {String}   needle    The value you're looking for
 * @param  {Boolean}  (parents) Should it return the parent of the matching element
 * @return {Array}              An array of parent nodes which have matching children
 */
};
getValuesByKey(tree, key, maxDepth)
/**
 * Gets all values from object graph that exist at the specified key name
 * @param  {Object}   tree      Object graph
 * @param  {String}   key       Name of key
 * @param  {Integer} (maxDepth) Max recursion depth, zero means no maxDepth. Default zero
 * @return {Array}              Array of values from matching keys
 */

License

Copyright 2013 Condé Nast. Licensed under the MIT License.

Keywords

FAQs

Package last updated on 30 Aug 2013

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