All Projects → developit → Dlv

developit / Dlv

Safe deep property access in 120 bytes. x = dlv(obj, 'a.b.x')

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Dlv

ObjectUI
Create SwiftUI Views with any data
Stars: ✭ 19 (-98.23%)
Mutual labels:  object
Morphism
⚡ Type-safe data transformer for JavaScript, TypeScript & Node.js.
Stars: ✭ 336 (-68.63%)
Mutual labels:  object
Shallow Clone
Make a shallow clone of an object, array or primitive.
Stars: ✭ 23 (-97.85%)
Mutual labels:  object
fromentries
Object.fromEntries() ponyfill (in 6 lines)
Stars: ✭ 62 (-94.21%)
Mutual labels:  object
Pysot Toolkit
Python Single Object Tracking Evaluation
Stars: ✭ 262 (-75.54%)
Mutual labels:  object
Object Graph
Provides useful operations on PHP object graphs
Stars: ✭ 443 (-58.64%)
Mutual labels:  object
Less3
Less3 is an S3-compatible object storage server that runs on your laptop, servers, just about anywhere!
Stars: ✭ 16 (-98.51%)
Mutual labels:  object
Change By Example
Finds a function that transforms a given object into another given object.
Stars: ✭ 32 (-97.01%)
Mutual labels:  object
Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (-74.98%)
Mutual labels:  object
Icaro
Smart and efficient javascript object observer, ideal for batching DOM updates (~1kb)
Stars: ✭ 568 (-46.97%)
Mutual labels:  object
Kvpbase
Scalable, simple RESTful object storage platform, written in C#
Stars: ✭ 43 (-95.99%)
Mutual labels:  object
Simple-YAML
A Java API that provides an easy-to-use way to store data using the YAML format.
Stars: ✭ 68 (-93.65%)
Mutual labels:  object
Deep Object Diff
Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️
Stars: ✭ 515 (-51.91%)
Mutual labels:  object
python-yamlable
A thin wrapper of PyYaml to convert Python objects to YAML and back
Stars: ✭ 28 (-97.39%)
Mutual labels:  object
Reconstruct
👷 Iterate over properties and merge them into a new object.
Stars: ✭ 11 (-98.97%)
Mutual labels:  object
normalize-pkg
Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs.
Stars: ✭ 18 (-98.32%)
Mutual labels:  object
Fmt Obj
Stringifies any javascript object in your console for CLI inspection ✨
Stars: ✭ 428 (-60.04%)
Mutual labels:  object
Objecttransport
Send and Receive objects over TCP or UDP
Stars: ✭ 39 (-96.36%)
Mutual labels:  object
Object.reduce
Reduces an object to a value that is the accumulated result of running each property in the object through a callback. JavaScript/node.js utility.
Stars: ✭ 11 (-98.97%)
Mutual labels:  object
Moses
Utility library for functional programming in Lua
Stars: ✭ 541 (-49.49%)
Mutual labels:  object

dlv(obj, keypath) NPM Build

Safely get a dot-notated path within a nested object, with ability to return a default if the full key path does not exist or the value is undefined

Why?

Smallest possible implementation: only 120 bytes.

You could write this yourself, but then you'd have to write tests.

Supports ES Modules, CommonJS and globals.

Installation

npm install --save dlv

Usage

delve(object, keypath, [default])

import delve from 'dlv';

let obj = {
	a: {
		b: {
			c: 1,
			d: undefined,
			e: null
		}
	}
};

//use string dot notation for keys
delve(obj, 'a.b.c') === 1;

//or use an array key
delve(obj, ['a', 'b', 'c']) === 1;

delve(obj, 'a.b') === obj.a.b;

//returns undefined if the full key path does not exist and no default is specified
delve(obj, 'a.b.f') === undefined;

//optional third parameter for default if the full key in path is missing
delve(obj, 'a.b.f', 'foo') === 'foo';

//or if the key exists but the value is undefined
delve(obj, 'a.b.d', 'foo') === 'foo';

//Non-truthy defined values are still returned if they exist at the full keypath
delve(obj, 'a.b.e', 'foo') === null;

//undefined obj or key returns undefined, unless a default is supplied
delve(undefined, 'a.b.c') === undefined;
delve(undefined, 'a.b.c', 'foo') === 'foo';
delve(obj, undefined, 'foo') === 'foo';

Setter Counterparts

  • dset by @lukeed is the spiritual "set" counterpart of dlv and very fast.
  • bury by @kalmbach does the opposite of dlv and is implemented in a very similar manner.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].