@sendbird/uikit-utils
Version:
A collection of utility functions and constants for building chat UI components with Sendbird UIKit.
52 lines (51 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isStartsWithRTL = exports.isEndsWithRTL = void 0;
const isRTLString = (dir, str) => {
if (!str || str.length === 0) {
return false;
}
const trimmedStr = str.trimStart();
if (trimmedStr.length === 0) {
return false;
}
const char = dir === 'start' ? Array.from(trimmedStr)[0] : Array.from(trimmedStr).pop();
const point = char === null || char === void 0 ? void 0 : char.codePointAt(0);
if (point === undefined) {
return false;
}
return isRTLCodePoint(point);
};
const isStartsWithRTL = str => {
return isRTLString('start', str);
};
exports.isStartsWithRTL = isStartsWithRTL;
const isEndsWithRTL = str => {
return isRTLString('end', str);
};
exports.isEndsWithRTL = isEndsWithRTL;
const isRTLCodePoint = codePoint => {
for (const [start, end] of rtlCodePointRanges) {
if (codePoint >= start && codePoint <= end) {
return true;
}
}
return false;
};
const rtlCodePointRanges = [[0x0590, 0x05ff],
// Hebrew
[0x0600, 0x06ff],
// Arabic
[0x0750, 0x077f],
// Arabic Supplement
[0x08a0, 0x08ff],
// Hebrew Supplement
[0xfb1d, 0xfb4f],
// Hebrew Presentation Forms
[0xfe70, 0xfeff],
// Arabic Presentation Forms-B
[0x1ee00, 0x1eeff] // Arabic Mathematical Alphabetic Symbols
];
//# sourceMappingURL=rtl.js.map