UNPKG

@wordpress/components

Version:
29 lines (28 loc) • 943 B
import removeAccents from "remove-accents"; // packages/components/src/utils/strings.ts /** * All unicode characters that we consider "dash-like": * - `\u007e`: ~ (tilde) * - `\u00ad`: ­ (soft hyphen) * - `\u2053`: ⁓ (swung dash) * - `\u207b`: ⁻ (superscript minus) * - `\u208b`: ₋ (subscript minus) * - `\u2212`: − (minus sign) * - `\\p{Pd}`: any other Unicode dash character */ const ALL_UNICODE_DASH_CHARACTERS = /* @__PURE__ */ new RegExp(/[\u007e\u00ad\u2053\u207b\u208b\u2212\p{Pd}]/gu); const normalizeTextString = (value) => { return removeAccents(value).normalize("NFKC").toLocaleLowerCase().replace(ALL_UNICODE_DASH_CHARACTERS, "-"); }; /** * Escapes the RegExp special characters. * * @param string Input string. * * @return Regex-escaped string. */ function escapeRegExp(string) { return string.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&"); } export { escapeRegExp, normalizeTextString }; //# sourceMappingURL=strings.mjs.map