Skip to content
Get the code points of each character in the string
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist
src
.editorconfig
.gitattributes
.gitignore
.jshintrc
.travis.yml
LICENSE
README.md
appveyor.yml
bower.json
cli.js
gulpfile.js
package.json
test.js

README.md

code-points.js

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

Get the UTF-16-encoded code points of each character in the string

codePoints('Hello, 世界\n'); //=> [72, 101, 108, 108, 111, 44, 32, 19990, 30028]

Installation

Package managers

npm

npm i --save code-points

Bower

bower i --save code-points

Duo

var codePoints = require('shinnn/code-points.js');

Standalone

Download the script file directly and install its dependency.

Dependency

API

codePoints(str, option)

str: String
option: Object
Return: Array of Number

It returns the code points of each character in the string as an array.

See the document of String.prototype.codePointAt() for the details about code point.

codePoints('\udada'); //=> [56026]
codePoints('\udfdf\udada\udada'); //=> [57311, 56026, 56026]
codePoints('\udada\udfdf\udada'); //=> [814047, 56026]

option.unique

Type: Boolean
Default: false

Removes duplicates from result.

codePoints('banana'); //=> [98, 97, 110, 97, 110, 97]
codePoints('banana', {unique: true}); //=> [98,97,110]

CLI

You can use this module as a CLI tool by installing it globally.

npm install -g code-points

Usage

Usage1: code-points <string>
Usage2: code-points --file <file path>
Usage3: cat <file path> | code-points

Options:
--unique, --uniq, -u  Remove duplicates from result
--file,           -f  Use a file as an input
--help,           -h  Print usage information
--version,        -v  Print version

It print the code points splitted by commas.

Example

code-points "0123 abcd"

yields:

48,49,50,51,32,97,98,99,100

License

Copyright (c) 2014 - 2015 Shinnosuke Watanabe

Licensed under the MIT License.

Something went wrong with that request. Please try again.