Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

pxth

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pxth

Tiny utility library for object property path handling

latest
Source
npmnpm
Version
0.9.2
Version published
Weekly downloads
165
36.36%
Maintainers
2
Weekly downloads
 
Created
Source

pxth

Tiny utility library for object property path handling

npm version npm downloads vulnerabilities

Install

npm install pxth

Or

yarn add pxth

Api reference

Here are all functions described.

Pxth<T>

Holds path to field of type T in the origin object.

const a: Pxth<string>; // path to string field.

const b: Pxth<number>; // path to number field.

If T is object, it is possible to get paths to its fields:

const objectPath: Pxth<{ inner: string }>; // path to parent object.

const innerPath: Pxth<string> = objectPath.inner; // path to object's field.

const lengthPath: Pxth<number> = innerPath.length; // you can do it also for primitive type fields.

const deepLengthPath: Pxth<number> = objectPath.inner.length; // any amount of levels, just like normal object.

deepGet

Deeply get value from object.

Usage:

import { deepGet } from 'pxth';

const somePath: Pxth<string> = /* from somewhere */;

// Function is type safe - type of value will be automatically inferred from Pxth. In this case - string.
const value = deepGet({ a: { b: { c: 'Hello world!' } } }, somePath);

console.log(value); // -> 'Hello world'

deepSet

Deeply set value in object. Mutates the object and returns it. If value already exists, overwrites it.

Usage:

import { deepSet } from 'pxth';

const somePath: Pxth<string> = /* from somewhere */;

// Type safe - type of third parameter is inferred from Pxth.
deepSet({ a: { hello: 'asdf' } }, somePath, 'New value'); // -> { a: { hello: 'New value' } }

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT © Artiom Tretjakovas

Created with aqu 🌊

Keywords

deep

FAQs

Package last updated on 15 Nov 2024

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