Socket
Book a DemoInstallSign in
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
Package was removed
Sorry, it seems this package was removed from the registry

@pdz/objectpath

Simple object manipulation by path

1.0.4
unpublished
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
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

object

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.