diff --git a/types/sort-json/index.d.ts b/types/sort-json/index.d.ts new file mode 100644 index 0000000000..af1a30cbee --- /dev/null +++ b/types/sort-json/index.d.ts @@ -0,0 +1,52 @@ +// Type definitions for sort-json 2.0 +// Project: https://github.com/kesla/sort-json +// Definitions by: Florian Keller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace visit { + interface VisitOptions { + /** + * Depth's level sorting keys on a multidimensional object + * (default: `Infinity`) + */ + depth?: number; + /** + * When sorting keys, converts all keys to lowercase so that + * capitalization doesn't interfere with sort order (default: `false`) + */ + ignoreCase?: boolean; + /** Default: `1` */ + level?: number; + /** Reverse the ordering z -> a (default: `false`) */ + reverse?: boolean; + } + + interface OverwriteOptions extends VisitOptions { + /** + * Formats the file content with an indentation of spaces. Use a number + * greater then 0 for the value (default: detects the used indentation + * of the file) + */ + indentSize?: number; + /** Default: `false` */ + noFinalNewLine?: boolean; + } + + /** + * Sorts the JSON files with the `visit()` function and then overwrites the + * file with sorted JSON + * @param absolutePaths + * * String: Absolute path to JSON file to sort and overwrite + * * Array: Absolute paths to JSON files to sort and overwrite + */ + function overwrite(absolutePaths: string | string[], options?: OverwriteOptions): any; +} + +/** + * Sorts the keys on objects + * @param old An object to sort the keys of, if not object just returns whatever + * was given + */ +declare function visit(old: T, options?: visit.VisitOptions): T; + +export = visit; diff --git a/types/sort-json/sort-json-tests.ts b/types/sort-json/sort-json-tests.ts new file mode 100644 index 0000000000..80c85ad240 --- /dev/null +++ b/types/sort-json/sort-json-tests.ts @@ -0,0 +1,7 @@ +import sortJson = require('sort-json'); + +const options: sortJson.VisitOptions = { ignoreCase: true, reverse: true, depth: 1 }; +sortJson({ AA: 123, a: 1, b: 21 }, options); + +sortJson.overwrite('some/absolute/path.json', options); +sortJson.overwrite(['some/absolute/path1.json', 'some/absolute/path2.json'], options); diff --git a/types/sort-json/tsconfig.json b/types/sort-json/tsconfig.json new file mode 100644 index 0000000000..9c3bd8ad2d --- /dev/null +++ b/types/sort-json/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", + "sort-json-tests.ts" + ] +} diff --git a/types/sort-json/tslint.json b/types/sort-json/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/sort-json/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }