Popularity
0.5
Stable
Activity
0.0
Stable
2
2
0

Description

A port of ucwidth C library to Elixir, with Emoji (basis, variations and zwj-combined-sequences) supported.

Monthly Downloads: 2,056
Programming language: Elixir
License: MIT License
Tags: Third Party APIs     Elixir     String     Unicode    

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.

Do you think we are missing an alternative of Ucwidth or a related project?

Add another 'Third Party APIs' Package

README

Ucwidth

A port of ucwidth C library to Elixir, with Emoji (basis, variations and zwj-combined-sequences) supported.

Online documentation

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.