Skip to main content
Two complementary helpers for Persian ordinals — addOrdinalSuffix (cardinal → ordinal) and removeOrdinalSuffix (ordinal → cardinal). Both operate on already-Persian word forms; for numeric → words conversion, use Number to Words which can apply the ordinal automatically.

Functions

addOrdinalSuffix(number)

Rules (applied in order)

  1. Ends with ی → append اُم (leading space + standalone اُم).
  2. Ends with سه → strip last 2 chars, append سوم.
  3. Otherwise → append م.

Input

  • Must be a string. Anything else throws TypeError("PersianTools: addOrdinalSuffix - The input must be string").
  • "" does NOT throw — it falls through rule 3 and returns "م". Validate non-emptiness upstream if needed.

removeOrdinalSuffix(word)

Behaviour

  1. Falsy input is returned as-is (no throw, no "" coercion).
  2. Generic suffixes are removed: مین, ام, اُم.
  3. A table of irregular forms is applied (longest matches first) — e.g. سوم → سه, یازدهم → یازده, دوازدهم → دوازده.

Pitfalls

  • addOrdinalSuffix("") returns "م" (a single character), not "". Validate upstream.
  • addOrdinalSuffix(null) throws TypeError, doesn’t return "".
  • removeOrdinalSuffix(null) returns null unchanged (falsy input passes through).
  • اول is not handled by removeOrdinalSuffix — it returns "اول" unchanged (no built-in mapping to یک).
  • Rule coverage is conservative. addOrdinalSuffix("یک") returns "یک اُم" (rule 1: ends with ی), which is grammatical but uncommon; the colloquial "یکم" is not produced. Confirm against your style guide.

Composition with Number to Words

Source

src/modules/addOrdinalSuffix/addOrdinalSuffix.ts, src/modules/removeOrdinalSuffix/index.ts · Tests: test/addOrdinalSuffix.spec.ts, test/removeOrdinalSuffix.spec.ts