@protobufjs/utf8
Advanced tools
Comparing version 1.0.1 to 1.0.2
40
index.js
@@ -16,6 +16,5 @@ "use strict"; | ||
utf8.length = function length(string) { | ||
var strlen = string.length >>> 0; | ||
var len = 0, | ||
c = 0; | ||
for (var i = 0; i < strlen; ++i) { | ||
for (var i = 0; i < string.length; ++i) { | ||
c = string.charCodeAt(i); | ||
@@ -44,22 +43,21 @@ if (c < 128) | ||
var len = end - start; | ||
if (len > 0) { | ||
var string = [], | ||
i = 0, // char offset | ||
t; // temporary | ||
while (start < end) { | ||
t = buffer[start++]; | ||
if (t < 128) | ||
string[i++] = t; | ||
else if (t > 191 && t < 224) | ||
string[i++] = (t & 31) << 6 | buffer[start++] & 63; | ||
else if (t > 239 && t < 365) { | ||
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000; | ||
string[i++] = 0xD800 + (t >> 10); | ||
string[i++] = 0xDC00 + (t & 1023); | ||
} else | ||
string[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63; | ||
} | ||
return String.fromCharCode.apply(String, string.slice(0, i)); | ||
if (len < 1) | ||
return ""; | ||
var string = [], | ||
i = 0, // char offset | ||
t; // temporary | ||
while (start < end) { | ||
t = buffer[start++]; | ||
if (t < 128) | ||
string[i++] = t; | ||
else if (t > 191 && t < 224) | ||
string[i++] = (t & 31) << 6 | buffer[start++] & 63; | ||
else if (t > 239 && t < 365) { | ||
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000; | ||
string[i++] = 0xD800 + (t >> 10); | ||
string[i++] = 0xDC00 + (t & 1023); | ||
} else | ||
string[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63; | ||
} | ||
return ""; | ||
return String.fromCharCode.apply(String, string.slice(0, i)); | ||
}; | ||
@@ -66,0 +64,0 @@ |
{ | ||
"name": "@protobufjs/utf8", | ||
"description": "A minimal UTF8 implementation for number arrays.", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>", | ||
@@ -6,0 +6,0 @@ "repository": { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
15569
91