alisinabh
Numero - a micro library for converting non-english digits in Elixir
Hi everyone.
A few days ago i was developing a JSON API on phoenix which receives users phone number from client and starts sending messages to that phone number. There was a little problem in production however.
The problem was some people used Arabic or Persian keyboards to enter their phone number. And the phone number was not passed correctly into sending message API. So i’ve developed a micro library called Numero to tackle this problem in elixir.
Here is Numero: https://hex.pm/packages/numero
Currently it supports Persian, Arabic and NKO digits.
Most Liked
NobbZ
I’d not use that guarded version at all… Unicode has a lot of possible digits:
One doesn’t really have to iterate that list over and over again when using when char in @digits. Instead it should roughly like this:
@digits ~c[1234567890…] # include them all!
Enum.each(@digits, fn digit ->
defp do_digit_only?(<<unquote(digit)::utf8, rest::binary>>), do: do_digit_only?(rest)
end
defp dp_digit_only?(<<_::utf8, _::binary>>), do: false
defp do_digit_only?(""), do: true
alisinabh
Numero 0.2.0 is released.
Hi everyone. Numero 0.2.0 is released.
In this version i have added two new functions.
is_digit_only?/1which checks if all of a string is numerical chars.remove_non_digits/2which removes all non numerical chars form a given string with ability to have exceptions for some chars (optional).
I hope it will be useful for you guys.
Thanks.
Eiji
@alisinabh: Here are my ideas:
- Look at Naming Conventions: Trailing question mark (foo?)
- I think that some things could be written simpler
For example:
defmodule Example do
@digits String.graphemes("0123456789")
def digit_only?(""), do: false
def digit_only?(string), do: do_digit_only?(string)
defp do_digit_only?(""), do: true
defp do_digit_only?(<<char::binary-size(1), rest::binary>>) when char in @digits, do: do_digit_only?(rest)
defp do_digit_only?(_), do: false
end
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









