# emojicharstring

> [![npm version](https://badge.fury.io/js/emojicharstring.svg)](https://badge.fury.io/js/emojicharstring) [![Build Status](https://travis-ci.org/YingshanDeng/EmojiCharString.svg?branch=master)](https://travis-ci.org/YingshanDeng/EmojiCharString) [![Coverag

Latest version **0.1.2** (published 2018-12-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install emojicharstring
pnpm add emojicharstring
yarn add emojicharstring
bun add emojicharstring
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2018-12-10 |
| First published | 2017-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | YingshanDeng |
| Maintainers | yingshandeng |
| Keywords | unicode, emoji, string, length, substr, substring, reverse |

## Links

- npm: https://www.npmjs.com/package/emojicharstring
- Repository: https://github.com/YingshanDeng/EmojiCharString
- Homepage: https://github.com/YingshanDeng/EmojiCharString#readme
- Issues: https://github.com/YingshanDeng/EmojiCharString/issues
- npm.io page: https://npm.io/package/emojicharstring

## 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

- 0.1.2 (latest) — 2018-12-10
- 0.1.1 — 2018-12-10
- 0.1.0 — 2017-07-17

## README

# EmojiCharString

[![npm version](https://badge.fury.io/js/emojicharstring.svg)](https://badge.fury.io/js/emojicharstring)
[![Build Status](https://travis-ci.org/YingshanDeng/EmojiCharString.svg?branch=master)](https://travis-ci.org/YingshanDeng/EmojiCharString)
[![Coverage Status](https://coveralls.io/repos/github/YingshanDeng/EmojiCharString/badge.svg?branch=master)](https://coveralls.io/github/YingshanDeng/EmojiCharString?branch=master)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

When the string contains emoji, we use `String.prototype.length` cannot get the characters count correctly! Such as:
- `'👦🏿'.length` return 4, it should be 1!
- `'👨‍👩‍👦'.length` return 8, it alse should be 1!

EmojiCharString is based on a RegExp to work with JavaScript String's unicode problem. It can solve the problem above.

❗️Note that it is not for good performance but for accuracy, because it uses a complex RegExp to analyze the string.

## Install
Using NPM, install EmojiCharString, and add it to your `package.json` dependencies.
```bash
npm install emojicharstring --save
```

And then you can import it
```javascript
// CommonJS
const EmojiCharString = require('EmojiCharString');

// or ES6
import EmojiCharString from 'EmojiCharString'
```

Or include the file in your HTML page using the following tags:
```javascript
<script src="/path/to/dist/EmojiCharString.min.js"></script>
```

## Usage

### initialise EmojiCharString
```javascript
var emojiStr = new EmojiCharString('👦🏿')
```

### `length`
Get the string's length correctly.
```javascript
var emojiStr = new EmojiCharString('👦🏿')
var len = emojiStr.length // 1
```

### `toString`
Get the string you pass in.
```javascript
var emojiStr = new EmojiCharString('hello')
var str = emojiStr.toString() // hello
```

### `reverse ()`
Reverse the string in place.
```javascript
var emojiStr = new EmojiCharString('👦🏿👨‍👩‍👦')
console.log(emojiStr.reverse()) // '👨‍👩‍👦👦🏿'
```

### `substring (begin = 0, end)`
The substring() method returns a subset of a string between begin index and end index

| Param | Type | Default | Description |
|---|---|---|---|
| begin | <code>Number</code> | *0* | begin index |
| end | <code>Number</code> | *none* | end index |

```javascript
var emojiStr = new EmojiCharString('👨‍👨‍👦 our family 我们一家 ❤️')
console.log(emojiStr.substring(2, 5)) // 'our'
```

### `substr (begin = 0, len)`
The substr() method return the characters in a string beginning at the specified location through the specified number of characters.

| Param | Type | Default | Description |
|---|---|---|---|
| begin | <code>Number</code> | *0* | Location at which to begin extracting characters |
| len | <code>Number</code> | *none* | The number of characters to extract |

```javascript
var emojiStr = new EmojiCharString('👨‍👨‍👦 our family 我们一家 ❤️')
console.log(emojiStr.substr(2, 5)) // 'our f'
```

## License
MIT

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