Giter VIP home page Giter VIP logo

elm-char-codepoint's Introduction

Code Point

Convert char to code point and code point to string, similar to javascript's String.codePointAt and String.fromCodePoint. Demo.

What's the difference between Char.toCode and Char.CodePoint.fromChar?

From MDN:

The charCodeAt() method returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index (the UTF-16 code unit matches the Unicode code point for code points representable in a single UTF-16 code unit, but might also be the first code unit of a surrogate pair for code points not representable in a single UTF-16 code unit, e.g. Unicode code points > 0x10000). If you want the entire code point value, use codePointAt().

This mean that not all chars exists in a single 16 bits representation, and Char.toCode only returns the first 16 bits code of any given char.

Here is an example to demonstrate how this can affect the output of Char.toCode and how Char.CodePoint.fromChar fix that:

Char.toCode '๐”ธ' == 55349
Char.fromCode 55349 == '๏ฟฝ'


Char.CodePoint.fromChar '๐”ธ' == 120120
Char.CodePoint.toString 120120 == "๐”ธ"

You can try different chars in this demo.

elm-char-codepoint's People

Contributors

pablohirafuji avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.