https://github.com/alisinabh/numero
A micro library for converting non-english digits in elixir.
https://github.com/alisinabh/numero
arabic-digits digits english-digits
Last synced: 5 days ago
JSON representation
A micro library for converting non-english digits in elixir.
- Host: GitHub
- URL: https://github.com/alisinabh/numero
- Owner: alisinabh
- License: mit
- Created: 2017-05-31T21:46:17.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2025-03-21T14:57:43.000Z (25 days ago)
- Last Synced: 2025-04-04T12:56:20.721Z (11 days ago)
- Topics: arabic-digits, digits, english-digits
- Language: Elixir
- Homepage: https://hex.pm/packages/numero
- Size: 73.2 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - A micro library for converting non-english utf-8 digits in elixir. (Text and Numbers)
- fucking-awesome-elixir - numero - A micro library for converting non-english utf-8 digits in elixir. (Text and Numbers)
- awesome-elixir - numero - A micro library for converting non-english utf-8 digits in elixir. (Text and Numbers)
README
# Numero
[![Build Status][build-badge]](https://github.com/alisinabh/Numero)
[![Module Version][version-shield]](https://hex.pm/packages/numero)
[![Hex Docs][docs-badge]](https://hexdocs.pm/numero)Numero is a micro library for converting non-Western Arabic numerals, such as ۱
(Farsi), ۲ (Bengali), ۳ (Devanagari), ੪ (Gurmukhi), and ๕ (Thai), into Western
Arabic numerals (1, 2, 3, 4, and 5, respectively). It also provides conversion
into `integer()` and `float()` [basic types][bt].## Supported Languages / Scripts
All numbers defined in Unicode 16.0.0 as `Nd` (numeric digit) class are
supported. For more information, see the Unicode specification chapter 4,
[Character Properties][core-spec-4] sections on General Category and Numeric
Value.The conversion routine is derived from [DerivedNumericValues.txt][dnv].
## Installation
Numero can be installed by adding `numero` to your list of dependencies in
`mix.exs`:```elixir
def deps do
[{:numero, "~> 0.5.0"}]
end
```## Using Numero
On strings for strings:
```elixir
result = Numero.normalize("1۲۳۰4a۳tس")
# result = "12304a3tس"
```Smart numeric convert:
(Convert numbers to Integer or Float based on input string)
```elixir
result = Numero.normalize_as_number("1۲۳۰4۳")
# result = {:ok, 123043}result = Numero.normalize_as_number("1۲۳۰4۳.۴5")
# result = {:ok, 123043.45}result = Numero.normalize_as_number!("1۲۳۰4۳.۴5")
# result = 123043.45
```Strip all non numeric chars from a string:
```elixir
result = Numero.remove_non_digits("12 345abs")
# result = "12345"# Or even make exceptions for some chars like 'a' and ' ' (space)
result = Numero.remove_non_digits("12 345bas", ~c[a ])
# result = "12 345a"
```Checking if a string is all numbers
```elixir
result = Numero.digit_only?("1234567890")
# result = trueresult = Numero.digit_only?("1234567890.a")
# result = false
```[dnv]: https://www.unicode.org/Public/16.0.0/ucd/extracted/DerivedNumericValues.txt
[core-spec-4]: https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-4/
[bt]: https://hexdocs.pm/elixir/typespecs.html#basic-types
[build-badge]: https://github.com/alisinabh/Numero/actions/workflows/ci.yml/badge.svg
[repo]: https://github.com/alisinabh/Numero
[version-shield]: https://img.shields.io/hexpm/v/numero.svg
[hex]: https://hex.pm/packages/numero
[docs-badge]: https://img.shields.io/badge/hex-docs-lightgreen.svg
[hexdocs]: https://hexdocs.pm/numero/