UNPKG

xxm-test-js

Version:
22 lines 703 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cssEscape = cssEscape; /** * 将字符串进行 CSS 转义 * @param {string | null | undefined} str - 要转义的字符串,可为 null 或 undefined * @returns {string} 转义后的字符串 * @example * ```js * cssEscape('div::after') // 返回 'div\:\:after' * cssEscape('Hello # World') // 返回 'Hello \000023 World' * ``` */ function cssEscape(str) { if (str === null || str === undefined) { return ''; } return str.replace(/[\s'"(){};:#&,.<>[\]/\\^$*+?|=~`!-]/g, (match) => { return '\\' + match.charCodeAt(0).toString(16); }); } //# sourceMappingURL=cssEscape.js.map