-
Notifications
You must be signed in to change notification settings - Fork 0
moveEllipsis
⚠️ Version Recommendation: Always install and use the latest version ofrtl-text-tools(npm install rtl-text-tools@latest). While this specific feature was introduced in an earlier version, the latest release includes crucial bug fixes, better edge-case handling, and improved legacy browser compatibility. Avoid pinning your project to an old version just to use this function.
In RTL languages, truncation ellipsis traditionally appears at the visual start (the right side), which is the logical beginning of the string. This function automatically detects a trailing ellipsis and moves it to the front of the text to ensure proper visual rendering.
It supports both the standard three-dot sequence (...) and the single Unicode HORIZONTAL ELLIPSIS character (…, U+2026).
moveEllipsis(text: string): string| Name | Type | Description |
|---|---|---|
text |
string |
The text to fix ellipsis placement in. |
-
string: The text with the ellipsis moved to the front if it was at the end. - Returns the original string unchanged if it is empty, contains no RTL characters, or if the ellipsis is not at the very end of the string.
import { moveEllipsis } from 'rtl-text-tools';
moveEllipsis("مرحبا...");
// Output: "...مرحبا"
moveEllipsis("مرحبا…");
// Output: "…مرحبا" (Supports Unicode ellipsis)The function is smart enough to only move the ellipsis if it is at the very end of the string. If it's in the middle, or if there's no RTL text, it leaves the string untouched.
import { moveEllipsis } from 'rtl-text-tools';
// Ellipsis in the middle = unchanged
moveEllipsis("مرحبا...كيف");
// Output: "مرحبا...كيف"
// No RTL characters = unchanged
moveEllipsis("Hello...");
// Output: "Hello..."
// No ellipsis = unchanged
moveEllipsis("مرحبا");
// Output: "مرحبا"-
Dual Ellipsis Support: It checks for both the three-dot sequence (
...) and the single Unicode character…(U+2026). -
Smart Detection: Like other functions in the library, it runs a quick
hasRTL()check first. If no RTL characters are found, it immediately returns the original string, ensuring English/LTR text is never accidentally modified. -
IE11 Compatibility: The implementation relies on standard, legacy-safe string methods like
charAt(),slice(), and string concatenation. It completely avoids modern ES6+ features to ensure full compatibility with IE11 and older browsers. -
Safe Execution: If the input is falsy (e.g.,
null,undefined, or""), it immediately returns the input without throwing an error.
-
v1.0.0: Added support for the single Unicode HORIZONTAL ELLIPSIS character
…(U+2026) in addition to the three-dot sequence. -
v0.2.0: Renamed from
fixRTLDots()tomoveEllipsis()for better naming conventions. -
v0.1.0: Feature originally introduced as
fixRTLDots()in the initial release.
🏠 Home • 🚀 Getting Started • 📖 API Reference • 🐛 Report Issue
Made with ❤️ by Homayoun Mohammadi
If you find this project useful, please consider ⭐ starring the repo to show your support!
- 🏠 Home
- 🚀 Getting Started
- 🧩 API Overview
- 🛠️ Framework Guides
- 💡 Use Cases
- 🖥️ Browser Compatibility
- ❓ FAQ & Troubleshooting
Homayoun Mohammadi
🔗 GitHub • ✉️ Email
⭐ Love this project? Star it on GitHub to show your support!