diff --git a/types/dot-prop/dot-prop-tests.ts b/types/dot-prop/dot-prop-tests.ts index b7687bb64b..420fe2d320 100644 --- a/types/dot-prop/dot-prop-tests.ts +++ b/types/dot-prop/dot-prop-tests.ts @@ -1,11 +1,23 @@ +/// +import dotProp = require('dot-prop'); +import { get, has, set } from 'dot-prop'; -import * as dotProp from 'dot-prop'; - -dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar'); +get({foo: {bar: 'unicorn'}}, 'foo.bar'); dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep'); +dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value'); dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'); const obj = {foo: {bar: 'a'}}; -dotProp.set(obj, 'foo.bar', 'b'); +set(obj, 'foo.bar', 'b'); +console.log(obj); dotProp.set(obj, 'foo.baz', 'x'); -dotProp.set(obj, 'foo.dot\\.dot', 'unicorn'); +console.log(obj); + +has({foo: {bar: 'unicorn'}}, 'foo.bar'); +dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar'); + +dotProp.delete(obj, 'foo.bar'); +console.log(obj); +( obj).foo.bar = {x: 'y', y: 'x'}; +dotProp.delete(obj, 'foo.bar.x'); +console.log(obj); diff --git a/types/dot-prop/index.d.ts b/types/dot-prop/index.d.ts index b8d9ce406c..31877dbd9e 100644 --- a/types/dot-prop/index.d.ts +++ b/types/dot-prop/index.d.ts @@ -1,8 +1,17 @@ -// Type definitions for dot-prop -// Project: https://github.com/sindresorhus/dot-prop +// Type definitions for dot-prop 4.1 +// Project: https://github.com/sindresorhus/dot-prop#readme // Definitions by: Sam Verschueren +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 +interface DotProp { + get(obj: object, path: string, defaultValue?: any): any; + set(obj: object, path: string, value: any): void; + has(obj: object, path: string): boolean; + delete(obj: object, path: string): boolean; +} -export declare function get(object: any, path: string): any; -export declare function set(object: any, path: string, value: any): void; +declare const dotProp: DotProp; + +export = dotProp; diff --git a/types/dot-prop/tsconfig.json b/types/dot-prop/tsconfig.json index f404606239..9569bb6470 100644 --- a/types/dot-prop/tsconfig.json +++ b/types/dot-prop/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -19,4 +19,4 @@ "index.d.ts", "dot-prop-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/dot-prop/tslint.json b/types/dot-prop/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dot-prop/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/dot-prop/v2/dot-prop-tests.ts b/types/dot-prop/v2/dot-prop-tests.ts new file mode 100644 index 0000000000..f9991f8d5b --- /dev/null +++ b/types/dot-prop/v2/dot-prop-tests.ts @@ -0,0 +1,10 @@ +import * as dotProp from 'dot-prop'; + +dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar'); +dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep'); +dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'); + +const obj = {foo: {bar: 'a'}}; +dotProp.set(obj, 'foo.bar', 'b'); +dotProp.set(obj, 'foo.baz', 'x'); +dotProp.set(obj, 'foo.dot\\.dot', 'unicorn'); diff --git a/types/dot-prop/v2/index.d.ts b/types/dot-prop/v2/index.d.ts new file mode 100644 index 0000000000..86964e32a7 --- /dev/null +++ b/types/dot-prop/v2/index.d.ts @@ -0,0 +1,7 @@ +// Type definitions for dot-prop 2.x +// Project: https://github.com/sindresorhus/dot-prop +// Definitions by: Sam Verschueren +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export function get(object: any, path: string): any; +export function set(object: any, path: string, value: any): void; diff --git a/types/dot-prop/v2/tsconfig.json b/types/dot-prop/v2/tsconfig.json new file mode 100644 index 0000000000..2e274e84da --- /dev/null +++ b/types/dot-prop/v2/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "dot-prop": ["dot-prop/v2"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "dot-prop-tests.ts" + ] +} diff --git a/types/dot-prop/v2/tslint.json b/types/dot-prop/v2/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dot-prop/v2/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }