removeOrdinalSuffix — strip Persian ordinal suffix
import { removeOrdinalSuffix } from "@persian-tools/persian-tools";
// CommonJS
const { removeOrdinalSuffix } = require("@persian-tools/persian-tools");
Public export
removeOrdinalSuffix(word: string): string
What it does
- Falsy input is returned as-is (no throw, no
""coercion). - Generic suffixes are removed:
مین,ام,اُم(note the leading space for the standaloneاُمform). - A table of irregular ordinals is applied (longest matches first) — e.g.
سوم → سه,یکم → یک,یازدهم → یازده,دوازدهم → دوازده, etc. Seesrc/modules/removeOrdinalSuffix/index.tsfor the full list.
import { removeOrdinalSuffix } from "@persian-tools/persian-tools";
removeOrdinalSuffix("سوم"); // "سه"
removeOrdinalSuffix("یازدهم"); // "یازده"
removeOrdinalSuffix("بیستم"); // "بیست"
removeOrdinalSuffix("سیزدهمین"); // "سیزده"
removeOrdinalSuffix("سه هزارم"); // "سه هزار"
removeOrdinalSuffix("چهاردهمین"); // "چهارده"
Input rules
- Accepts
string. Does not throw onnull/undefined/""; they pass through unchanged. - Does not normalize Arabic-typed characters (
ي,ك). RunautoArabicToPersianupstream if input may originate from an Arabic keyboard, otherwise irregular-form matches will miss.
What it does NOT recognize
اول→یکis NOT a built-in mapping.removeOrdinalSuffix("اول")returns"اول"unchanged. The function only handles forms produced byaddOrdinalSuffixplus the suffix-addition pattern; older idiomatic ordinals likeاول/اولیare out of scope.- Latin-numeric ordinals like
"1st","3rd"are out of scope (return unchanged).
Common use case — canonicalising user input for lookup
import { removeOrdinalSuffix, wordsToNumber } from "@persian-tools/persian-tools";
const numericValue = (s: string) => wordsToNumber(removeOrdinalSuffix(s));
numericValue("سومین نفر"); // wordsToNumber("سه نفر") drops "نفر" silently → 3
numericValue("بیستم"); // wordsToNumber("بیست") → 20
References
- Tests:
test/removeOrdinalSuffix.spec.ts - Inverse:
addOrdinalSuffixskill