New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

access-by-path

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

access-by-path

Get and set values in object by path

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

access-by-path

NPM version Build Status Downloads License

Functions of getting and setting the values of the object fields by the string representation of the path to them.

Russian readme

Install

npm install access-by-path

Usage

getByPath

import { getByPath } from 'access-by-path';

let obj = { a: 1, b: { c: 2, d: 3}};
let result = getByPath(obj, 'b.d'); // 3

getByPath(obj, path[, defaultValue[, splitChar[, escapeChar]]])

  • obj {Object} - object
  • path {string} - path to field
  • defaultValue {*} [undefined] - return value if the field is not found in object
  • splitChar {string} ['.'] - path delimiter character
  • escapeChar {string} ['\\'] - character to escape delimiter

setByPath

import { setByPath } from 'access-by-path';

let obj = { a: 1, b: { c: 2, d: 3}};
setByPath(obj, 'b.d', 4); // { a: 1, b: { c: 2, d: 4}}

setByPath(obj, path, value[, splitChar[, escapeChar]])

  • obj {Object} - object
  • path {string} - path to field
  • value {*} - set value
  • splitChar {string} ['.'] - path delimiter character
  • escapeChar {string} ['\\'] - character to escape delimiter

Testing

To run tests, use:

npm test

FAQs

Package last updated on 06 Jun 2019

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