# substr

> 将emoji表情或者字符串当一个字符处理，解决emoji等特殊字符在字符串裁剪出现乱码的问题，解决emoji字符截取不完整的问题。

Latest version **0.0.7** (published 2019-04-01) · ISC license · 0 weekly downloads

## Install

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

## 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.0.7 |
| Published | 2019-04-01 |
| First published | 2019-03-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jinzhan |
| Maintainers | jinzhan |

## Links

- npm: https://www.npmjs.com/package/substr
- Repository: https://github.com/jinzhan/substr
- Homepage: https://github.com/jinzhan/substr#readme
- Issues: https://github.com/jinzhan/substr/issues
- npm.io page: https://npm.io/package/substr

## Recent versions

- 0.0.7 (latest) — 2019-04-01
- 0.0.6 — 2019-04-01
- 0.0.5 — 2019-03-31
- 0.0.4 — 2019-03-29
- 0.0.3 — 2019-03-28
- 0.0.2 — 2019-03-28
- 0.0.1 — 2019-03-28

## README

# substr

将emoji表情或者字符串当一个字符处理，解决emoji等特殊字符在字符串裁剪出现乱码的问题，解决emoji字符截取不完整的问题。


## Installation

```
npm i substr -S
```

## Usage

```
import substr, {str2Array} from 'substr';
```



## methods

### substr(< String > str, < Number > start, [ Number ] end,[ Object ] option)
#### option参数

- options.hasEmoji: 是否包含emoji文本（如[微笑]）字符串，默认`false`
- options.emojiMaxLength: emoji字符串的最大长度，如果传了emojiData，则忽略该数值
- options.emojiData: emoji的数据，默认`[]`，不传的话会自动将`options.emojiMaxLength `长度以下的字符串当做emoji；

#### demo
- substr('👩‍👩‍👦family', 0, 1)  ==> 👩‍👩‍👦
- substr('[微笑]', 0, 1, {hasEmoji: true, emojiMaxLength: 4})  ==> [微笑]


### str2Array(< String > str, [ Object ] options)
- str2Array('👩‍👩‍👦abc') => ['👩‍👩‍👦', 'a', 'b', 'c'] 
- str2Array('百度[微笑]', 0, 1, {hasEmoji: true, emojiMaxLength: 4})  ==> ['百', '度', '[微笑]']

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