mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
prettier-package-json: Add type definitions (#35790)
This commit is contained in:
parent
8ce8f37634
commit
5ce88a3373
18
types/prettier-package-json/index.d.ts
vendored
Normal file
18
types/prettier-package-json/index.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Type definitions for prettier-package-json 2.1
|
||||
// Project: https://github.com/cameronhunter/prettier-package-json
|
||||
// Definitions by: Daniel Cassidy <https://github.com/djcsdy>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export type CompareFn = (a: string, b: string) => number;
|
||||
|
||||
export interface Options {
|
||||
tabWidth?: number;
|
||||
useTabs?: boolean;
|
||||
expandUsers?: boolean;
|
||||
keyOrder?: ReadonlyArray<string> | CompareFn;
|
||||
}
|
||||
|
||||
export function format(json: object, options?: Options): string;
|
||||
|
||||
export function check(json: string | object, options?: Options): boolean;
|
||||
69
types/prettier-package-json/prettier-package-json-tests.ts
Normal file
69
types/prettier-package-json/prettier-package-json-tests.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { format, check } from "prettier-package-json";
|
||||
|
||||
const json = {
|
||||
name: "some-package",
|
||||
version: "0.0.0"
|
||||
};
|
||||
|
||||
// $ExpectType string
|
||||
format(json);
|
||||
|
||||
// $ExpectType string
|
||||
format(json, {});
|
||||
|
||||
// $ExpectType string
|
||||
format(json, {
|
||||
tabWidth: 2,
|
||||
useTabs: false,
|
||||
expandUsers: false,
|
||||
keyOrder: ["name", "version"]
|
||||
});
|
||||
|
||||
// $ExpectType string
|
||||
format(json, {
|
||||
tabWidth: 4,
|
||||
useTabs: true,
|
||||
expandUsers: true,
|
||||
keyOrder: (a, b) => {
|
||||
// $ExpectType string
|
||||
a;
|
||||
|
||||
// ExpectType string
|
||||
b;
|
||||
|
||||
return b < a ? -1 : b > a ? 1 : 0;
|
||||
}
|
||||
});
|
||||
|
||||
// $ExpectType boolean
|
||||
check("");
|
||||
|
||||
// $ExpectType boolean
|
||||
check(json);
|
||||
|
||||
// $ExpectType boolean
|
||||
check("", {});
|
||||
|
||||
// $ExpectType boolean
|
||||
check(json, {});
|
||||
|
||||
// $ExpectType boolean
|
||||
check("", {
|
||||
tabWidth: 8,
|
||||
useTabs: true,
|
||||
expandUsers: false,
|
||||
keyOrder: ["private", "version"]
|
||||
});
|
||||
|
||||
// $ExpectType boolean
|
||||
check(json, {
|
||||
keyOrder: (a, b) => {
|
||||
// $ExpectType string
|
||||
a;
|
||||
|
||||
// $ExpectType string
|
||||
b;
|
||||
|
||||
return b < a ? -1 : b > a ? 1 : 0;
|
||||
}
|
||||
});
|
||||
23
types/prettier-package-json/tsconfig.json
Normal file
23
types/prettier-package-json/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"prettier-package-json-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/prettier-package-json/tslint.json
Normal file
1
types/prettier-package-json/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user