Merge pull request #32536 from ryansonshine/dlv

Adds type definitions for dlv
This commit is contained in:
Pranav Senthilnathan
2019-01-29 15:44:21 -08:00
committed by GitHub
4 changed files with 80 additions and 0 deletions
+44
View File
@@ -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');
+12
View File
@@ -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;
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }