Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /** * Sometimes you don't allow every type to be partially parsed. * For example, you may not want a partial number because it may increase its size gradually before it's complete. * In this case, you can use the `Allow` object to control what types you allow to be partially parsed. * @module */ /** * Allow partial strings like `"hello \u12` to be parsed as `"hello "` */ export const STR = 0b000000001; // 1 /** * Allow partial numbers like `123.` to be parsed as `123` */ export const NUM = 0b000000010; // 2 /** * Allow partial arrays like `[1, 2,` to be parsed as `[1, 2]` */ export const ARR = 0b000000100; // 4 /** * Allow partial objects like `{"a": 1, "b":` to be parsed as `{"a": 1}` */ export const OBJ = 0b000001000; // 8 /** * Allow `nu` to be parsed as `null` */ export const NULL = 0b000010000; // 16 /** * Allow `tr` to be parsed as `true`, and `fa` to be parsed as `false` */ export const BOOL = 0b000100000; // 32 /** * Allow `Na` to be parsed as `NaN` */ export const NAN = 0b001000000; // 64 /** * Allow `Inf` to be parsed as `Infinity` */ export const INFINITY = 0b010000000; // 128 /** * Allow `-Inf` to be parsed as `-Infinity` */ export const _INFINITY = 0b100000000; // 256 /** * Allow partial parsing of the outermost JSON object */ export const OUTERMOST_OBJ = 0b0000000100000000; // 512 /** * Allow partial parsing of the outermost JSON array */ export const OUTERMOST_ARR = 0b0000001000000000; // 1024 export const INF = INFINITY | _INFINITY; // 384 export const SPECIAL = NULL | BOOL | INF | NAN; // 432 export const ATOM = STR | NUM | SPECIAL; // 499 export const COLLECTION = ARR | OBJ; // 12 export const ALL = ATOM | COLLECTION; // 511 /** * Control what types you allow to be partially parsed. * The default is to allow all types to be partially parsed, which in most cases is the best option. * @example * If you don't want to allow partial objects, you can use the following code: * ```ts * import { Allow, parse } from "partial-json"; * parse(`[{"a": 1, "b": 2}, {"a": 3,`, Allow.ARR); // [ { a: 1, b: 2 } ] * ``` * Or you can use `~` to disallow a type: * ```ts * parse(`[{"a": 1, "b": 2}, {"a": 3,`, ~Allow.OBJ); // [ { a: 1, b: 2 } ] * ``` * @example * If you don't want to allow partial strings, you can use the following code: * ```ts * import { Allow, parse } from "partial-json"; * parse(`["complete string", "incompl`, ~Allow.STR); // [ 'complete string' ] * ``` */ export const Allow = { STR, NUM, ARR, OBJ, NULL, BOOL, NAN, INFINITY, _INFINITY, OUTERMOST_OBJ, OUTERMOST_ARR, INF, SPECIAL, ATOM, COLLECTION, ALL, }; export default Allow; |