# unicode-substring

> Unicode-aware substring

Latest version **1.0.0** (published 2017-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install unicode-substring
pnpm add unicode-substring
yarn add unicode-substring
bun add unicode-substring
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-07-11 |
| First published | 2015-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Ville Lautanala |
| Maintainers | lautis |
| Keywords | unicode, substring |

## Links

- npm: https://www.npmjs.com/package/unicode-substring
- Repository: https://github.com/lautis/unicode-substring
- Issues: https://github.com/lautis/unicode-substring/issues
- npm.io page: https://npm.io/package/unicode-substring

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-07-11
- 0.1.0 — 2015-01-28

## README

# unicode-substring [![Build Status](https://travis-ci.org/lautis/unicode-substring.svg?branch=master)](https://travis-ci.org/lautis/unicode-substring)

Unicode-aware substring for JavaScript. Surrogate pairs are counted as a single character.

## What?

Characters in JavaScript strings are exposed as 16-bit code points, also known as UCS-2 encoding. This usually good enough, but since there are more than 2^16 characters in Unicode, 16 bits is not enough to represent all characters. To overcome this limitation, characters with scalar value over `0x10FFFF` need to be encoded as surrogate pairs. This encoding is known as UTF-16.

The purpose of this library is to treat surrogate pairs as one character when extracting substrings from a string. This might be preferable if indices are returned from an Unicode-compatible environment.

## Usage

```javascript

var unicodeSubstring = require('unicode-substring')
// unicodeSubstring(string, start, end)
unicodeSubstring("💥Emoji Rule💥", 0, 6)
// => "💥Emoji"
```

The `start` and `end` parameters behave similarly as [String.prototype.substring](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/substring).

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