code-point

Get a UTF-16-encoded code point number of a character


Keywords
code, point, code-point, string, char, character, unicode, utf16, utf-16, codepointat, surrogate, plane
License
MIT
Install
bower install code-point

Documentation

code-point

npm version Build Status [Coverage Status

Get a UTF-16-encoded code point number of a character

'A'.charCodeAt(0); //=> 65
codePoint('A'); //=> 65

'嶲'.charCodeAt(0); //=> 55422
codePoint('嶲'); //=> 195060

Installation

Use npm.

npm install code-point

API

import codePoint from 'code-point';

codePoint(character)

character: string
Return: number

If it takes a string as an argument, it returns the same result of character.codePointAt(0).

It throws an error if the argument is not a string or the string is empty.

codePoint('\udada'); //=> 56026
codePoint('\udada\udfdf'); //=> 814047

It works correctly even in ECMAScript <= 5 environments that don't support String.prototype.codePointAt.

Credit

This module includes the code of mathiasbynens / String.prototype.codePointAt. Thanks, Mathias Bynens.

Licenses

Author: Mathias Bynens

This polyfill is available under the MIT license.

code-point

Copyright (c) 2014 - 2018 Shinnosuke Watanabe

Licensed under the MIT License.