Socket
Socket
Sign inDemoInstall

doc-path

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doc-path

A document path library for Node.JS


Version published
Weekly downloads
388K
decreased by-4.09%
Maintainers
1
Weekly downloads
 
Created
Source

A Document Path Library for Node

Build Status David - Dependency Checker Icon Monthly Downloads NPM version bitHound Score

This module will take paths in documents which can include nested paths specified by '.'s and can evaluate the path to a value, or can set the value at that path depending on the function called.

Installation

$ npm install doc-path

Usage

var path = require('doc-path');

API

path.evaluatePath(document, key)
  • document - Object - A JSON document that will be iterated over.
  • key - String - A path to the existing key whose value will be returned.

If the key does not exist, null is returned.

path.evaluatePath Example:
var path = require('doc-path');

var document = {
    Make: 'Nissan',
    Model: 'Murano',
    Year: '2013',
    Specifications: {
        Mileage: '7106',
        Trim: 'S AWD'
    }
};

console.log(path.evaluatePath(document, 'Make'));
// => 'Nissan'

console.log(path.evaluatePath(document, 'Specifications.Mileage'));
// => '7106'
path.setPath(document, key, value)
  • document - Object - A JSON document that will be iterated over.
  • key - String - A path to the existing key whose value will be set.
  • value - * - The value that will be set at the given key.

If the key does not exist, then the object will be built up to have that path. If no document is provided, an error will be thrown.

path.setPath Example:
var path = require('doc-path');

var document = {
    Make: 'Nissan'
};

console.log(path.setPath(document, 'Color.Interior', 'Tan'));
// => { Make: 'Nissan', Color: { Interior: 'Tan' } }

console.log(path.setPath(document, 'StockNumber', '34567'));
// => { Make: 'Nissan', Color: { Interior: 'Tan' }, StockNumber: '34567' }

Tests

$ npm test

Note: This requires mocha, should, async, and underscore.

To see test coverage, please run:

$ npm run coverage

Current Coverage is:

Statements   : 100% ( 22/22 )
Branches     : 90% ( 9/10 )
Functions    : 100% ( 2/2 )
Lines        : 100% ( 19/19 )

Features

  • Supports nested paths
  • Same common path specification as other programs such as MongoDB

Keywords

FAQs

Package last updated on 08 Oct 2015

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