Comparing version 0.0.0 to 0.0.1
15
index.js
@@ -5,2 +5,17 @@ module.exports = function (str) { | ||
var c = str.charCodeAt(i); | ||
if (c >= 0xd800 && c <= 0xdbff && i + 1 < str.length) { | ||
var cn = str.charCodeAt(i + 1); | ||
if (cn >= 0xdc00 && cn <= 0xdfff) { | ||
var pt = (c - 0xd800) * 0x400 + cn - 0xdc00 + 0x10000; | ||
bytes.push( | ||
0xf0 + Math.floor(pt / 64 / 64 / 64), | ||
0x80 + Math.floor(pt / 64 / 64) % 64, | ||
0x80 + Math.floor(pt / 64) % 64, | ||
0x80 + pt % 64 | ||
); | ||
i += 1; | ||
continue; | ||
} | ||
} | ||
if (c >= 2048) { | ||
@@ -7,0 +22,0 @@ bytes.push( |
{ | ||
"name": "utf8-bytes", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "return an array of bytes from a unicode string", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,11 @@ var bytes = require('../'); | ||
test('some canned examples', function (t) { | ||
t.deepEqual(bytes('[☉,☼]'), Buffer('[☉,☼]').toJSON()); | ||
t.deepEqual(bytes('[☉,☼]'), bufArray('[☉,☼]')); | ||
t.deepEqual( | ||
bytes('\uD834\uDF06'), | ||
[ 240, 157, 140, 134 ] | ||
); | ||
t.deepEqual( | ||
bytes('\uD835\uDC01'), | ||
[ 240, 157, 144, 129 ] | ||
); | ||
t.end(); | ||
@@ -14,4 +22,8 @@ }); | ||
var s = String.fromCharCode(i); | ||
t.deepEqual(bytes(s), Buffer(s).toJSON()); | ||
t.deepEqual(bytes(s), bufArray(s)); | ||
} | ||
}); | ||
function bufArray (s) { | ||
return [].slice.call(Buffer(s)); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4217
58