@visulima/fs
Version:
Human friendly file system utilities for Node.js
24 lines (20 loc) • 854 B
JavaScript
;
const F_OK = require('./F_OK-CWSqQIdF.cjs');
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(F_OK.INTERNAL_STRIP_JSON_REGEX, (match) => {
if (match.startsWith('"') || match[1] === "*" && !match.endsWith("*/")) {
return match;
}
return whitespace ? match.replaceAll(/\S/g, " ") : "";
})
), "stripJsonComments");
module.exports = stripJsonComments;