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

Function markIntegerIndexKeys

apps/json-format/json-auto-utils.js:145–192  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

143 }
144
145 function markIntegerIndexKeys(source) {
146 source = String(source || '');
147 let result = '';
148 let i = 0;
149
150 while (i < source.length) {
151 if (source[i] !== '"') {
152 result += source[i++];
153 continue;
154 }
155
156 const start = i;
157 i++;
158 let escaped = false;
159 while (i < source.length) {
160 const char = source[i++];
161 if (escaped) {
162 escaped = false;
163 continue;
164 }
165 if (char === '\\') {
166 escaped = true;
167 continue;
168 }
169 if (char === '"') {
170 break;
171 }
172 }
173
174 const rawKey = source.slice(start, i);
175 let j = i;
176 while (j < source.length && /\s/.test(source[j])) j++;
177
178 if (source[j] === ':') {
179 try {
180 const key = JSON.parse(rawKey);
181 if (isIntegerIndexKey(key)) {
182 result += JSON.stringify(PRESERVED_INTEGER_KEY_PREFIX + key);
183 continue;
184 }
185 } catch (_) {}
186 }
187
188 result += rawKey;
189 }
190
191 return result;
192 }
193
194 function normalizePreservedKey(key) {
195 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