@sendbird/uikit-utils
Version:
A collection of utility functions and constants for building chat UI components with Sendbird UIKit.
44 lines • 1.14 kB
JavaScript
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);
};
export const isStartsWithRTL = str => {
return isRTLString('start', str);
};
export const isEndsWithRTL = str => {
return isRTLString('end', str);
};
const isRTLCodePoint = codePoint => {
for (const [start, end] of rtlCodePointRanges) {
if (codePoint >= start && codePoint <= end) {
return true;
}
}
return false;
};
const rtlCodePointRanges = [[0x0590, 0x05ff],
// Hebrew
[],
// Arabic
[],
// Arabic Supplement
[],
// Hebrew Supplement
[],
// Hebrew Presentation Forms
[],
// Arabic Presentation Forms-B
[] // Arabic Mathematical Alphabetic Symbols
];
//# sourceMappingURL=rtl.js.map