From 90298b1f8bd69d6af23607b457a291330e71cdb8 Mon Sep 17 00:00:00 2001 From: Rebecca Turner <637275@gmail.com> Date: Thu, 8 Aug 2019 10:07:45 -0700 Subject: [PATCH] [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 --- types/pathval/index.d.ts | 21 +++++++++++++++++++++ types/pathval/pathval-tests.ts | 18 ++++++++++++++++++ types/pathval/tsconfig.json | 23 +++++++++++++++++++++++ types/pathval/tslint.json | 3 +++ 4 files changed, 65 insertions(+) create mode 100644 types/pathval/index.d.ts create mode 100644 types/pathval/pathval-tests.ts create mode 100644 types/pathval/tsconfig.json create mode 100644 types/pathval/tslint.json diff --git a/types/pathval/index.d.ts b/types/pathval/index.d.ts new file mode 100644 index 0000000000..24c2f7cf93 --- /dev/null +++ b/types/pathval/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for pathval 1.1 +// Project: https://www.npmjs.com/package/pathval +// Definitions by: Rebecca Turner +// 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; diff --git a/types/pathval/pathval-tests.ts b/types/pathval/pathval-tests.ts new file mode 100644 index 0000000000..cf5ade0a20 --- /dev/null +++ b/types/pathval/pathval-tests.ts @@ -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' diff --git a/types/pathval/tsconfig.json b/types/pathval/tsconfig.json new file mode 100644 index 0000000000..5bb83e2210 --- /dev/null +++ b/types/pathval/tsconfig.json @@ -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 + } +} diff --git a/types/pathval/tslint.json b/types/pathval/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/pathval/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}