feat(find-duplicated-property-keys): new definition (#47058)

Definition types for JSON utility
- definition file
- tests

https://github.com/SebastianG77/find-duplicated-property-keys
https://www.npmjs.com/package/find-duplicated-property-keys

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-08-27 03:57:21 +02:00 committed by GitHub
parent 226c237a52
commit 042839f349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 0 deletions

View File

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

View File

@ -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 <https://github.com/peterblazejewicz>
// 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;

View File

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

View File

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