JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3907
  • Score
    100M100P100Q139362F

Get the code points of each character in the string

Package Exports

  • code-points

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (code-points) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.