sitegen/package-lock.json
chloe caruso af60d1172f i accidentally deleted the repo, but recovered it. i'll start committing
it was weird. i pressed delete on a subfolder, i think one of the
pages.off folders that i was using. and then, suddenly, nvim on windows
7 decided to delete every file in the directory. they weren't shred off
the space time continuum, but just marked deleted. i had to pay $80 to
get access to a software that could see them. bleh!

just seeing all my work, a little over a week, was pretty heart
shattering. but i remembered that long ago, a close friend said i could
call them whenever i was feeling sad. i finally took them up on that
offer. the first time i've ever called someone for emotional support.
but it's ok. i got it back. and the site framework is better than ever.

i'm gonna commit and push more often. the repo is private anyways.
2025-06-06 23:38:02 -07:00

81 lines
2.8 KiB
JSON

// DEFAULT_OPTIONS
[object Object]
// strip
function strip(jsonString, options = DEFAULT_OPTIONS) {
if (typeof jsonString !== "string") {
throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``);
}
const { trailingCommas = false, whitespace = true } = options;
const _strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
let isInsideString = false;
let isInsideComment = false;
let offset = 0;
let buffer = "";
let result = "";
let commaIndex = -1;
for (let i = 0; i < jsonString.length; i++) {
const currentCharacter = jsonString[i];
const nextCharacter = jsonString[i + 1];
if (!currentCharacter) {
continue;
}
if (!isInsideComment && currentCharacter === '"') {
const escaped = isEscaped(jsonString, i);
if (!escaped) {
isInsideString = !isInsideString;
}
}
if (isInsideString) {
continue;
}
if (!isInsideComment && currentCharacter + nextCharacter === "//") {
buffer += jsonString.slice(offset, i);
offset = i;
isInsideComment = singleComment;
i++;
} else if (isInsideComment === singleComment && currentCharacter + nextCharacter === "\r\n") {
i++;
isInsideComment = false;
buffer += _strip(jsonString, offset, i);
offset = i;
continue;
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
isInsideComment = false;
buffer += _strip(jsonString, offset, i);
offset = i;
} else if (!isInsideComment && currentCharacter + nextCharacter === "/*") {
buffer += jsonString.slice(offset, i);
offset = i;
isInsideComment = multiComment;
i++;
continue;
} else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") {
i++;
isInsideComment = false;
buffer += _strip(jsonString, offset, i + 1);
offset = i + 1;
continue;
} else if (trailingCommas && !isInsideComment) {
if (commaIndex !== -1) {
if (currentCharacter === "}" || currentCharacter === "]") {
buffer += jsonString.slice(offset, i);
result += _strip(buffer, 0, 1) + buffer.slice(1);
buffer = "";
offset = i;
commaIndex = -1;
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
buffer += jsonString.slice(offset, i);
offset = i;
commaIndex = -1;
}
} else if (currentCharacter === ",") {
result += buffer + jsonString.slice(offset, i);
buffer = "";
offset = i;
commaIndex = i;
}
}
}
return result + buffer + (isInsideComment ? _strip(jsonString.slice(offset)) : jsonString.slice(offset));
}