UNPKG

1.62 kBTypeScriptView Raw
1/**
2 * JSON parser.
3 */
4/**
5 * ============================================================================
6 * IMPORTS
7 * ============================================================================
8 * @hidden
9 */
10import { DataParser, IDataParserOptions } from "./DataParser";
11import { DateFormatter } from "../formatters/DateFormatter";
12/**
13 * Defines options for JSON format parser
14 */
15export interface IJSONOptions extends IDataParserOptions {
16 /**
17 * A list of fields that should be treaded as numeric.
18 *
19 * Any information container in such fields will be converted to `number`.
20 */
21 numberFields?: string[];
22 /**
23 * A list of fields that hold date/time infromation.
24 *
25 * Parser will try to convert such fields into `Date` objects.
26 */
27 dateFields?: string[];
28 /**
29 * A date formatted to be used when parsing dates.
30 */
31 dateFormatter?: DateFormatter;
32}
33/**
34 * A parser for JSON.
35 *
36 * @important
37 */
38export declare class JSONParser extends DataParser {
39 /**
40 * Tests if the data is valid JSON.
41 *
42 * @param data Source data
43 * @return Is it JSON?
44 */
45 static isJSON(data: string): boolean;
46 /**
47 * Content-type suitable for JSON format.
48 */
49 contentType: string;
50 /**
51 * Parser options.
52 *
53 * @see {@link IJSONOptions} for description of each option
54 */
55 options: IJSONOptions;
56 /**
57 * Parses and returns data.
58 *
59 * @param data Unparsed data
60 * @return Parsed data
61 */
62 parse(data: string): any;
63}