1 | // Original from DefinitelyTyped. Thanks a million
|
2 | // Type definitions for comment-json 1.1
|
3 | // Project: https://github.com/kaelzhang/node-comment-json
|
4 | // Definitions by: Jason Dent <https://github.com/Jason3S>
|
5 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
6 |
|
7 | // For now, typescript does not support symbol as object/array index key,
|
8 | // just use any to clean the mess
|
9 | // https://github.com/microsoft/TypeScript/issues/1863
|
10 | export type CommentJSONValue = any;
|
11 | export type CommentArray = any;
|
12 |
|
13 | // export type CommentJSONValue = number | string | null | boolean | CommentJSONArray<CommentJSONValue> | CommentJSONObject
|
14 |
|
15 | // // export type CommentJSONArray = Array<CommentJSONValue>
|
16 |
|
17 | // export class CommentJSONArray<CommentJSONValue> extends Array<CommentJSONValue> {
|
18 | // [key: symbol]: CommentToken
|
19 | // }
|
20 |
|
21 | // export interface CommentJSONObject {
|
22 | // [key: string]: CommentJSONValue
|
23 | // [key: symbol]: CommentToken
|
24 | // }
|
25 |
|
26 | // export interface CommentToken {
|
27 | // type: 'BlockComment' | 'LineComment'
|
28 | // // The content of the comment, including whitespaces and line breaks
|
29 | // value: string
|
30 | // // If the start location is the same line as the previous token,
|
31 | // // then `inline` is `true`
|
32 | // inline: boolean
|
33 |
|
34 | // // But pay attention that,
|
35 | // // locations will NOT be maintained when stringified
|
36 | // loc: CommentLocation
|
37 | // }
|
38 |
|
39 | // export interface CommentLocation {
|
40 | // // The start location begins at the `//` or `/*` symbol
|
41 | // start: Location
|
42 | // // The end location of multi-line comment ends at the `*/` symbol
|
43 | // end: Location
|
44 | // }
|
45 |
|
46 | // export interface Location {
|
47 | // line: number
|
48 | // column: number
|
49 | // }
|
50 |
|
51 | export type Reviver = (k: number | string, v: any) => any;
|
52 |
|
53 | /**
|
54 | * Converts a JavaScript Object Notation (JSON) string into an object.
|
55 | * @param json A valid JSON string.
|
56 | * @param reviver A function that transforms the results. This function is called for each member of the object.
|
57 | * @param removes_comments If true, the comments won't be maintained, which is often used when we want to get a clean object.
|
58 | * If a member contains nested objects, the nested objects are transformed before the parent object is.
|
59 | */
|
60 | export function parse(json: string, reviver?: Reviver, removes_comments?: boolean): CommentJSONValue;
|
61 |
|
62 | /**
|
63 | * Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
|
64 | * @param value A JavaScript value, usually an object or array, to be converted.
|
65 | * @param replacer A function that transforms the results or an array of strings and numbers that acts as a approved list for selecting the object properties that will be stringified.
|
66 | * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
|
67 | */
|
68 | export function stringify(value: any, replacer?: ((key: string, value: any) => any) | Array<number | string> | null, space?: string | number): string;
|
69 |
|
70 |
|
71 | export function tokenize(input: string, config?: TokenizeOptions): Token[];
|
72 |
|
73 | export interface Token {
|
74 | type: string;
|
75 | value: string;
|
76 | }
|
77 |
|
78 | export interface TokenizeOptions {
|
79 | tolerant?: boolean;
|
80 | range?: boolean;
|
81 | loc?: boolean;
|
82 | comment?: boolean;
|
83 | }
|
84 |
|
85 | export function assign(target: any, source: any, keys?: Array<string>): any;
|