@visulima/fs
Version:
Human friendly file system utilities for Node.js
20 lines (17 loc) • 684 B
JavaScript
import { INTERNAL_STRIP_JSON_REGEX } from './F_OK-BalxCn9n.js';
const stripJsonComments = (jsonString, { whitespace = true } = {}) => (
// This regular expression translates to:
//
// /quoted-string|line-comment|block-comment/g
//
// This means that comment characters inside of strings will match
// as strings, not comments, so we can just skip the whole string
// in the replacer function.
jsonString.replace(INTERNAL_STRIP_JSON_REGEX, (match) => {
if (match.startsWith('"') || match[1] === "*" && !match.endsWith("*/")) {
return match;
}
return whitespace ? match.replaceAll(/\S/g, " ") : "";
})
);
export { stripJsonComments as default };