JSString v0.1.2 JSString View Source

Documentation for ElixirJsString. There are differences between JavaScript string length and Elixir string length. JavaScript String.prototype.length sometimes doesn’t return the actual string length. For example, a length of some Emoji is sometimes more than 1.

Link to this section Summary

Link to this section Functions

Link to this function charcodes_to_string(charcodes) View Source
Link to this function string_to_charcodes(string) View Source

Examples

iex> JSString.string_to_charcodes("Beer")
'Beer'
iex> JSString.string_to_charcodes("ビール")
[12499, 12540, 12523]
iex> JSString.string_to_charcodes("🍺")
[55356, 57210]

iex> JSString.charcodes_to_string('Beer')
"Beer"
iex> JSString.charcodes_to_string([66, 101, 101, 114])
"Beer"
iex> JSString.charcodes_to_string([12499, 12540, 12523])
"ビール"
iex> JSString.charcodes_to_string([55356, 57210])
"🍺"

iex> JSString.js_length("Beer")
4
iex> JSString.js_length("🍺")
2