mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
Merge pull request #32536 from ryansonshine/dlv
Adds type definitions for dlv
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import dlv from 'dlv';
|
||||
|
||||
const obj = {
|
||||
undef: undefined,
|
||||
zero: 0,
|
||||
one: 1,
|
||||
n: null,
|
||||
f: false,
|
||||
a: {
|
||||
two: 2,
|
||||
b: {
|
||||
three: 3,
|
||||
c: {
|
||||
four: 4
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Test without defaults
|
||||
dlv(obj, '');
|
||||
dlv(obj, 'one');
|
||||
dlv(obj, 'one.two');
|
||||
dlv(obj, 'a');
|
||||
dlv(obj, 'a.two');
|
||||
dlv(obj, 'a.b');
|
||||
dlv(obj, 'a.b.three');
|
||||
dlv(obj, 'a.b.c');
|
||||
dlv(obj, 'a.b.c.four');
|
||||
dlv(obj, 'n');
|
||||
dlv(obj, 'n.badkey');
|
||||
dlv(obj, 'f');
|
||||
dlv(obj, 'f.badkey');
|
||||
|
||||
// Test defaults
|
||||
dlv(obj, '', 'foo');
|
||||
dlv(obj, 'undef', 'foo');
|
||||
dlv(obj, 'n', null);
|
||||
dlv(obj, 'n.badkey', 'foo');
|
||||
dlv(obj, 'zero', 0);
|
||||
dlv(obj, 'a.badkey', 'foo');
|
||||
dlv(obj, 'a.badkey.anotherbadkey', 'foo');
|
||||
dlv(obj, 'f', false);
|
||||
dlv(obj, 'f.badkey', 'foo');
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// Type definitions for dlv 1.1
|
||||
// Project: https://github.com/developit/dlv#readme
|
||||
// Definitions by: Ryan Sonshine <https://github.com/ryansonshine>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
export default function dlv(object: object, key: string | string[], defaultValue?: any): any;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"dlv-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user