ExNumerlo (ExNumerlo v0.4.0)

Copy Markdown View Source

ExNumerlo provides a unified interface for rendering and parsing integers using over 50 different Unicode numeral systems.

It supports modern positional systems, historical additive and hybrid systems, and specialized mathematical representations.

Core Features

  • Unified API: Use convert/2 for encoding, decoding, and cross-system conversion.
  • Auto-Detection: Automatically identify the source numeral system when decoding strings.
  • Broad Support: Coverage for dozens of scripts including CJK, Indic, African, and historical systems.
  • Formatting: Support for custom separators (e.g., thousands separators) in positional systems.

Supported Systems

Modern Positional (Base-10)

:arabic, :arabic_indic, :extended_arabic_indic, :devanagari, :bengali, :gurmukhi, :gujarati, :oriya, :tamil, :sinhala, :telugu, :kannada, :malayalam, :thai, :lao, :tibetan, :burmese, :khmer, :mongolian, :adlam, :balinese, :chakma, :cham, :gunjala_gondi, :javanese, :kayah_li, :lepcha, :limbu, :masaram_gondi, :meetei_mayek, :modi, :mro, :n_ko, :new_tai_lue, :nyiakeng_puachue_hmong, :ol_chiki, :osmanya, :pahawh_hmong, :saurashtra, :sharada, :sora_sompeng, :sundanese, :tai_tham_hora, :tai_tham_tham, :takri, :tangsa, :tirhuta, :toto, :vai, :wancho, :warang_citi, :nag_mundari, :fullwidth

Historical and Specialized

  • Additive: :roman (1-3999), :aegean, :attic, :egyptian, :brahmi
  • Alphabetic (Letter) Numerals: :greek (1-9999), :armenian (1-9999), :hebrew (1-999), :cyrillic (1-9999)
  • Sign-Value and Accounting: :arabic_abjad, :tamil_traditional, :sinhala_archaic, :kharosthi, :rumi, :siyaq_indic, :siyaq_ottoman
  • Hybrid: :ethiopic, :han (Chinese/Japanese myriad-based)
  • Positional (Non-Base-10): :mayan (Base-20), :kaktovik (Base-20), :cuneiform (Base-60), :duodecimal (Base-12)
  • Programmer Bases: :binary (Base-2), :octal (Base-8), :hexadecimal (Base-16), :base32 (Base-32), :base36 (Base-36)
  • Specialized: :han_positional, :suzhou, :rod, :math_bold, :math_double_struck, :math_monospace, :math_sans, :math_sans_bold

Usage Examples

Encoding

ExNumerlo.convert(123, to: :devanagari)
# {:ok, "१२३"}

ExNumerlo.convert(2026, to: :roman)
# {:ok, "MMXXVI"}

Decoding with Auto-Detection

ExNumerlo.convert("१२३", to: :integer)
# {:ok, 123}

ExNumerlo.convert("MMXXVI", to: :integer)
# {:ok, 2026}

Formatting with Separators

ExNumerlo.convert(1234567, to: :arabic, separator: ",")
# {:ok, "1,234,567"}

ExNumerlo.convert("1,234,567", to: :integer, separator: ",")
# {:ok, 1234567}

Summary

Types

Supported numeral systems.

Functions

Converts an input (integer, list of integers, or encoded string) to another numeral system.

Returns metadata for all supported numeral systems.

Types

system()

@type system() ::
  :arabic
  | :arabic_indic
  | :extended_arabic_indic
  | :devanagari
  | :bengali
  | :gurmukhi
  | :gujarati
  | :oriya
  | :tamil
  | :telugu
  | :kannada
  | :malayalam
  | :sinhala
  | :thai
  | :lao
  | :tibetan
  | :burmese
  | :khmer
  | :mongolian
  | :limbu
  | :new_tai_lue
  | :tai_tham_hora
  | :tai_tham_tham
  | :balinese
  | :sundanese
  | :lepcha
  | :ol_chiki
  | :vai
  | :saurashtra
  | :kayah_li
  | :javanese
  | :cham
  | :meetei_mayek
  | :osmanya
  | :brahmi
  | :sora_sompeng
  | :chakma
  | :sharada
  | :tirhuta
  | :modi
  | :takri
  | :warang_citi
  | :gunjala_gondi
  | :masaram_gondi
  | :kaktovik
  | :mro
  | :tangsa
  | :pahawh_hmong
  | :nyiakeng_puachue_hmong
  | :wancho
  | :toto
  | :nag_mundari
  | :adlam
  | :n_ko
  | :han
  | :han_positional
  | :suzhou
  | :rod
  | :fullwidth
  | :math_monospace
  | :math_bold
  | :math_double_struck
  | :math_sans
  | :math_sans_bold
  | :roman
  | :aegean
  | :attic
  | :egyptian
  | :greek
  | :armenian
  | :hebrew
  | :cyrillic
  | :arabic_abjad
  | :tamil_traditional
  | :sinhala_archaic
  | :kharosthi
  | :rumi
  | :siyaq_indic
  | :siyaq_ottoman
  | :mayan
  | :ethiopic
  | :cuneiform
  | :duodecimal
  | :binary
  | :octal
  | :hexadecimal
  | :base32
  | :base36

Supported numeral systems.

Functions

convert(input, opts \\ [])

@spec convert(integer() | [integer()] | String.t(), keyword()) ::
  {:ok, String.t() | [String.t()] | integer()} | {:error, term()}

Converts an input (integer, list of integers, or encoded string) to another numeral system.

Options

  • :to - The target system (default: :arabic). Use :integer to decode to an Elixir integer.
  • :from - The source system (default: :auto). When set to :auto, the library will attempt to identify the system based on the characters present in the string.
  • :separator - A string to use as a digit group separator (e.g., , for thousands). Only supported for positional numeral systems.

Returns

  • {:ok, encoded_string} for single integer inputs.
  • {:ok, [encoded_strings]} for list inputs.
  • {:ok, integer} when to: :integer is used.
  • {:error, reason} if the input is invalid or the conversion is not supported.

Examples

iex> ExNumerlo.convert(123, to: :devanagari)
{:ok, "१२३"}

iex> ExNumerlo.convert(123, to: :thai)
{:ok, "๑๒๓"}

iex> ExNumerlo.convert(123, to: :roman)
{:ok, "CXXIII"}

iex> ExNumerlo.convert(120, to: :kaktovik)
{:ok, "𝋆𝋀"}

iex> ExNumerlo.convert("MMXXVI", to: :integer)
{:ok, 2026}

iex> ExNumerlo.convert("𝋆𝋀", to: :integer)
{:ok, 120}

iex> ExNumerlo.convert([1, 2], to: :roman)
{:ok, ["I", "II"]}

systems()

@spec systems() :: %{required(system()) => map()}

Returns metadata for all supported numeral systems.

Examples

iex> ExNumerlo.systems()[:roman][:range]
1..3999

iex> %{mayan: %{base: base}} = ExNumerlo.systems()
iex> base
20