html-truncate-ts
Version:
TypeScript library for truncating HTML strings while preserving HTML tags and structure
16 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WORD_BREAK_REGEX = exports.IMAGE_TAG_REGEX = exports.URL_REGEX = exports.HTML_TAG_REGEX = exports.SELF_CLOSE_REGEX = exports.CLOSE_REGEX = exports.IS_CLOSE_REGEX = exports.KEY_VALUE_REGEX = exports.EXCLUDE_TAGS = exports.DEFAULT_TRUNCATE_SYMBOL = exports.EMPTY_STRING = exports.EMPTY_OBJECT = void 0;
exports.EMPTY_OBJECT = {};
exports.EMPTY_STRING = '';
exports.DEFAULT_TRUNCATE_SYMBOL = '...';
exports.EXCLUDE_TAGS = ['img', 'br'];
exports.KEY_VALUE_REGEX = '([\\w|-]+\\s*=\\s*"[^"]*"\\s*)*';
exports.IS_CLOSE_REGEX = '\\s*\\/?\\s*';
exports.CLOSE_REGEX = '\\s*\\/\\s*';
exports.SELF_CLOSE_REGEX = new RegExp('<\\/?\\w+\\s*' + exports.KEY_VALUE_REGEX + exports.CLOSE_REGEX + '>');
exports.HTML_TAG_REGEX = new RegExp('<\\/?\\w+\\s*' + exports.KEY_VALUE_REGEX + exports.IS_CLOSE_REGEX + '>');
exports.URL_REGEX = /(((ftp|https?):\/\/)[-\w@:%_+.~#?,&//=]+)|((mailto:)?[_.\w-]+@([\w][\w-]+\.)+[a-zA-Z]{2,3})/g;
exports.IMAGE_TAG_REGEX = new RegExp('<img\\s*' + exports.KEY_VALUE_REGEX + exports.IS_CLOSE_REGEX + '>');
exports.WORD_BREAK_REGEX = new RegExp('\\W+', 'g');
//# sourceMappingURL=truncate.const.js.map