@uimkit/uikit-react
Version:
<img style="width:64px" src="https://mgmt.uimkit.chat/media/img/avatar.png"/>
33 lines (31 loc) • 1.11 kB
JavaScript
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&');
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt#getting_whole_characters
var getWholeChar = function (str, i) {
var code = str.charCodeAt(i);
if (Number.isNaN(code))
return '';
if (code < 0xd800 || code > 0xdfff)
return str.charAt(i);
if (0xd800 <= code && code <= 0xdbff) {
if (str.length <= i + 1) {
throw 'High surrogate without following low surrogate';
}
var next = str.charCodeAt(i + 1);
if (0xdc00 > next || next > 0xdfff) {
throw 'High surrogate without following low surrogate';
}
return str.charAt(i) + str.charAt(i + 1);
}
if (i === 0) {
throw 'Low surrogate without preceding high surrogate';
}
var prev = str.charCodeAt(i - 1);
if (0xd800 > prev || prev > 0xdbff) {
throw 'Low surrogate without preceding high surrogate';
}
return '';
};
export { escapeRegExp, getWholeChar };
//# sourceMappingURL=utils.js.map