Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 27 days ago
JSON representation

A micro library for converting non-english digits in elixir.

Awesome Lists containing this project

README

        

# Numero

[![Build Status](https://github.com/alisinabh/Numero/actions/workflows/ci.yml/badge.svg)](https://github.com/alisinabh/Numero)
[![Module Version](https://img.shields.io/hexpm/v/numero.svg)](https://hex.pm/packages/numero)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/numero/)

A micro library for converting non-english UTF8 digits. (like ۱=1, ۲=2)

## Supported languages

Almost all numbers defined in Unicode is supported in Numero.

For more info on supported characters you can visit [here](http://www.fileformat.info/info/unicode/category/Nd/list.htm)

## Installation

Numero can be installed
by adding `numero` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:numero, "~> 0.3.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 = true

result = Numero.digit_only?("1234567890.a")
# result = false
```

[https://hexdocs.pm/numero](https://hexdocs.pm/numero).