alisinabh

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

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

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?/1 which checks if all of a string is numerical chars.
  • remove_non_digits/2 which 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

Eiji

@alisinabh: Here are my ideas:

  1. Look at Naming Conventions: Trailing question mark (foo?)
  2. 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

Where Next?

Popular in Announcing Top

mspanc
I am pleased to announce an initial release of the Membrane Framework - an Elixir-based framework with special focus on processing multim...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
Crowdhailer
The latest release of Ace (0.10.0) includes serving content over HTTP/2. I have started writing a webserver to teach my self more about...
New
Eiji
ExApi is a library that I’m developing now and hope release soon This library will allow to: list all apis list all api implementation...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
Crowdhailer
Experimenting with this code. OK.try do user &lt;- fetch_user(1) cart &lt;- fetch_cart(1) order = checkout(cart, user) save_orde...
New
sbs
Only 650 LOC, wrote for fun :slight_smile: https://github.com/sunboshan/qrcode
New
aditya7iyengar
Rummage.Ecto and Rummage.Phoenix provide ways to perform Searching, Sorting and Pagination over Ecto queries and Phoenix collections. Fo...
New
hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement