source: trip-planner-front/node_modules/ajv/dist/runtime/parseJson.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.1 KB
RevLine 
[6a3a178]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.parseJsonString = exports.parseJsonNumber = exports.parseJson = void 0;
4const rxParseJson = /position\s(\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].toLowerCase();
134 if (c >= "a" && c <= "f") {
135 code += c.charCodeAt(0) - CODE_A + 10;
136 }
137 else if (c >= "0" && c <= "9") {
138 code += c.charCodeAt(0) - CODE_0;
139 }
140 else if (c === undefined) {
141 errorMessage("unexpected end");
142 return undefined;
143 }
144 else {
145 errorMessage(`unexpected token ${c}`);
146 return undefined;
147 }
148 pos++;
149 }
150 str += String.fromCharCode(code);
151 }
152 else {
153 errorMessage(`unexpected token ${c}`);
154 return undefined;
155 }
156 }
157 else if (c === undefined) {
158 errorMessage("unexpected end");
159 return undefined;
160 }
161 else {
162 if (c.charCodeAt(0) >= 0x20) {
163 str += c;
164 }
165 else {
166 errorMessage(`unexpected token ${c}`);
167 return undefined;
168 }
169 }
170 }
171 parseJsonString.position = pos;
172 return str;
173 function errorMessage(msg) {
174 parseJsonString.position = pos;
175 parseJsonString.message = msg;
176 }
177}
178exports.parseJsonString = parseJsonString;
179parseJsonString.message = undefined;
180parseJsonString.position = 0;
181parseJsonString.code = 'require("ajv/dist/runtime/parseJson").parseJsonString';
182//# sourceMappingURL=parseJson.js.map
Note: See TracBrowser for help on using the repository browser.