mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[pathval] Add types for pathval (#37453)
* [pathval] Add types for pathval * Clean up redundant interfaces, use UMD mod. syntax Changes requested by @sandersn - Don't override lint rules in tslint.json - Use modern UMD module syntax - Removed redundant namespaces
This commit is contained in:
parent
659898602e
commit
90298b1f8b
21
types/pathval/index.d.ts
vendored
Normal file
21
types/pathval/index.d.ts
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// Type definitions for pathval 1.1
|
||||
// Project: https://www.npmjs.com/package/pathval
|
||||
// Definitions by: Rebecca Turner <https://github.com/9999years>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export interface PathInfo {
|
||||
parent: object;
|
||||
name: string;
|
||||
value?: any;
|
||||
exists: boolean;
|
||||
}
|
||||
|
||||
export type Property = string | symbol | number;
|
||||
|
||||
export function hasProperty(obj: object | undefined | null, name: Property): boolean;
|
||||
export function getPathInfo(obj: object, path: string): PathInfo;
|
||||
export function getPathValue(obj: object, path: string): object | undefined;
|
||||
export function setPathValue(obj: object, path: string, val: any): object;
|
||||
|
||||
export as namespace pathval;
|
||||
18
types/pathval/pathval-tests.ts
Normal file
18
types/pathval/pathval-tests.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import * as pathval from 'pathval';
|
||||
|
||||
const obj = { prop: 'a value' };
|
||||
pathval.hasProperty(obj, 'prop'); // true
|
||||
|
||||
const earth = { earth: { country: 'Brazil' } };
|
||||
pathval.getPathInfo(earth, 'earth.country');
|
||||
const info: pathval.PathInfo = {
|
||||
parent: { country: 'Brazil' },
|
||||
name: 'country',
|
||||
value: 'Brazil',
|
||||
exists: true,
|
||||
};
|
||||
|
||||
pathval.getPathValue(earth, 'earth.country'); // 'Brazil'
|
||||
|
||||
pathval.setPathValue(earth, 'earth.country', 'USA');
|
||||
const usa: string = earth.earth.country; // 'USA'
|
||||
23
types/pathval/tsconfig.json
Normal file
23
types/pathval/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"pathval-tests.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
3
types/pathval/tslint.json
Normal file
3
types/pathval/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user