Skip to content
Get a UTF-16-encoded code point number of a character
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist improve error message
src
.editorconfig
.gitattributes
.gitignore
.jshintrc init
.travis.yml only test on the environment .codePointAt is available
LICENSES.md
README.md update readme
appveyor.yml only test on the environment .codePointAt is available
bower.json update package settings
gulpfile.js
package.json
test.js

README.md

code-point.js

NPM version Bower version Build Status Build status Coverage Status devDependency Status

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

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

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

Installation

Package managers

npm

npm install code-point

Bower

bower install code-point

Duo

var codePoint = require('shinnn/code-point.js');

Standalone

Download the script file directly.

API

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 even if the String object doesn't have codePointAt method as its prototype.

Credit

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

Licenses

String.prototype.codePointAt

Author: Mathias Bynens

This polyfill is available under the MIT license.

code-point.js

Copyright (c) 2014 - 2015 Shinnosuke Watanabe

Licensed under the MIT License.

Something went wrong with that request. Please try again.