Comparing version 1.3.5 to 1.4.0
17
index.js
@@ -12,3 +12,3 @@ | ||
function encode(obj) { | ||
function encode(obj, avoidSlice) { | ||
var buf | ||
@@ -83,3 +83,3 @@ , len | ||
buf = obj.reduce(function(acc, obj) { | ||
acc.append(encode(obj)) | ||
acc.append(encode(obj, true)) | ||
return acc | ||
@@ -137,3 +137,6 @@ }, bl().append(buf)) | ||
return buf | ||
if (avoidSlice) | ||
return buf | ||
else | ||
return buf.slice() | ||
} | ||
@@ -349,4 +352,4 @@ | ||
++length | ||
acc.push(encode(key)) | ||
acc.push(encode(obj[key])) | ||
acc.push(encode(key, true)) | ||
acc.push(encode(obj[key], true)) | ||
} | ||
@@ -505,2 +508,6 @@ } | ||
, decoder: streams.decoder | ||
// needed for levelup support | ||
, buffer: true | ||
, type: 'msgpack5' | ||
} | ||
@@ -507,0 +514,0 @@ } |
{ | ||
"name": "msgpack5", | ||
"version": "1.3.5", | ||
"description": "A msgpack v5 implementation for node.js, with extension points", | ||
"version": "1.4.0", | ||
"description": "A msgpack v5 implementation for node.js and the browser, with extension points", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test/* | faucet", | ||
"jshint": "jshint *.js test/*" | ||
"jshint": "jshint *.js test/*", | ||
"build": "npm run browserify && npm run dist", | ||
"browserify": "node_modules/.bin/browserify index.js -o dist/msgpack5.js -s msgpack5", | ||
"dist": "node_modules/.bin/uglifyjs dist/msgpack5.js -o dist/msgpack5.min.js", | ||
"test-browser": "browserify -r bl:inherits:readable-stream test/* | testling -u" | ||
}, | ||
@@ -33,11 +37,28 @@ "pre-commit": [ | ||
"devDependencies": { | ||
"bl": "^0.9.3", | ||
"browserify": "^6.3.3", | ||
"faucet": "0.0.1", | ||
"jshint": "^2.5.2", | ||
"level": "^0.18.0", | ||
"level-test": "^1.6.6", | ||
"pre-commit": "0.0.9", | ||
"tap": "^0.4.11", | ||
"tape": "^2.14.0" | ||
"tape": "^2.14.0", | ||
"testling": "^1.7.1", | ||
"uglify-js": "^2.4.15" | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"ie/6..latest", | ||
"chrome/22..latest", | ||
"firefox/16..latest", | ||
"safari/latest", | ||
"opera/11.0..latest", | ||
"iphone/6", | ||
"ipad/6", | ||
"android-browser/latest" | ||
] | ||
}, | ||
"dependencies": { | ||
"bl": "^0.9.0", | ||
"bl": "^0.9.3", | ||
"inherits": "^2.0.1", | ||
@@ -44,0 +65,0 @@ "readable-stream": "^1.0.27-1" |
msgpack5 [![Build Status](https://travis-ci.org/mcollina/msgpack5.png)](https://travis-ci.org/mcollina/msgpack5) | ||
======== | ||
A msgpack v5 implementation for node.js, with extension point support. | ||
A msgpack v5 implementation for node.js and the browser, with extension point support. | ||
@@ -13,2 +13,3 @@ Install | ||
Usage | ||
@@ -61,2 +62,24 @@ ----- | ||
In the Browser | ||
----------- | ||
This library is compatible with [Browserify](http://npm.im/browserify). | ||
If you want to use standalone, grab the file in the `dist` folder of | ||
this repo, and use in your own HTML page, the module will expose a | ||
`msgpack5` global. | ||
``` | ||
<script type="text/javascript" | ||
src="./msgpack5.min.js"> | ||
</script> | ||
``` | ||
### To build | ||
``` | ||
npm run build | ||
``` | ||
API | ||
@@ -157,2 +180,25 @@ --- | ||
LevelUp Support | ||
--------------- | ||
__msgpack5__ can be used as a LevelUp | ||
[`valueEncoding`](https://github.com/rvagg/node-levelup#leveluplocation-options-callback) straight away: | ||
```js | ||
var level = require('level') | ||
, pack = msgpack() | ||
, db = level('foo', { | ||
valueEncoding: pack | ||
}) | ||
, obj = { my: 'obj' } | ||
db.put('hello', obj, function(err) { | ||
db.get('hello', function(err, result) { | ||
console.log(result) | ||
db.close() | ||
}) | ||
}) | ||
``` | ||
Disclaimer | ||
@@ -159,0 +205,0 @@ ---------- |
@@ -18,13 +18,15 @@ | ||
test('encode/decode map with all files in this directory', function(t) { | ||
if (process.title !== "browser") { | ||
test('encode/decode map with all files in this directory', function(t) { | ||
var files = fs.readdirSync(__dirname) | ||
, map = files.reduce(function(acc, file) { | ||
acc[file] = fs.readFileSync(__dirname + '/' + file) | ||
return acc | ||
}, {}) | ||
, pack = msgpack() | ||
var files = fs.readdirSync(__dirname) | ||
, map = files.reduce(function(acc, file) { | ||
acc[file] = fs.readFileSync(__dirname + '/' + file) | ||
return acc | ||
}, {}) | ||
, pack = msgpack() | ||
t.deepEqual(pack.decode(pack.encode(map)), map) | ||
t.end() | ||
}) | ||
t.deepEqual(pack.decode(pack.encode(map)), map) | ||
t.end() | ||
}) | ||
} |
@@ -18,13 +18,15 @@ | ||
test('encode/decode map with all files in this directory', function(t) { | ||
if (process.title !== "browser") { | ||
test('encode/decode map with all files in this directory', function(t) { | ||
var files = fs.readdirSync(__dirname) | ||
, map = files.reduce(function(acc, file) { | ||
acc[file] = fs.readFileSync(__dirname + '/' + file).toString('utf8') | ||
return acc | ||
}, {}) | ||
, pack = msgpack() | ||
var files = fs.readdirSync(__dirname) | ||
, map = files.reduce(function(acc, file) { | ||
acc[file] = fs.readFileSync(__dirname + '/' + file).toString('utf8') | ||
return acc | ||
}, {}) | ||
, pack = msgpack() | ||
t.deepEqual(pack.decode(pack.encode(map)), map) | ||
t.end() | ||
}) | ||
t.deepEqual(pack.decode(pack.encode(map)), map) | ||
t.end() | ||
}) | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
384305
51
7494
220
10
1
10
1
Updatedbl@^0.9.3