frontity
Version:
Frontity cli and entry point to other packages
24 lines (23 loc) • 967 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const he_1 = __importDefault(require("he"));
const simple_entity_decode_1 = __importDefault(require("simple-entity-decode"));
const containsHTMLEntities_1 = __importDefault(require("./containsHTMLEntities"));
const decode = (text) => {
// If we are free of HTML entities, just return the text
if (!containsHTMLEntities_1.default(text)) {
return text;
}
// simpleDecode only decodes the most common entities
// We check if it escaped all possible entities and if not,
// we fall back on full decoding
const decodedText = simple_entity_decode_1.default(text);
if (!containsHTMLEntities_1.default(decodedText)) {
return decodedText;
}
return he_1.default.decode(text);
};
exports.default = decode;