mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-04 19:42:46 +08:00
[dot-prop] introduce typings for v4 (#18261)
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
/// <reference types="node"/>
|
||||
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);
|
||||
(<any> obj).foo.bar = {x: 'y', y: 'x'};
|
||||
dotProp.delete(obj, 'foo.bar.x');
|
||||
console.log(obj);
|
||||
|
||||
17
types/dot-prop/index.d.ts
vendored
17
types/dot-prop/index.d.ts
vendored
@@ -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 <https://github.com/samverschueren>
|
||||
// BendingBender <https://github.com/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;
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
1
types/dot-prop/tslint.json
Normal file
1
types/dot-prop/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
10
types/dot-prop/v2/dot-prop-tests.ts
Normal file
10
types/dot-prop/v2/dot-prop-tests.ts
Normal file
@@ -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');
|
||||
7
types/dot-prop/v2/index.d.ts
vendored
Normal file
7
types/dot-prop/v2/index.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// Type definitions for dot-prop 2.x
|
||||
// Project: https://github.com/sindresorhus/dot-prop
|
||||
// Definitions by: Sam Verschueren <https://github.com/samverschueren>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export function get(object: any, path: string): any;
|
||||
export function set(object: any, path: string, value: any): void;
|
||||
25
types/dot-prop/v2/tsconfig.json
Normal file
25
types/dot-prop/v2/tsconfig.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
1
types/dot-prop/v2/tslint.json
Normal file
1
types/dot-prop/v2/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user