code-points.js
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-pointsBower
bower i --save code-pointsDuo
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-pointsUsage
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 versionIt print the code points splitted by commas.
Example
code-points "0123 abcd"yields:
48,49,50,51,32,97,98,99,100License
Copyright (c) 2014 - 2015 Shinnosuke Watanabe
Licensed under the MIT License.