UNPKG

@darkgl/slow-json-stringify

Version:
24 lines 956 B
const _replaceString = (type) => (type.includes('string') ? '"__par__"' : '__par__'); const matchStartRe = /^(\"\,|\,|\")/; const _chunkRegex = /"\w+__sjs"/gm; const isLastRegex = /^("}|})/; const _makeChunks = (str, queue) => { return (str .replace(_chunkRegex, _replaceString) .split('__par__') .map((chunk, index, chunks) => { const matchProp = `("${queue[index]?.name}":(\"?))$`; const matchWhenLast = `(\,?)${matchProp}`; const isLast = isLastRegex.test(chunks[index + 1] || ''); const matchPropRe = new RegExp(isLast ? matchWhenLast : matchProp); return { flag: false, pure: chunk, prevUndef: chunk.replace(matchStartRe, ''), isUndef: chunk.replace(matchPropRe, ''), bothUndef: chunk.replace(matchStartRe, '').replace(matchPropRe, ''), }; })); }; export { _makeChunks }; //# sourceMappingURL=_makeChunks.js.map