mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[sort-json] Add sort-json (#45932)
This commit is contained in:
parent
d36efb6a51
commit
120445b449
52
types/sort-json/index.d.ts
vendored
Normal file
52
types/sort-json/index.d.ts
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
// Type definitions for sort-json 2.0
|
||||
// Project: https://github.com/kesla/sort-json
|
||||
// Definitions by: Florian Keller <https://github.com/ffflorian>
|
||||
// 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<T>(old: T, options?: visit.VisitOptions): T;
|
||||
|
||||
export = visit;
|
||||
7
types/sort-json/sort-json-tests.ts
Normal file
7
types/sort-json/sort-json-tests.ts
Normal file
@ -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);
|
||||
23
types/sort-json/tsconfig.json
Normal file
23
types/sort-json/tsconfig.json
Normal 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",
|
||||
"sort-json-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/sort-json/tslint.json
Normal file
1
types/sort-json/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user