dlv

WebJar for dlv

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

dlv
Last Version

Last Version

1.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

dlv
WebJar for dlv
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/developit/dlv

Download dlv

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/dlv/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>dlv</artifactId>
    <version>1.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/dlv/
implementation 'org.webjars.npm:dlv:1.1.3'
// https://jarcasting.com/artifacts/org.webjars.npm/dlv/
implementation ("org.webjars.npm:dlv:1.1.3")
'org.webjars.npm:dlv:jar:1.1.3'
<dependency org="org.webjars.npm" name="dlv" rev="1.1.3">
  <artifact name="dlv" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='dlv', version='1.1.3')
)
libraryDependencies += "org.webjars.npm" % "dlv" % "1.1.3"
[org.webjars.npm/dlv "1.1.3"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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

Versions

Version
1.1.3
1.1.2