Skip to content

Commit 158c9b1

Browse files
committed
Update README
1 parent 8ce9fd7 commit 158c9b1

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,21 @@ utf8.encode('\uD800\uDC01');
7373
// → '\xF0\x90\x80\x81'
7474
```
7575

76-
### `utf8.decode(byteString)`
76+
### `utf8.decode(byteString, options)`
7777

7878
Decodes any given UTF-8-encoded string (`byteString`) as UTF-8, and returns the UTF-8-decoded version of the string. It throws an error when malformed UTF-8 is detected. (If you need to be able to decode encoded non-scalar values as well, use [WTF-8](https://mths.be/wtf8) instead.)
7979

80+
You can use `allowTruncatedEnd` option to ignore last symbol if it was truncated on the end of input.
8081
```js
8182
utf8.decode('\xC2\xA9');
8283
// → '\xA9'
8384

8485
utf8.decode('\xF0\x90\x80\x81');
8586
// → '\uD800\uDC01'
8687
// → U+10001 LINEAR B SYLLABLE B038 E
88+
89+
utf8.decode('\xC2\xA9\xC2', { allowTruncatedEnd: true });
90+
// → '\xA9'
8791
```
8892

8993
### `utf8.version`

0 commit comments

Comments
 (0)