Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

nested-object-access

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Issues
File Explorer

Advanced tools

nested-object-access

TypeScript-powered util to work with nested objects using dot-separated keys

    0.2.5latest

Version published
Maintainers
1
Yearly downloads
5,145

Weekly downloads

Readme

Source

Nested Object Access

NPM Downloads

TypeScript-powered util to work with nested objects using dot-separated keys.

Get it on NPM here

This package exports the following stuff:

Helper type: NestedKeys

Returns a union of all dot-separated paths to entries in a nested object.

type TestDict = { b: string; c: { d: number; w: string; e: { p: false } }; t: { l: boolean; e: { q: "foo" } }; i: { d: string | undefined; o: null }; }; // Default functionality // "b" | "c" | "t" | "i" | "c.d" | "c.w" | "c.e.p" | "t.e.q" | "t.l" | "i.d" | "i.o" | "c.e" | "t.e" type TestKeys = NestedKeys<TestDict>; // Get only the paths to primitive values // "b" | "c.d" | "c.w" | "c.e.p" | "t.e.q" | "t.l" | "i.d" | "i.o" type TestKeysPr = NestedKeys<TestDict, "primitives">; // Get only the paths to nested objects // "c" | "t" | "i" | "c.e" | "t.e" type TestKeysObj = NestedKeys<TestDict, "objects">; // Get only up to a certain depth // "b" | "c" | "t" | "i" | "c.d" | "c.w" | "c.e" | "t.e" | "t.l" | "i.d" | "i.o" type TestKeysWithDepth = NestedKeys<TestDict, any, 2>;

Helper type: RetrieveNested

Returns the type that is at a dot-separated path in an object.

type TestDict2 = { c: { e: { p: "pp" } } } // { e: { p: "pp"; }; } type TestNestedPath1 = RetrieveNested<TestDict2, "c">; // { p: "pp"; } type TestNestedPath2 = RetrieveNested<TestDict2, "c.e">; // "pp" type TestNestedPath3 = RetrieveNested<TestDict2, "c.e.p">;

Function: getNested

Function version of RetrieveNested.

import { getNested } from "nested-object-access"; const testDict = { c: { e: { p: "pp" } } }; console.log(getNested(testDict, "c.e.p")); // "pp"

TODO

  • You can currently only pass a type Foo = {...} into the helper functions, not interface Foo {...} because of missing index signature...

Keywords

FAQs

What is nested-object-access?

TypeScript-powered util to work with nested objects using dot-separated keys

Is nested-object-access popular?

The npm package nested-object-access receives a total of 151 weekly downloads. As such, nested-object-access popularity was classified as not popular.

Is nested-object-access well maintained?

We found that nested-object-access demonstrated a healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 06 May 2022
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc