# utf16-char-codes

> Get location of code point in a string or get code points from string

Latest version **2.1.0** (published 2020-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install utf16-char-codes
pnpm add utf16-char-codes
yarn add utf16-char-codes
bun add utf16-char-codes
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2020-08-31 |
| First published | 2019-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=0.10 |
| Dependencies | 1 |
| Unpacked size | 67.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Paul Moss |
| Maintainers | amourspirit |
| Keywords | code, codePoint, string, char, character, unicode, utf16, utf-16, polyfill, ponyfill, char, codePointAt, codePoints, codePointFullWidth, fromCodePoint, surrogate, plane |

## Links

- npm: https://www.npmjs.com/package/utf16-char-codes
- Repository: https://github.com/Amourspirit/node-utf16-char-codes
- Issues: https://github.com/Amourspirit/node-utf16-char-codes/issues
- npm.io page: https://npm.io/package/utf16-char-codes

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.11.2

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2020-08-31
- 2.0.0 — 2020-08-30
- 1.0.3 — 2020-08-02
- 1.0.2 — 2020-08-01
- 1.0.0 — 2019-04-14
- 0.1.6 — 2019-04-13
- 0.1.5 — 2019-04-12
- 0.1.4 — 2019-04-12
- 0.1.3 — 2019-04-12
- 0.1.2 — 2019-04-11
- 0.1.1 — 2019-04-11
- 0.1.0 — 2019-04-11

## README

<p align="center">
«-(¯`v´¯)-« <a href="https://www.npmjs.com/package/utf16-char-codes">【🇺​🇹​🇫​►🇨​🇭​🇦​🇷​ 🇨​🇴​🇩​🇪​🇸​​】</a> »-(¯`v´¯)-»
<br /><a href="https://en.wikipedia.org/wiki/UTF-16">utf-16-code-points</a> string encode and decode
</p>
<p align="center">
<a href="https://travis-ci.org/Amourspirit/node-utf16-char-codes"><img src="https://travis-ci.org/Amourspirit/node-utf16-char-codes.svg?branch=master" /></a>
<a href="https://snyk.io/test/github/Amourspirit/node-utf16-char-codes?targetFile=package.json"><img src="https://snyk.io/test/github/Amourspirit/node-utf16-char-codes/badge.svg?targetFile=package.json" /></a> <img src="https://img.shields.io/github/package-json/v/Amourspirit/node-utf16-char-codes.svg" />
<img src="https://img.shields.io/github/license/Amourspirit/node-utf16-char-codes.svg" /><a href="http://github.com/badges/stability-badges"> <img src="http://badges.github.io/stability-badges/dist/stable.svg" /></a>
</p>

# utf16-char-codes

## Code Point methods

### codePoints(str[, opts])

Gets the code points for a string.  
Returns a number array of integers matching the code points of *str*.

```ts
import { codePoints } from 'utf16-char-codes';

let p = codePoints('Hello World!');   // [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]
p = codePoints('Hello World!', true); // [72, 101, 108, 111, 32, 87, 114, 100, 33]
p = codePoints('0𧌠嶲0𧏨');             // [48, 160544, 195060, 48, 160744]
```

```text
@param str The input string to get the code points for.

@param opts (optional) Options, if boolean is passed in it will
       determine if the method returns unique code points.
       If true only code points that are unique will be returned in the array.
```

### codePointFullWidth(codePoint)

Test if a unicode code point is a full width character.  
Returns **true** if codePoint is a full width character; otherwise, **false**

```ts
import { codePointFullWidth } from 'utf16-char-codes';

const fullWidth = 'ＦＵＬＬＷＩＤＴＨ ＴＥＸＴ';
let p = Number(fullWidth.codePointAt(3));
console.log(codePointFullWidth(p)); // true
console.log(codePointFullWidth(Number(('고').codePointAt(0)))); // true
console.log(codePointFullWidth(Number(('A').codePointAt(0)))); // false
console.log(codePointFullWidth(Infinity)); // false
```

```text
@param codePoint The code point to test
```

### codePointAt([pos])

Method returns a non-negative integer that is the Unicode code point value.  
This method was introduced to ECMAScript 2015 (6th Edition, ECMA-262) and is included here for older versions of ECMAScripts.

```js
('ABC').codePointAt(1);           // 66
('\uD800\uDC00').codePointAt(0);  // 65536
('XYZ').codePointAt(42);          // undefined
```

```text
@param pos (optional) Position of an element in the String to
       return the code point value from.
       Default value 0
```

Ref: [String​.prototype​.char​CodeAt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)

### fromCodePoint()

Method returns a string created by using the specified sequence of code points.  
This method was introduced to ECMAScript 2015 (6th Edition, ECMA-262) and is included for older versions of ECMAScripts.

```js
String.fromCodePoint(42);       // "*"
String.fromCodePoint(65, 90);   // "AZ"
String.fromCodePoint(0x404);    // "\u0404"
String.fromCodePoint(0x2F804);  // "\uD87E\uDC04"
String.fromCodePoint(194564);   // "\uD87E\uDC04"
String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07"
```

Ref: [String​.from​Code​Point()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)

### Extensions

This module also will add **String.prototype.codePointAt** and **String.fromCodePoint** methods if they do not exist. This usefull for using this module with versions of ECMAScript pre 2015 (es6).

Use *somestring.codePointAt()* on any version of ECMAScript

```js
('ABC').codePointAt(1);           // 66
('\uD800\uDC00').codePointAt(0);  // 65536
('XYZ').codePointAt(42);          // undefined
```

Use *String.fromCodePoint()* on any version of ECMAScript

```js
String.fromCodePoint(42);       // "*"
String.fromCodePoint(65, 90);   // "AZ"
String.fromCodePoint(0x404);    // "\u0404"
String.fromCodePoint(0x2F804);  // "\uD87E\uDC04"
String.fromCodePoint(194564);   // "\uD87E\uDC04"
String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07"
```

---
_Source: https://npm.io/package/utf16-char-codes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
