@visulima/fs
Version:
Human friendly file system utilities for Node.js
22 lines (19 loc) • 859 B
JavaScript
import { INTERNAL_STRIP_JSON_REGEX } from './F_OK-JER1LjUr.mjs';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const stripJsonComments = /* @__PURE__ */ __name((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, " ") : "";
})
), "stripJsonComments");
export { stripJsonComments as default };