vectocore4 0.0.28 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +45 -32
- package/dist/mjs/index.js +45 -32
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -340,46 +340,59 @@ class Lens {
|
|
|
340
340
|
});
|
|
341
341
|
}
|
|
342
342
|
jsonAutoComplete(jsonString) {
|
|
343
|
-
const dataCloseChar = {
|
|
344
|
-
"{": "}",
|
|
345
|
-
"[": "]",
|
|
346
|
-
'"': '"',
|
|
347
|
-
};
|
|
348
343
|
if (!jsonString)
|
|
349
344
|
return null;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
missingChars.pop();
|
|
345
|
+
const stack = [];
|
|
346
|
+
let isInsideString = false;
|
|
347
|
+
let isEscaped = false;
|
|
348
|
+
for (let i = 0; i < jsonString.length; i++) {
|
|
349
|
+
const char = jsonString[i];
|
|
350
|
+
if (isEscaped) {
|
|
351
|
+
isEscaped = false;
|
|
352
|
+
continue;
|
|
359
353
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
354
|
+
if (char === "\\") {
|
|
355
|
+
isEscaped = true;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if (char === '"') {
|
|
359
|
+
isInsideString = !isInsideString;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (!isInsideString) {
|
|
363
|
+
if (char === "{")
|
|
364
|
+
stack.push("}");
|
|
365
|
+
else if (char === "[")
|
|
366
|
+
stack.push("]");
|
|
367
|
+
else if (char === "}" || char === "]") {
|
|
368
|
+
if (stack.length > 0 && stack[stack.length - 1] === char) {
|
|
369
|
+
stack.pop();
|
|
370
|
+
}
|
|
364
371
|
}
|
|
365
372
|
}
|
|
366
373
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
374
|
+
let result = jsonString.trim();
|
|
375
|
+
// 1. 문자열이 열린 채로 끝났다면 따옴표 닫기
|
|
376
|
+
if (isInsideString) {
|
|
377
|
+
result += '"';
|
|
378
|
+
}
|
|
379
|
+
// 2. trailing comma 제거 (중요: ", ]" 또는 ", }" 방지)
|
|
380
|
+
result = result.replace(/,\s*$/, "");
|
|
381
|
+
// 3. 스택을 역순으로 닫기 전에, 속성 이름만 있고 값이 없는 경우 처리
|
|
382
|
+
// 예: "key": 문자로 끝난 경우
|
|
383
|
+
if (result.endsWith(":")) {
|
|
384
|
+
result += "null";
|
|
385
|
+
}
|
|
386
|
+
// 4. 남아있는 모든 괄호 닫기
|
|
387
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
388
|
+
const closingChar = stack[i];
|
|
389
|
+
// 배열 중간에서 끊겼을 때를 위한 보정 (예: [{}, { -> [{}, {}])
|
|
390
|
+
if (closingChar === "]" && result.endsWith(",")) {
|
|
391
|
+
result = result.slice(0, -1);
|
|
373
392
|
}
|
|
393
|
+
result += closingChar;
|
|
374
394
|
}
|
|
375
|
-
|
|
376
|
-
const completeString = string + missingCharsString;
|
|
377
|
-
const cleanedString = completeString
|
|
378
|
-
.replace(/"":/g, "")
|
|
379
|
-
.replace(/":}|": }/g, '": null }')
|
|
380
|
-
.replace(/,""}|,}|,\"\w+\"}/g, "}")
|
|
381
|
-
.replace(/},]/g, "}]");
|
|
382
|
-
return cleanedString;
|
|
395
|
+
return result;
|
|
383
396
|
}
|
|
384
397
|
}
|
|
385
398
|
exports.Lens = Lens;
|
package/dist/mjs/index.js
CHANGED
|
@@ -301,46 +301,59 @@ export class Lens {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
jsonAutoComplete(jsonString) {
|
|
304
|
-
const dataCloseChar = {
|
|
305
|
-
"{": "}",
|
|
306
|
-
"[": "]",
|
|
307
|
-
'"': '"',
|
|
308
|
-
};
|
|
309
304
|
if (!jsonString)
|
|
310
305
|
return null;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
missingChars.pop();
|
|
306
|
+
const stack = [];
|
|
307
|
+
let isInsideString = false;
|
|
308
|
+
let isEscaped = false;
|
|
309
|
+
for (let i = 0; i < jsonString.length; i++) {
|
|
310
|
+
const char = jsonString[i];
|
|
311
|
+
if (isEscaped) {
|
|
312
|
+
isEscaped = false;
|
|
313
|
+
continue;
|
|
320
314
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
315
|
+
if (char === "\\") {
|
|
316
|
+
isEscaped = true;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (char === '"') {
|
|
320
|
+
isInsideString = !isInsideString;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (!isInsideString) {
|
|
324
|
+
if (char === "{")
|
|
325
|
+
stack.push("}");
|
|
326
|
+
else if (char === "[")
|
|
327
|
+
stack.push("]");
|
|
328
|
+
else if (char === "}" || char === "]") {
|
|
329
|
+
if (stack.length > 0 && stack[stack.length - 1] === char) {
|
|
330
|
+
stack.pop();
|
|
331
|
+
}
|
|
325
332
|
}
|
|
326
333
|
}
|
|
327
334
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
335
|
+
let result = jsonString.trim();
|
|
336
|
+
// 1. 문자열이 열린 채로 끝났다면 따옴표 닫기
|
|
337
|
+
if (isInsideString) {
|
|
338
|
+
result += '"';
|
|
339
|
+
}
|
|
340
|
+
// 2. trailing comma 제거 (중요: ", ]" 또는 ", }" 방지)
|
|
341
|
+
result = result.replace(/,\s*$/, "");
|
|
342
|
+
// 3. 스택을 역순으로 닫기 전에, 속성 이름만 있고 값이 없는 경우 처리
|
|
343
|
+
// 예: "key": 문자로 끝난 경우
|
|
344
|
+
if (result.endsWith(":")) {
|
|
345
|
+
result += "null";
|
|
346
|
+
}
|
|
347
|
+
// 4. 남아있는 모든 괄호 닫기
|
|
348
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
349
|
+
const closingChar = stack[i];
|
|
350
|
+
// 배열 중간에서 끊겼을 때를 위한 보정 (예: [{}, { -> [{}, {}])
|
|
351
|
+
if (closingChar === "]" && result.endsWith(",")) {
|
|
352
|
+
result = result.slice(0, -1);
|
|
334
353
|
}
|
|
354
|
+
result += closingChar;
|
|
335
355
|
}
|
|
336
|
-
|
|
337
|
-
const completeString = string + missingCharsString;
|
|
338
|
-
const cleanedString = completeString
|
|
339
|
-
.replace(/"":/g, "")
|
|
340
|
-
.replace(/":}|": }/g, '": null }')
|
|
341
|
-
.replace(/,""}|,}|,\"\w+\"}/g, "}")
|
|
342
|
-
.replace(/},]/g, "}]");
|
|
343
|
-
return cleanedString;
|
|
356
|
+
return result;
|
|
344
357
|
}
|
|
345
358
|
}
|
|
346
359
|
export class AIMS {
|