qhwa
Ucwidth - A small library to detect the display width in columns for Unicode texts
Hi everyone!
I just published a small library, Ucwidth to help to detect the display width for any Unicode characters or texts. I think it might be useful if you’re working on something related to text typographing.
Links
Motivation
When developing a terminal-based Elixir application, I found a lack of some library handling character width correctly. Turns out there’s a need to port ucwidth (in C language) to Elixir.
So I made this porting with some additional features.
Key features
- sticking to the latest Unicode standard, and can be updated easily thanks to Elixir’s powerful metaprogramming ability
- Emoji support, even the combined ones
How to use?
Quite simple and straightforward:
iex> Ucwidth.width("👩🔬")
2
iex> Ucwidth.width("H")
1
iex> Ucwidth.width("你好, this is a lovely message 💌!")
34
Feedbacks
I’m not professional at Unicode, just read some specifications and references. Also, this is my first project heavily using metaprogramming (special thanks to the book Metaprogramming Elixir).
So in a word, any comment is welcome!
Popular in Libraries
Hello :wave:
Allow me to introduce you to Tz, an alternative time zone database support to Tzdata.
Why another library?
First and fore...
New
Dune is a sandbox for Elixir and aims to safely evaluate user-provided code.
You can try it out using this basic Elixir playground made ...
New
Hey there!
I wrote a download elixir package which does exactly what its name about - an easy way to download files.
I saw solutions ...
New
I’d like to announce a small library called boundaries.
This is an experimental project which explores the idea of enforcing boundaries ...
New
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
Hello all,
I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
I’ve just released the first version of Snap, an Elasticsearch client. It borrows ideas about application structure and process managemen...
New
Experimenting with this code.
OK.try do
user <- fetch_user(1)
cart <- fetch_cart(1)
order = checkout(cart, user)
save_or...
New
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM.
...
New
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
Other popular topics
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
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
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New








