(options: DecodeOptions | undefined)
| 134 | } |
| 135 | |
| 136 | const makeConfig = (options: DecodeOptions | undefined): Config => { |
| 137 | const pointer = options?.pointer ?? "" |
| 138 | if (pointer !== "" && (!pointer.startsWith("/") || /~(?:[^01]|$)/.test(pointer))) { |
| 139 | throw new Error(`JsonArray: pointer must be an RFC 6901 JSON Pointer, got ${JSON.stringify(pointer)}`) |
| 140 | } |
| 141 | const maxDepth = options?.maxDepth ?? 1000 |
| 142 | if (!(Number.isInteger(maxDepth) && maxDepth >= 0)) { |
| 143 | throw new Error(`JsonArray: maxDepth must be a non-negative integer, got ${maxDepth}`) |
| 144 | } |
| 145 | const maxElementSize = options?.maxElementSize ?? 16 * 1024 * 1024 |
| 146 | if (!(maxElementSize >= 1)) { |
| 147 | throw new Error(`JsonArray: maxElementSize must be at least 1, got ${maxElementSize}`) |
| 148 | } |
| 149 | const tokens = pointer === "" ? [] : pointer.slice(1).split("/").map(JsonPointer.unescapeToken) |
| 150 | return { |
| 151 | tokens, |
| 152 | indices: tokens.map((token) => /^(?:0|[1-9]\d*)$/.test(token) ? Number(token) : -1), |
| 153 | maxDepth, |
| 154 | maxElementSize |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | const TAB = 9 |
| 159 | const LF = 10 |
no test coverage detected