magister.js
Version:
A JavaScript implementation of the Magister 6 API
25 lines (20 loc) • 729 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.cleanHtmlContent = cleanHtmlContent;
var _lodash = _interopRequireDefault(require("lodash"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Strips HTML tags and entities from the given `str`
* If `str` is `undefined` or `null` an empty string will be returned.
*
* @param {string} [str]
* @returns {string}
*/
function cleanHtmlContent(str) {
if (str == null) {
return '';
}
return _lodash.default.unescape(str).replace(/<br\s*\/?>/g, '\n').replace(/<\/\s*p\s*>/g, '\n').replace(/ /g, ' ').replace(/(<[^>]*>)|(​)/g, '').replace(/\r?\n/g, '\n').trim();
}