代码拉取完成,页面将自动刷新
'use strict';
const singleComment = Symbol('singleComment');
const multiComment = Symbol('multiComment');
const stripWithoutWhitespace = () => '';
const stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/\S/g, ' ');
const isEscaped = (jsonString, quotePosition) => {
let index = quotePosition - 1;
let backslashCount = 0;
while (jsonString[index] === '\\') {
index -= 1;
backslashCount += 1;
}
return Boolean(backslashCount % 2);
};
module.exports = (jsonString, options = {}) => {
const strip = options.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace;
let insideString = false;
let insideComment = false;
let offset = 0;
let result = '';
for (let i = 0; i < jsonString.length; i++) {
const currentCharacter = jsonString[i];
const nextCharacter = jsonString[i + 1];
if (!insideComment && currentCharacter === '"') {
const escaped = isEscaped(jsonString, i);
if (!escaped) {
insideString = !insideString;
}
}
if (insideString) {
continue;
}
if (!insideComment && currentCharacter + nextCharacter === '//') {
result += jsonString.slice(offset, i);
offset = i;
insideComment = singleComment;
i++;
} else if (insideComment === singleComment && currentCharacter + nextCharacter === '\r\n') {
i++;
insideComment = false;
result += strip(jsonString, offset, i);
offset = i;
continue;
} else if (insideComment === singleComment && currentCharacter === '\n') {
insideComment = false;
result += strip(jsonString, offset, i);
offset = i;
} else if (!insideComment && currentCharacter + nextCharacter === '/*') {
result += jsonString.slice(offset, i);
offset = i;
insideComment = multiComment;
i++;
continue;
} else if (insideComment === multiComment && currentCharacter + nextCharacter === '*/') {
i++;
insideComment = false;
result += strip(jsonString, offset, i + 1);
offset = i + 1;
continue;
}
}
return result + (insideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。