removeOrdinalSuffix
DevelopmentremoveOrdinalSuffix is an Agent Skill for development published in the persian-tools/persian-tools repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Strip Persian ordinal endings (مین, ام, اُم, م, plus irregular forms like سوم → سه, یازدهم → یازده) from a Persian word, leaving the cardinal form. Use when canonicalizing user-typed ordinals before lookup or comparison. Triggers on mentions of removeOrdinalSuffix, strip Persian ordinal, "سوم → سه", "یازدهم → یازده", canonical Persian number word.
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/persian-tools/persian-tools/blob/HEAD/skills/removeOrdinalSuffix/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/removeordinalsuffix, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
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