Skip to content

moveEllipsis

Homayoun edited this page Jul 9, 2026 · 1 revision

Introduced in v0.2.0

⚠️ Version Recommendation: Always install and use the latest version of rtl-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).

📝 Syntax

moveEllipsis(text: string): string

Parameters

Name Type Description
text string The text to fix ellipsis placement in.

Returns

  • 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.

💡 Examples

Basic Usage

import { moveEllipsis } from 'rtl-text-tools';

moveEllipsis("مرحبا...");    
// Output: "...مرحبا"

moveEllipsis("مرحبا…");     
// Output: "…مرحبا" (Supports Unicode ellipsis)

Edge Cases

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: "مرحبا"

⚙️ Technical Details & Compatibility

  • 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.

📜 Version History

  • 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() to moveEllipsis() for better naming conventions.
  • v0.1.0: Feature originally introduced as fixRTLDots() in the initial release.

🚀 rtl-text-tools

npm downloads

👨‍💻 Created by

Homayoun Mohammadi
🔗 GitHub • ✉️ Email

⭐ Love this project? Star it on GitHub to show your support!

Clone this wiki locally