@coolgk/string
Version:
string utility functions
48 lines (46 loc) • 1.42 kB
JavaScript
/*!
* @package @coolgk/utils
* @version 3.1.4
* @link https://github.com/coolgk/node-utils
* @license MIT
* @author Daniel Gong <daniel.k.gong@gmail.com>
*
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved.
* Licensed under the MIT License.
*/
;
/*!
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
function stripTags(value = '') {
return (value + '').replace(/(<([^>]+)>)/ig, ' ').replace(/\s+/g, ' ').trim();
}
exports.stripTags = stripTags;
function escapeHtml(value = '') {
const mappings = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return value ? (value + '').replace(/[&<>"']/g, (matches) => (mappings[matches])) : '';
}
exports.escapeHtml = escapeHtml;
function unescapeHtml(value = '') {
const mappings = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'"
};
return value ? (value + '').replace(/&.+?;/g, (matches) => (mappings[matches] || matches)) : '';
}
exports.unescapeHtml = unescapeHtml;
function prepad0(value, length = 2) {
return (value + '').length > length ? value + '' : ('0'.repeat(length) + value).substr(-length);
}
exports.prepad0 = prepad0;