MCPcopy Create free account
hub / github.com/zxlie/FeHelper / markIntegerIndexKeys

Function markIntegerIndexKeys

apps/json-format/json-utils.js:156–203  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

154}
155
156export function markIntegerIndexKeys(source) {
157 source = String(source || '');
158 let result = '';
159 let i = 0;
160
161 while (i < source.length) {
162 if (source[i] !== '"') {
163 result += source[i++];
164 continue;
165 }
166
167 const start = i;
168 i++;
169 let escaped = false;
170 while (i < source.length) {
171 const char = source[i++];
172 if (escaped) {
173 escaped = false;
174 continue;
175 }
176 if (char === '\\') {
177 escaped = true;
178 continue;
179 }
180 if (char === '"') {
181 break;
182 }
183 }
184
185 const rawKey = source.slice(start, i);
186 let j = i;
187 while (j < source.length && /\s/.test(source[j])) j++;
188
189 if (source[j] === ':') {
190 try {
191 const key = JSON.parse(rawKey);
192 if (isIntegerIndexKey(key)) {
193 result += JSON.stringify(PRESERVED_INTEGER_KEY_PREFIX + key);
194 continue;
195 }
196 } catch (_) {}
197 }
198
199 result += rawKey;
200 }
201
202 return result;
203}
204
205export function normalizePreservedKey(key) {
206 if (typeof key === 'string' && key.indexOf(PRESERVED_INTEGER_KEY_PREFIX) === 0) {

Callers 1

parseWithBigIntFunction · 0.70

Calls 2

isIntegerIndexKeyFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected