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

@gulujs/object-path

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

@gulujs/object-path

Access nested object properties using a dot path

latest
Source
npmnpm
Version
0.6.0
Version published
Maintainers
1
Created
Source

@gulujs/object-path

Installation

npm install @gulujs/object-path

Usage

import { ObjectPath } from '@gulujs/object-path';

const obj = { foo: [{ bar: 'Hello' }] };

/**
 * default is `escapeDotStyle`
 * `quoteStyle` can access by `ObjectPath.quoteStyle.get(obj, 'foo[0].bar')`
 */
console.log(ObjectPath.get(obj, 'foo[0].bar')); // 'Hello'

ObjectPath.set(obj, 'baz', 'world');
console.log(obj); // { foo: [{ bar: 'Hello' }], baz: 'world' }

ObjectPath.del(obj, 'foo[0].bar');
console.log(obj); // { foo: [{}], baz: 'world' }

console.log(ObjectPath.has(obj, 'foo[0].bar')); // false
console.log(ObjectPath.has(obj, 'foo')); // true

let path = ObjectPath.escapeDotStyle.keyPath.parse('users[0].user\\.name');
console.log(path); // ['users', 0, 'user.name']

let key = ObjectPath.escapeDotStyle.keyPath.stringify(path);
console.log(key); // 'users[0].user\\.name'

path = ObjectPath.quoteStyle.keyPath.parse(`users[0].'user name'`);
console.log(path); // ['users', 0, 'user name']

key = ObjectPath.quoteStyle.keyPath.stringify(path);
console.log(key); // `users[0].'user name'`
  • Quote style is implemented base on TOML Keys

License

MIT

Keywords

object

FAQs

Package last updated on 12 Nov 2023

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