Socket
Socket
Sign inDemoInstall

utf8-bytes

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utf8-bytes - npm Package Compare versions

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(

2

package.json
{
"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));
}
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