source: imaps-frontend/node_modules/ajv/dist/runtime/parseJson.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 5.3 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.parseJsonString = exports.parseJsonNumber = exports.parseJson = void 0;
4const rxParseJson = /position\s(\d+)(?: \(line \d+ column \d+\))?$/;
5function parseJson(s, pos) {
6 let endPos;
7 parseJson.message = undefined;
8 let matches;
9 if (pos)
10 s = s.slice(pos);
11 try {
12 parseJson.position = pos + s.length;
13 return JSON.parse(s);
14 }
15 catch (e) {
16 matches = rxParseJson.exec(e.message);
17 if (!matches) {
18 parseJson.message = "unexpected end";
19 return undefined;
20 }
21 endPos = +matches[1];
22 const c = s[endPos];
23 s = s.slice(0, endPos);
24 parseJson.position = pos + endPos;
25 try {
26 return JSON.parse(s);
27 }
28 catch (e1) {
29 parseJson.message = `unexpected token ${c}`;
30 return undefined;
31 }
32 }
33}
34exports.parseJson = parseJson;
35parseJson.message = undefined;
36parseJson.position = 0;
37parseJson.code = 'require("ajv/dist/runtime/parseJson").parseJson';
38function parseJsonNumber(s, pos, maxDigits) {
39 let numStr = "";
40 let c;
41 parseJsonNumber.message = undefined;
42 if (s[pos] === "-") {
43 numStr += "-";
44 pos++;
45 }
46 if (s[pos] === "0") {
47 numStr += "0";
48 pos++;
49 }
50 else {
51 if (!parseDigits(maxDigits)) {
52 errorMessage();
53 return undefined;
54 }
55 }
56 if (maxDigits) {
57 parseJsonNumber.position = pos;
58 return +numStr;
59 }
60 if (s[pos] === ".") {
61 numStr += ".";
62 pos++;
63 if (!parseDigits()) {
64 errorMessage();
65 return undefined;
66 }
67 }
68 if (((c = s[pos]), c === "e" || c === "E")) {
69 numStr += "e";
70 pos++;
71 if (((c = s[pos]), c === "+" || c === "-")) {
72 numStr += c;
73 pos++;
74 }
75 if (!parseDigits()) {
76 errorMessage();
77 return undefined;
78 }
79 }
80 parseJsonNumber.position = pos;
81 return +numStr;
82 function parseDigits(maxLen) {
83 let digit = false;
84 while (((c = s[pos]), c >= "0" && c <= "9" && (maxLen === undefined || maxLen-- > 0))) {
85 digit = true;
86 numStr += c;
87 pos++;
88 }
89 return digit;
90 }
91 function errorMessage() {
92 parseJsonNumber.position = pos;
93 parseJsonNumber.message = pos < s.length ? `unexpected token ${s[pos]}` : "unexpected end";
94 }
95}
96exports.parseJsonNumber = parseJsonNumber;
97parseJsonNumber.message = undefined;
98parseJsonNumber.position = 0;
99parseJsonNumber.code = 'require("ajv/dist/runtime/parseJson").parseJsonNumber';
100const escapedChars = {
101 b: "\b",
102 f: "\f",
103 n: "\n",
104 r: "\r",
105 t: "\t",
106 '"': '"',
107 "/": "/",
108 "\\": "\\",
109};
110const CODE_A = "a".charCodeAt(0);
111const CODE_0 = "0".charCodeAt(0);
112function parseJsonString(s, pos) {
113 let str = "";
114 let c;
115 parseJsonString.message = undefined;
116 // eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
117 while (true) {
118 c = s[pos++];
119 if (c === '"')
120 break;
121 if (c === "\\") {
122 c = s[pos];
123 if (c in escapedChars) {
124 str += escapedChars[c];
125 pos++;
126 }
127 else if (c === "u") {
128 pos++;
129 let count = 4;
130 let code = 0;
131 while (count--) {
132 code <<= 4;
133 c = s[pos];
134 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
135 if (c === undefined) {
136 errorMessage("unexpected end");
137 return undefined;
138 }
139 c = c.toLowerCase();
140 if (c >= "a" && c <= "f") {
141 code += c.charCodeAt(0) - CODE_A + 10;
142 }
143 else if (c >= "0" && c <= "9") {
144 code += c.charCodeAt(0) - CODE_0;
145 }
146 else {
147 errorMessage(`unexpected token ${c}`);
148 return undefined;
149 }
150 pos++;
151 }
152 str += String.fromCharCode(code);
153 }
154 else {
155 errorMessage(`unexpected token ${c}`);
156 return undefined;
157 }
158 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
159 }
160 else if (c === undefined) {
161 errorMessage("unexpected end");
162 return undefined;
163 }
164 else {
165 if (c.charCodeAt(0) >= 0x20) {
166 str += c;
167 }
168 else {
169 errorMessage(`unexpected token ${c}`);
170 return undefined;
171 }
172 }
173 }
174 parseJsonString.position = pos;
175 return str;
176 function errorMessage(msg) {
177 parseJsonString.position = pos;
178 parseJsonString.message = msg;
179 }
180}
181exports.parseJsonString = parseJsonString;
182parseJsonString.message = undefined;
183parseJsonString.position = 0;
184parseJsonString.code = 'require("ajv/dist/runtime/parseJson").parseJsonString';
185//# sourceMappingURL=parseJson.js.map
Note: See TracBrowser for help on using the repository browser.