diff --git a/types/find-duplicated-property-keys/find-duplicated-property-keys-tests.ts b/types/find-duplicated-property-keys/find-duplicated-property-keys-tests.ts new file mode 100644 index 0000000000..931c0ba3f3 --- /dev/null +++ b/types/find-duplicated-property-keys/find-duplicated-property-keys-tests.ts @@ -0,0 +1,14 @@ +import findDuplicatedPropertyKeys = require('find-duplicated-property-keys'); + +const jsonString = '{"name": "Carl", "name": "Carla", "data": 1, "data": [{ "data": 1, "data": 2}]}'; + +const result = findDuplicatedPropertyKeys(jsonString); // $ExpectType PropertyInfo[] + +result.forEach(item => { + item.isArray; // $ExpectgType boolean + item.key; // $ExpecgtType string + item.occurrence; // $ExpectType number + item.parent; // $ExpectType PropertyInfo + item.propertyPath; // $ExpectType () => string[] + item.toString(); // $ExpectType string +}); diff --git a/types/find-duplicated-property-keys/index.d.ts b/types/find-duplicated-property-keys/index.d.ts new file mode 100644 index 0000000000..81bf6e2319 --- /dev/null +++ b/types/find-duplicated-property-keys/index.d.ts @@ -0,0 +1,46 @@ +// Type definitions for find-duplicated-property-keys 1.1 +// Project: https://github.com/SebastianG77/find-duplicated-property-keys#readme +// Definitions by: Piotr Błażejewicz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * A package for detecting all duplicated property keys of a JSON string. + * It can either be used as a standalone tool for validating JSON files or as a submodule for other Node.js projects. + */ +declare function findDuplicatedPropertyKeys(content: string): findDuplicatedPropertyKeys.PropertyInfo[]; + +declare namespace findDuplicatedPropertyKeys { + interface PropertyInfo { + /** + * The key name of the duplicated property + */ + key: string; + + /** + * The parent object of a property key + */ + parent: PropertyInfo; + + /** + * The number of property keys having the same key and parent object + */ + occurrence: number; + /** + * Is this property an array + */ + isArray: boolean; + + /** + * Returns a list of property keys, which represents the path to the property key of the current object. + */ + propertyPath(): string[]; + + /** + * Prints the path to the property key. However, since all necessary raw data are also contained by the object, + * the result objects can also be represented in any other way if desired. + */ + toString(): string; + } +} + +export = findDuplicatedPropertyKeys; diff --git a/types/find-duplicated-property-keys/tsconfig.json b/types/find-duplicated-property-keys/tsconfig.json new file mode 100644 index 0000000000..a18516a064 --- /dev/null +++ b/types/find-duplicated-property-keys/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "find-duplicated-property-keys-tests.ts" + ] +} diff --git a/types/find-duplicated-property-keys/tslint.json b/types/find-duplicated-property-keys/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/find-duplicated-property-keys/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }