arabicfmt
Version:
Arabic-first formatting for numbers, currency, dates and bidirectional text across all 22 Arab League countries — with correct handling of the 2025–2026 Unicode currency-symbol transition (Saudi Riyal U+20C1, UAE Dirham U+20C3, Omani Rial U+20C4).
60 lines (56 loc) • 2.68 kB
TypeScript
import { D as Direction } from '../types-CK7PVYeU.js';
/** Strong direction of a single character/codepoint. */
declare function charDirection(ch: string): Direction;
/**
* Detect the base direction of `text` using the first-strong-character rule.
* Returns `"neutral"` when the string has no strong letters (e.g. only digits
* or punctuation).
*/
declare function detectDirection(text: string): Direction;
/** True when the first strong character of `text` is right-to-left. */
declare function isRTL(text: string): boolean;
/** Left-to-Right Isolate (U+2066). */
declare const LRI: string;
/** Right-to-Left Isolate (U+2067). */
declare const RLI: string;
/** First Strong Isolate (U+2068). */
declare const FSI: string;
/** Pop Directional Isolate (U+2069). */
declare const PDI: string;
/** Left-to-Right Mark (U+200E). */
declare const LRM: string;
/** Right-to-Left Mark (U+200F). */
declare const RLM: string;
/** Arabic Letter Mark (U+061C). */
declare const ALM: string;
/** Direction hint for {@link isolate}: pick the bracket, or let it auto-detect. */
type IsolateDirection = "auto" | "ltr" | "rtl";
/**
* Wrap `text` in a Unicode directional isolate so it composes safely inside
* surrounding text of either direction. Defaults to a First Strong Isolate
* (FSI), which adopts the text's own detected direction.
*/
declare function isolate(text: string, dir?: IsolateDirection): string;
/** Wrap `text` as a left-to-right isolate (LRI … PDI). */
declare function wrapLTR(text: string): string;
/** Wrap `text` as a right-to-left isolate (RLI … PDI). */
declare function wrapRTL(text: string): string;
/** Remove every Unicode bidi control character (marks, embeddings, isolates). */
declare function stripBidi(text: string): string;
interface IsolateForeignOptions {
/** Base direction of the surrounding text. Defaults to the detected base. */
base?: Direction;
/** Also isolate runs of Western digits (phone numbers, codes). Default true. */
numbers?: boolean;
}
/**
* Fix the "broken sentence" problem: wrap each run of opposite-direction content
* (English words, phone numbers, emails, URLs) embedded in `text` with an
* isolate, so it keeps its internal order without reordering the rest.
*
* @example
* isolateForeign("اتصل على +1 (555) 234-5678 الآن")
* // the phone number is wrapped in FSI … PDI and no longer flips the sentence
*/
declare function isolateForeign(text: string, options?: IsolateForeignOptions): string;
export { ALM, FSI, type IsolateDirection, type IsolateForeignOptions, LRI, LRM, PDI, RLI, RLM, charDirection, detectDirection, isRTL, isolate, isolateForeign, stripBidi, wrapLTR, wrapRTL };