OpenParable
Skip to content
← Back to skills

removeOrdinalSuffix

Development

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

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. 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

  1. Falsy input is returned as-is (no throw, no "" coercion).
  2. Generic suffixes are removed: مین, ام, اُم (note the leading space for the standalone اُم form).
  3. A table of irregular ordinals is applied (longest matches first) — e.g. سوم → سه, یکم → یک, یازدهم → یازده, دوازدهم → دوازده, etc. See src/modules/removeOrdinalSuffix/index.ts for the full list.
import { removeOrdinalSuffix } from "@persian-tools/persian-tools";

removeOrdinalSuffix("سوم");           // "سه"
removeOrdinalSuffix("یازدهم");        // "یازده"
removeOrdinalSuffix("بیستم");         // "بیست"
removeOrdinalSuffix("سیزدهمین");      // "سیزده"
removeOrdinalSuffix("سه هزارم");      // "سه هزار"
removeOrdinalSuffix("چهاردهمین");     // "چهارده"

Input rules

  • Accepts string. Does not throw on null/undefined/""; they pass through unchanged.
  • Does not normalize Arabic-typed characters (ي, ك). Run autoArabicToPersian upstream 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 by addOrdinalSuffix plus 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: addOrdinalSuffix skill