New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pdz/objectpath

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pdz/objectpath

Simple object manipulation by path

  • 1.0.4
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

A small set of universal functions for working with objects, using dot-separated path strings.

Use:

const pdzOP = require('@pdz/objectpath');

Get examples:

const test = { a: { b: { c: 123 }, d: { e: 456 } } }

pdzOP.get(test, 'a.b.c');
// 123

pdzOP.get(test, ['a.b.c', 'a.b', 'x.y.z']);
// { 'a.b.c': 123, 'a.b': { c: 123 }, 'x.y.z': undefined }

Set examples:

const test = { a: { b: { c: 123 }, d: { e: 456 } } }

pdzOP.set(test, 'a.b.c', 789); 
// { a: { b: { c: 789 }, d: { e: 456 } } }

pdzOP.set(test, { 'a.b.c': 789, 'a.f': 987 }); 
// { a: { b: { c: 789 }, d: { e: 456 }, f: 987 } }

pdzOP.set(test, ['a.b.c', 'a.d.e', 'a.f'], { g: 1 });
// { a: { b: { c: { g: 1 } }, d: { e: { g: 1 } }, f: { g: 1 } } }

Assign examples:

const test = { a: { b: { c: 123 }, d: { e: 456 } } }

pdzOP.assign(test, 'a.b', { c2: 789 }); 
// { a: { b: { c: 123, c2: 789 }, d: { e: 456 } } }

pdzOP.assign(test, { 'a.b': { c2: 789 }, 'a.d': { e2: 987 } }); 
// { a: { b: { c: 123, c2: 789 }, d: { e: 456, e2: 987 } } }

pdzOP.assign(test, ['a.b', 'a.d'], { f: 654 }); 
// { a: { b: { c: 123, c2: 789, f: 654 }, d: { e: 456, e2: 987, f: 654 } } }

Delete examples:

const test = { a: { b: { c: 123 }, d: { e: 456 } } }

pdzOP.del(test, 'a.b.c');
// { a: { b: { }, d: { e: 456 } } }

pdzOP.del(test, ['a.b.c', 'a.d']);
// { a: { b: { } } }

Keywords

FAQs

Package last updated on 04 Nov 2021

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