Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/code-points.js
Get the code points of each character in the string
https://github.com/shinnn/code-points.js
Last synced: 26 days ago
JSON representation
Get the code points of each character in the string
- Host: GitHub
- URL: https://github.com/shinnn/code-points.js
- Owner: shinnn
- License: mit
- Created: 2014-10-15T03:18:13.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-04-05T07:38:40.000Z (over 5 years ago)
- Last Synced: 2024-10-11T22:28:10.720Z (about 1 month ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# code-points
[![npm version](https://img.shields.io/npm/v/code-points.svg)](https://www.npmjs.com/package/code-points)
[![Build Status](https://travis-ci.com/shinnn/code-points.js.svg?branch=master)](https://travis-ci.com/shinnn/code-points.js)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/code-points.js.svg)](https://coveralls.io/github/shinnn/code-points.js)Get the [UTF-16](https://wikipedia.org/wiki/UTF-16)-encoded code points of each character in the string
```javascript
codePoints('Hello, 世界\n'); //=> [72, 101, 108, 108, 111, 44, 32, 19990, 30028]
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install code-points
```## API
### codePoints(*str*, *option*)
*str*: `string`
*option*: `Object`
Return: `Array`It returns the [code point](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)s of each character in the string as an array.
```javascript
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.
```javascript
codePoints('banana'); //=> [98, 97, 110, 97, 110, 97]
codePoints('banana', {unique: true}); //=> [98,97,110]
```## License
Copyright (c) 2014 - 2019 [Shinnosuke Watanabe](https://github.com/shinnn)
Licensed under [the MIT License](https://github.com/shinnn/code-points/blob/master/LICENSE).