16 lines
688 B
JavaScript
16 lines
688 B
JavaScript
const fs = require('fs');
|
|
const s = fs.readFileSync('methods/system.json', 'utf8');
|
|
function isEscaped(str, idx) { let cnt = 0; let j = idx - 1; while (j >= 0 && str[j] == '\\') { cnt++; j--; } return cnt % 2 === 1; }
|
|
const ph = s.indexOf('"headers"');
|
|
const posOpen = s.indexOf('[', ph);
|
|
let depth = 0; let inStr = false; let posClose = -1;
|
|
for (let i = posOpen; i < s.length; i++) {
|
|
const c = s[i];
|
|
if (c == '"' && !isEscaped(s, i)) inStr = !inStr;
|
|
if (inStr) continue;
|
|
if (c == '[') depth++;
|
|
else if (c == ']') { depth--; if (depth === 0) { posClose = i; break; } }
|
|
}
|
|
console.log('posOpen', posOpen, 'posClose', posClose);
|
|
console.log(s.slice(posClose - 40, posClose + 40));
|