XinXiKuaiBaoYuan/vue-info-reporter/node_modules/dlv
lixinran f57e8494f4 Initial commit: 知识采集分析Agent项目
- Django后端API服务
- Vue前端界面
- 集成王璞智能分析API
- 任务管理和报告生成功能
- Element Plus UI组件
- 响应式布局设计
2025-10-14 15:47:56 +08:00
..
dist Initial commit: 知识采集分析Agent项目 2025-10-14 15:47:56 +08:00
README.md Initial commit: 知识采集分析Agent项目 2025-10-14 15:47:56 +08:00
index.js Initial commit: 知识采集分析Agent项目 2025-10-14 15:47:56 +08:00
package.json Initial commit: 知识采集分析Agent项目 2025-10-14 15:47:56 +08:00

README.md

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 130 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