Description
A port of ucwidth C library to Elixir, with Emoji (basis, variations and zwj-combined-sequences) supported.
Ucwidth alternatives and similar packages
Based on the "Third Party APIs" category.
Alternatively, view Ucwidth alternatives based on common mentions on social networks and blogs.
-
ethereumex
Elixir JSON-RPC client for the Ethereum blockchain 0x063D3d782598744AF1252eBEaf3aA97D990Edf72 -
MongoosePush
MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS. -
cashier
Cashier is an Elixir library that aims to be an easy to use payment gateway, whilst offering the fault tolerance and scalability benefits of being built on top of Erlang/OTP
CodeRabbit: AI Code Reviews for Developers
Do you think we are missing an alternative of Ucwidth or a related project?
README
Ucwidth
A port of ucwidth C library to Elixir, with Emoji (basis, variations and zwj-combined-sequences) supported.
Motivation
When developing a terminal based Elixir application, I found lack of some library handling character width correctly. Turns out there's a need to port ucwidth to Elixir. So I made this library.
I'm not professional at Unicode, just read the specifications and some references. So please report any issues you meet, thanks in advance.
Usage
This library provides a function Ucwidth.width/2
for detecting the display width of a Unicode character.
For example:
iex> Ucwidth.width("行")
2
iex> Ucwidth.width("h")
1
iex> Ucwidth.width("\x0C")
0
iex> Ucwidth.width("Hello, <<👪>>, family lovers!")
29
Note: according to Unicode standard, not every character has fixed width. There are some characters with variable width, which is called ambiguous width characters
. Their width vary depends on the context. This library by default treats ambiguous charaters as narrow ones, and also provides a way to pass be context, e.g:
iex> Ucwidth.width("\u00a1")
1
iex> Ucwidth.width("\u00a1", :wide)
2
Installation
Add ucwidth
to your list of dependencies in mix.exs
:
def deps do
[
{:ucwidth, "~> 0.2"}
]
end
Performance
Attention to performance was paid during development. You can check the performance by running:
mix run bench/benchmark.exs
License
This library is open-sourced under an MIT license.
*Note that all licence references and agreements mentioned in the Ucwidth README section above
are relevant to that project's source code only.