[dot-prop] introduce typings for v4 (#18261)

This commit is contained in:
Dimitri Benin
2017-07-25 16:33:22 +02:00
committed by Andy
parent a7a3bd380b
commit d4ae9d2f0d
8 changed files with 76 additions and 11 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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"
]
}
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View 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
View 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;

View 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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }