Skip to content

Commit eef0999

Browse files
authored
feat: add types declaration file with entry in package.json
1 parent 32bb2cd commit eef0999

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

lib/index.d.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
declare type StringifyOptions = Partial<{
2+
/**
3+
* A function that alters the behavior of the stringification process, or an
4+
* array of String and Number objects that serve as a whitelist for
5+
* selecting/filtering the properties of the value object to be included in
6+
* the JSON5 string. If this value is null or not provided, all properties
7+
* of the object are included in the resulting JSON5 string.
8+
*/
9+
replacer: ((this: any, key: string, value: any) => any) | (string | number)[];
10+
11+
/**
12+
* A String or Number object that's used to insert white space into the
13+
* output JSON5 string for readability purposes. If this is a Number, it
14+
* indicates the number of space characters to use as white space; this
15+
* number is capped at 10 (if it is greater, the value is just 10). Values
16+
* less than 1 indicate that no space should be used. If this is a String,
17+
* the string (or the first 10 characters of the string, if it's longer than
18+
* that) is used as white space. If this parameter is not provided (or is
19+
* null), no white space is used. If white space is used, trailing commas
20+
* will be used in objects and arrays.
21+
*/
22+
space: string | number;
23+
24+
/**
25+
* A String representing the quote character to use when serializing strings.
26+
*/
27+
quote: string;
28+
}>
29+
30+
/**
31+
* Parses a JSON5 string, constructing the JavaScript value or object described
32+
* by the string. An optional reviver function can be provided to perform a
33+
* transformation on the resulting object before it is returned.
34+
* @param text The string to parse as JSON5.
35+
* @param reviver If a function, this prescribes how the value originally
36+
* produced by parsing is transformed, before being returned.
37+
*/
38+
export function parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
39+
40+
/**
41+
* Converts a JavaScript value to a JSON5 string, optionally replacing values
42+
* if a replacer function is specified, or optionally including only the
43+
* specified properties if a replacer array is specified.
44+
* @param value The value to convert to a JSON5 string.
45+
* @param replacer A function that alters the behavior of the stringification
46+
* process, or an array of String and Number objects that serve as a whitelist
47+
* for selecting/filtering the properties of the value object to be included in
48+
* the JSON5 string. If this value is null or not provided, all properties of
49+
* the object are included in the resulting JSON5 string.
50+
* @param space A String or Number object that's used to insert white space
51+
* into the output JSON5 string for readability purposes. If this is a Number,
52+
* it indicates the number of space characters to use as white space; this
53+
* number is capped at 10 (if it is greater, the value is just 10). Values less
54+
* than 1 indicate that no space should be used. If this is a String, the
55+
* string (or the first 10 characters of the string, if it's longer than that)
56+
* is used as white space. If this parameter is not provided (or is null), no
57+
* white space is used. If white space is used, trailing commas will be used in
58+
* objects and arrays.
59+
*/
60+
export function stringify(value: any, replacer?: ((this: any, key: string, value: any) => any) | (string | number)[], space?: string | number): string;
61+
62+
/**
63+
* Converts a JavaScript value to a JSON5 string, optionally replacing values
64+
* if a replacer function is specified, or optionally including only the
65+
* specified properties if a replacer array is specified.
66+
* @param value The value to convert to a JSON5 string.
67+
* @param options An object with the following properties:
68+
*
69+
* `replacer`: Same as the `replacer` parameter.
70+
*
71+
* `space`: Same as the `space` parameter.
72+
*
73+
* `quote`: A String representing the quote character to use when serializing
74+
* strings.
75+
*/
76+
export function stringify(value: any, options?: StringifyOptions): string;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"module": "dist/index.mjs",
77
"bin": "lib/cli.js",
88
"browser": "dist/index.js",
9+
"types": "lib/index.d.ts",
910
"files": [
1011
"lib/",
1112
"dist/"

0 commit comments

Comments
 (0)