A robust JavaScript implementation of a UTF-8 encoder/decoder, as defined by the Encoding Standard.
Installations
npm install utf8
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.9.0
NPM Version
5.5.1
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (87.35%)
Python (10.11%)
HTML (2.54%)
Developer
Download Statistics
Total Downloads
350,163,565
Last Day
263,917
Last Week
1,214,886
Last Month
5,652,352
Last Year
73,961,320
GitHub Statistics
557 Stars
28 Commits
115 Forks
25 Watching
2 Branches
3 Contributors
Bundle Size
1.65 kB
Minified
811.00 B
Minified + Gzipped
Package Meta Information
Latest Version
3.0.0
Package Id
utf8@3.0.0
Size
4.23 kB
NPM Version
5.5.1
Node Version
8.9.0
Publised On
04 Dec 2017
Total Downloads
Cumulative downloads
Total Downloads
350,163,565
Last day
-12.4%
263,917
Compared to previous day
Last week
-19.5%
1,214,886
Compared to previous week
Last month
11.8%
5,652,352
Compared to previous month
Last year
9.4%
73,961,320
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
utf8.js
utf8.js is a well-tested UTF-8 encoder/decoder written in JavaScript. Unlike many other JavaScript solutions, it is designed to be a proper UTF-8 encoder/decoder: it can encode/decode any scalar Unicode code point values, as per the Encoding Standard. Here’s an online demo.
Feel free to fork if you see possible improvements!
Installation
Via npm:
1npm install utf8
In a browser:
1<script src="utf8.js"></script>
In Node.js:
1const utf8 = require('utf8');
API
utf8.encode(string)
Encodes any given JavaScript string (string
) as UTF-8, and returns the UTF-8-encoded version of the string. It throws an error if the input string contains a non-scalar value, i.e. a lone surrogate. (If you need to be able to encode non-scalar values as well, use WTF-8 instead.)
1// U+00A9 COPYRIGHT SIGN; see http://codepoints.net/U+00A9 2utf8.encode('\xA9'); 3// → '\xC2\xA9' 4// U+10001 LINEAR B SYLLABLE B038 E; see http://codepoints.net/U+10001 5utf8.encode('\uD800\uDC01'); 6// → '\xF0\x90\x80\x81'
utf8.decode(byteString)
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 instead.)
1utf8.decode('\xC2\xA9'); 2// → '\xA9' 3 4utf8.decode('\xF0\x90\x80\x81'); 5// → '\uD800\uDC01' 6// → U+10001 LINEAR B SYLLABLE B038 E
utf8.version
A string representing the semantic version number.
Support
utf8.js has been tested in at least Chrome 27-39, Firefox 3-34, Safari 4-8, Opera 10-28, IE 6-11, Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.11, PhantomJS 1.9.0, and Rhino 1.7RC4.
Unit tests & code coverage
After cloning this repository, run npm install
to install the dependencies needed for development and testing. You may want to install Istanbul globally using npm install istanbul -g
.
Once that’s done, you can run the unit tests in Node using npm test
or node tests/tests.js
. To run the tests in Rhino, Ringo, Narwhal, PhantomJS, and web browsers as well, use grunt test
.
To generate the code coverage report, use grunt cover
.
FAQ
Why is the first release named v2.0.0? Haven’t you heard of semantic versioning?
Long before utf8.js was created, the utf8
module on npm was registered and used by another (slightly buggy) library. @ryanmcgrath was kind enough to give me access to the utf8
package on npm when I told him about utf8.js. Since there has already been a v1.0.0 release of the old library, and to avoid breaking backwards compatibility with projects that rely on the utf8
npm package, I decided the tag the first release of utf8.js as v2.0.0 and take it from there.
Author
Mathias Bynens |
License
utf8.js is available under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE-MIT.txt:0
- Info: FSF or OSI recognized license: MIT License: LICENSE-MIT.txt:0
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/28 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More