New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

utf8

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utf8 - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

9

Gruntfile.js

@@ -11,3 +11,3 @@ module.exports = function(grunt) {

'generate-test-data': { // Only when needed
'command': 'if [ ! -f data.json ]; then echo python generate-test-data.py; fi',
'command': 'if [ ! -f data.json ]; then python generate-test-data.py; fi',
'options': {

@@ -19,5 +19,8 @@ 'execOptions': {

},
'cover': {
'cover-html': {
'command': 'istanbul cover --report "html" --verbose --dir "coverage" "tests/tests.js"; istanbul report --root "coverage" --format "html"'
},
'cover-coveralls': {
'command': 'istanbul cover --verbose --dir "coverage" "tests/tests.js" && cat coverage/lcov.info | coveralls; rm -rf coverage/lcov*'
},
'test-narwhal': {

@@ -54,3 +57,3 @@ 'command': 'echo "Testing in Narwhal..."; export NARWHAL_OPTIMIZATION=-1; narwhal "tests/tests.js"'

grunt.registerTask('cover', 'shell:cover');
grunt.registerTask('cover', 'shell:cover-html');
grunt.registerTask('ci', [

@@ -57,0 +60,0 @@ 'shell:generate-test-data',

@@ -1,2 +0,2 @@

Copyright Mathias Bynens <http://mathiasbynens.be/>
Copyright Mathias Bynens <https://mathiasbynens.be/>

@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining

{
"name": "utf8",
"version": "2.0.0",
"version": "2.1.0",
"description": "A well-tested UTF-8 encoder/decoder written in JavaScript.",
"homepage": "http://mths.be/utf8js",
"homepage": "https://mths.be/utf8js",
"main": "utf8.js",

@@ -13,15 +13,6 @@ "keywords": [

],
"licenses": [
{
"type": "MIT",
"url": "http://mths.be/mit"
},
{
"type": "GPL",
"url": "http://mths.be/gpl"
}
],
"license": "MIT",
"author": {
"name": "Mathias Bynens",
"url": "http://mathiasbynens.be/"
"url": "https://mathiasbynens.be/"
},

@@ -32,20 +23,15 @@ "repository": {

},
"bugs": {
"url": "https://github.com/mathiasbynens/utf8.js/issues"
},
"directories": {
"test": "tests"
},
"bugs": "https://github.com/mathiasbynens/utf8.js/issues",
"scripts": {
"test": "node tests/tests.js"
},
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-shell": "~0.2.2",
"istanbul": "~0.1.36",
"qunit-clib": "~1.3.0",
"coveralls": "^2.11.1",
"grunt": "^0.4.5",
"grunt-shell": "^1.1.1",
"istanbul": "^0.3.5",
"qunit-extras": "^1.4.0",
"qunitjs": "~1.11.0",
"requirejs": "~2.1.6"
"requirejs": "^2.1.11"
}
}

@@ -1,4 +0,4 @@

# utf8.js [![Build status](https://travis-ci.org/mathiasbynens/utf8.js.png?branch=master)](https://travis-ci.org/mathiasbynens/utf8.js) [![Dependency status](https://gemnasium.com/mathiasbynens/utf8.js.png)](https://gemnasium.com/mathiasbynens/utf8.js)
# utf8.js [![Build status](https://travis-ci.org/mathiasbynens/utf8.js.svg?branch=master)](https://travis-ci.org/mathiasbynens/utf8.js) [![Code coverage status](http://img.shields.io/coveralls/mathiasbynens/utf8.js/master.svg)](https://coveralls.io/r/mathiasbynens/utf8.js) [![Dependency status](https://gemnasium.com/mathiasbynens/utf8.js.svg)](https://gemnasium.com/mathiasbynens/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 given Unicode code point, including astral symbols and unpaired surrogates.
_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](https://encoding.spec.whatwg.org/#utf-8). [Here’s an online demo.](https://mothereff.in/utf-8)

@@ -9,3 +9,3 @@ Feel free to fork if you see possible improvements!

Via [npm](http://npmjs.org/):
Via [npm](https://www.npmjs.org/):

@@ -34,3 +34,3 @@ ```bash

In [Narwhal](http://narwhaljs.org/), [Node.js](http://nodejs.org/), and [RingoJS ≥ v0.8.0](http://ringojs.org/):
In [Narwhal](http://narwhaljs.org/), [Node.js](https://nodejs.org/), and [RingoJS ≥ v0.8.0](http://ringojs.org/):

@@ -67,3 +67,3 @@ ```js

Encodes any given JavaScript string (`string`) as UTF-8, and returns the UTF-8-encoded version of the 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](https://mths.be/wtf8) instead.)

@@ -81,3 +81,3 @@ ```js

Encodes 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.
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.)

@@ -99,3 +99,3 @@ ```js

utf8.js has been tested in at least Chrome 27-29, Firefox 3-22, Safari 4-6, Opera 10-12, IE 6-10, Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, and Rhino 1.7RC4.
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.

@@ -108,3 +108,3 @@ ## Unit tests & code coverage

To generate [the code coverage report](http://rawgithub.com/mathiasbynens/utf8.js/master/coverage/utf8.js/utf8.js.html), use `grunt cover`.
To generate the code coverage report, use `grunt cover`.

@@ -119,8 +119,8 @@ ## FAQ

| [![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](http://twitter.com/mathias "Follow @mathias on Twitter") |
| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
|---|
| [Mathias Bynens](http://mathiasbynens.be/) |
| [Mathias Bynens](https://mathiasbynens.be/) |
## License
utf8.js is dual licensed under the [MIT](http://mths.be/mit) and [GPL](http://mths.be/gpl) licenses.
utf8.js is available under the [MIT](https://mths.be/mit) license.

@@ -1,10 +0,11 @@

;(function(root) {
(function(root) {
'use strict';
/** Use a single `load` function */
var load = typeof require == 'function' ? require : root.load;
var noop = Function.prototype;
/** The unit testing framework */
var load = (typeof require == 'function' && !(root.define && define.amd)) ?
require :
(!root.document && root.java && root.load) || noop;
var QUnit = (function() {
var noop = Function.prototype;
return root.QUnit || (

@@ -14,3 +15,2 @@ root.addEventListener || (root.addEventListener = noop),

root.QUnit = load('../node_modules/qunitjs/qunit/qunit.js') || root.QUnit,
(load('../node_modules/qunit-clib/qunit-clib.js') || { 'runInContext': noop }).runInContext(root),
addEventListener === noop && delete root.addEventListener,

@@ -21,2 +21,7 @@ root.QUnit

var qe = load('../node_modules/qunit-extras/qunit-extras.js');
if (qe) {
qe.runInContext(root);
}
/** The `utf8` object to test */

@@ -101,3 +106,4 @@ var utf8 = root.utf8 || (root.utf8 = (

'decoded': '\uD800',
'encoded': '\xED\xA0\x80'
'encoded': '\xED\xA0\x80',
'error': true
},

@@ -107,3 +113,4 @@ {

'decoded': '\uD800\uD800',
'encoded': '\xED\xA0\x80\xED\xA0\x80'
'encoded': '\xED\xA0\x80\xED\xA0\x80',
'error': true
},

@@ -113,3 +120,4 @@ {

'decoded': '\uD800A',
'encoded': '\xED\xA0\x80A'
'encoded': '\xED\xA0\x80A',
'error': true
},

@@ -119,3 +127,4 @@ {

'decoded': '\uD800\uD834\uDF06\uD800',
'encoded': '\xED\xA0\x80\xF0\x9D\x8C\x86\xED\xA0\x80'
'encoded': '\xED\xA0\x80\xF0\x9D\x8C\x86\xED\xA0\x80',
'error': true
},

@@ -125,3 +134,4 @@ {

'decoded': '\uD9AF',
'encoded': '\xED\xA6\xAF'
'encoded': '\xED\xA6\xAF',
'error': true
},

@@ -131,3 +141,4 @@ {

'decoded': '\uDBFF',
'encoded': '\xED\xAF\xBF'
'encoded': '\xED\xAF\xBF',
'error': true
},

@@ -138,3 +149,4 @@ // low surrogates: 0xDC00 to 0xDFFF

'decoded': '\uDC00',
'encoded': '\xED\xB0\x80'
'encoded': '\xED\xB0\x80',
'error': true
},

@@ -144,3 +156,4 @@ {

'decoded': '\uDC00\uDC00',
'encoded': '\xED\xB0\x80\xED\xB0\x80'
'encoded': '\xED\xB0\x80\xED\xB0\x80',
'error': true
},

@@ -150,3 +163,4 @@ {

'decoded': '\uDC00A',
'encoded': '\xED\xB0\x80A'
'encoded': '\xED\xB0\x80A',
'error': true
},

@@ -156,3 +170,4 @@ {

'decoded': '\uDC00\uD834\uDF06\uDC00',
'encoded': '\xED\xB0\x80\xF0\x9D\x8C\x86\xED\xB0\x80'
'encoded': '\xED\xB0\x80\xF0\x9D\x8C\x86\xED\xB0\x80',
'error': true
},

@@ -162,3 +177,4 @@ {

'decoded': '\uDEEE',
'encoded': '\xED\xBB\xAE'
'encoded': '\xED\xBB\xAE',
'error': true
},

@@ -168,3 +184,4 @@ {

'decoded': '\uDFFF',
'encoded': '\xED\xBF\xBF'
'encoded': '\xED\xBF\xBF',
'error': true
},

@@ -205,12 +222,29 @@

;
equal(
object.encoded,
utf8.encode(object.decoded),
'Encoding: ' + description
);
equal(
object.decoded,
utf8.decode(object.encoded),
'Decoding: ' + description
);
if (object.error) {
raises(
function() {
utf8.decode(object.encoded);
},
Error,
'Error: non-scalar value detected'
);
raises(
function() {
utf8.encode(object.decoded);
},
Error,
'Error: non-scalar value detected'
);
} else {
equal(
object.encoded,
utf8.encode(object.decoded),
'Encoding: ' + description
);
equal(
object.decoded,
utf8.decode(object.encoded),
'Decoding: ' + description
);
}
});

@@ -217,0 +251,0 @@

@@ -1,2 +0,2 @@

/*! http://mths.be/utf8js v2.0.0 by @mathias */
/*! https://mths.be/utf8js v2.0.0 by @mathias */
;(function(root) {

@@ -22,3 +22,3 @@

// Taken from http://mths.be/punycode
// Taken from https://mths.be/punycode
function ucs2decode(string) {

@@ -50,3 +50,3 @@ var output = [];

// Taken from http://mths.be/punycode
// Taken from https://mths.be/punycode
function ucs2encode(array) {

@@ -69,2 +69,10 @@ var length = array.length;

function checkScalarValue(codePoint) {
if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
throw Error(
'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
' is not a scalar value'
);
}
}
/*--------------------------------------------------------------------------*/

@@ -85,2 +93,3 @@

else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
checkScalarValue(codePoint);
symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);

@@ -100,7 +109,2 @@ symbol += createByte(codePoint, 6);

var codePoints = ucs2decode(string);
// console.log(JSON.stringify(codePoints.map(function(x) {
// return 'U+' + x.toString(16).toUpperCase();
// })));
var length = codePoints.length;

@@ -176,2 +180,3 @@ var index = -1;

if (codePoint >= 0x0800) {
checkScalarValue(codePoint);
return codePoint;

@@ -178,0 +183,0 @@ } else {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc