Skip to main content

Tiny ordinal↔cardinal converter in ~1KB (zero deps)

Project description

nano-ordinals

PyPI License Size CI

Tiny ordinal ↔ cardinal converter — ~1 KB, zero deps. 1 → 1st, 2 → 2nd, 11 → 11th, -3 → -3rd … and back. Perfect for code-golf, minimal containers, or just for fun.


✨ Features

  • ✅ Cardinal → ordinal (English suffix rules incl. 11/12/13 → th)
  • ✅ Ordinal → cardinal (case-insensitive: 21st, 101ST, 42nd)
  • ✅ Negative numbers supported (-3 → -3rd)
  • ✅ Zero dependencies, single tiny file; CLI included

🚀 Usage

# Local (from repo)
python app_min.py 1      # 1st
python app_min.py 11     # 11th
python app_min.py -3     # -3rd
python app_min.py 21st   # 21

After installing:

# CLI
pip install nano-ordinals
nano-ordinals 42      # -> 42nd
nano-ordinals 101     # -> 101st
nano-ordinals 101st   # -> 101

🤓 Why so small?

  • Minimal suffix rule: th unless endswith 1/2/3 and not 11/12/13
  • Tiny regex: ([+-]?\d+)(st|nd|rd|th)?
  • Single tiny file + tiny CLI: perfect for scripts, containers, CI.

🎉 Fun Ideas

  • Generate a calendar day label
date +%d | sed 's/^0//' | xargs nano-ordinals       # 1 -> 1st, 21 -> 21st
(Get-Date).Day | % { nano-ordinals $_ }              # 14 -> 14th
  • Ordinal list (1..20)
seq 1 20 | xargs -I{} nano-ordinals {}
1..20 | % { nano-ordinals $_ }
  • Rankings / leaderboards
for n in 1 2 3 4; do echo "Player $n: $(nano-ordinals $n) place"; done
# Player 1: 1st place, Player 2: 2nd place, ...
  • Git commit count → ordinal
nano-ordinals $(git rev-list --count HEAD)
# e.g., 42 -> 42nd commit
  • Rename files with ordinal indices
i=1; for f in *.png; do mv "$f" "$(nano-ordinals $i)-$f"; i=$((i+1)); done
# 1st-image.png, 2nd-image.png, ...
  • Sort plain ordinal tokens numerically
# lines like: 1st, 21st, 3rd...
awk '{print $0 "|" system("nano-ordinals "$0)}' ordinals.txt >/dev/null   # sanity check
paste <(cat ordinals.txt) <(sed 's/$//' ordinals.txt | xargs -n1 nano-ordinals) \
  | sort -k2,2n | cut -f1
  • Reverse conversion (ordinal → number)
for x in 21st 101st 42nd; do echo "$x -> $(nano-ordinals $x)"; done
# 21st -> 21, 101st -> 101, 42nd -> 42

**Tip: Input that contains letters is treated as ordinal → cardinal; digits-only is cardinal → ordinal.


📜 License

MIT © 2025

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nano_ordinals-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nano_ordinals-0.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file nano_ordinals-0.1.0.tar.gz.

File metadata

  • Download URL: nano_ordinals-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for nano_ordinals-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1333d4b968d392735a54b28c4dcfdf3f3b18c5a1690064be2719e79e0788a01d
MD5 e492e6ce5d333803d46fff7983a73480
BLAKE2b-256 43831839ec99d15bbd0f72ef4a9aba340c4322169e714c243f310b8b134d15e4

See more details on using hashes here.

File details

Details for the file nano_ordinals-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nano_ordinals-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for nano_ordinals-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 488db9d0e19e475716898478675d1cbefcfe5755ea9df6fd584c54b7fd047fec
MD5 6f110e3ebb44503b0739d9df73e089c5
BLAKE2b-256 79f846cc5f72affc49ac646d4dbb211e7f015a1010c2036e7daeef47fbd8a59b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page