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

jsonm

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonm - npm Package Compare versions

Comparing version 1.0.8-pre to 1.0.8

52

build/jsonm.js

@@ -46,2 +46,8 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jsonm = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

/**
* Reset the memoization dictionary, allowing consumption by
* new Unpacker instances.
*/
reset: reset,
/**
* Set the maximum dictionary size. Must match the dictionary size

@@ -156,2 +162,9 @@ * used by the unpacker.

}
function reset() {
dict = [];
dictMap = {};
dictIndex = MIN_DICT_INDEX;
sequenceId = -1;
}
};

@@ -163,3 +176,3 @@ },{}],3:[function(require,module,exports){

var OLD_MESSAGE = -1;
var OLD_MESSAGE = -99;
var TYPE_ARRAY = 0;

@@ -180,4 +193,6 @@ var TYPE_VALUE = 1;

* Unpack an packed object to its original input.
* (If this was a string, a string is returned.)
*
* In case you expect messages to be passed in out of order,
* please pass a callback function.
*
* @param {Object} packed

@@ -199,3 +214,3 @@ * @param {Function} [callback]

*/
unpackString: unpackString,
$unpackString: unpackString,

@@ -221,6 +236,20 @@ /**

function unpack(packed, callback) {
if (typeof packed === "string") return unpack(JSON.parse(packed));
if (!packed) return callback ? callback(null, packed) : packed;
function unpack(packed) {
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
if (callback) return unpackAsync(packed, true, callback);
var result = void 0;
unpackAsync(packed, false, function (err, _result) {
if (err) throw err;
result = _result;
});
return result;
}
function unpackAsync(packed, waitForSequence, callback) {
if (typeof packed === "string") return unpackAsync(JSON.parse(packed), waitForSequence, callback);
if (!packed) return callback(null, packed);
if (typeof packed[packed.length - 1] != "number") throw callback(new Error("Packed value expected"));
// Prepare input

@@ -231,3 +260,3 @@ var remoteSequenceId = packed.pop();

} else if (remoteSequenceId !== sequenceId + 1) {
if (callback && remoteSequenceId > sequenceId + 1) {
if (waitForSequence && remoteSequenceId > sequenceId + 1) {
// Try after receiving earlier messages

@@ -238,6 +267,3 @@ packed.push(remoteSequenceId);

var error = new Error("Message unpacked out of sequence");
error.code = "EOLD";
if (!callback) throw error;
return callback(error);
return callback(Object.assign(new Error("Message unpacked out of sequence or already unpacked"), { code: "EOLD" }));
}

@@ -251,3 +277,3 @@ sequenceId = remoteSequenceId;

// Return results
if (callback) callback(null, result);
callback(null, result);

@@ -261,4 +287,2 @@ if (pendingUnpacks.length) {

}
if (!callback) return result;
}

@@ -265,0 +289,0 @@

@@ -39,2 +39,8 @@ "use strict";

/**
* Reset the memoization dictionary, allowing consumption by
* new Unpacker instances.
*/
reset: reset,
/**
* Set the maximum dictionary size. Must match the dictionary size

@@ -149,2 +155,9 @@ * used by the unpacker.

}
function reset() {
dict = [];
dictMap = {};
dictIndex = MIN_DICT_INDEX;
sequenceId = -1;
}
};

@@ -5,3 +5,3 @@ "use strict";

var OLD_MESSAGE = -1;
var OLD_MESSAGE = -99;
var TYPE_ARRAY = 0;

@@ -22,4 +22,6 @@ var TYPE_VALUE = 1;

* Unpack an packed object to its original input.
* (If this was a string, a string is returned.)
*
* In case you expect messages to be passed in out of order,
* please pass a callback function.
*
* @param {Object} packed

@@ -41,3 +43,3 @@ * @param {Function} [callback]

*/
unpackString: unpackString,
$unpackString: unpackString,

@@ -63,6 +65,20 @@ /**

function unpack(packed, callback) {
if (typeof packed === "string") return unpack(JSON.parse(packed));
if (!packed) return callback ? callback(null, packed) : packed;
function unpack(packed) {
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
if (callback) return unpackAsync(packed, true, callback);
var result = void 0;
unpackAsync(packed, false, function (err, _result) {
if (err) throw err;
result = _result;
});
return result;
}
function unpackAsync(packed, waitForSequence, callback) {
if (typeof packed === "string") return unpackAsync(JSON.parse(packed), waitForSequence, callback);
if (!packed) return callback(null, packed);
if (typeof packed[packed.length - 1] != "number") throw callback(new Error("Packed value expected"));
// Prepare input

@@ -73,3 +89,3 @@ var remoteSequenceId = packed.pop();

} else if (remoteSequenceId !== sequenceId + 1) {
if (callback && remoteSequenceId > sequenceId + 1) {
if (waitForSequence && remoteSequenceId > sequenceId + 1) {
// Try after receiving earlier messages

@@ -80,6 +96,3 @@ packed.push(remoteSequenceId);

var error = new Error("Message unpacked out of sequence");
error.code = "EOLD";
if (!callback) throw error;
return callback(error);
return callback(Object.assign(new Error("Message unpacked out of sequence or already unpacked"), { code: "EOLD" }));
}

@@ -93,3 +106,3 @@ sequenceId = remoteSequenceId;

// Return results
if (callback) callback(null, result);
callback(null, result);

@@ -103,4 +116,2 @@ if (pendingUnpacks.length) {

}
if (!callback) return result;
}

@@ -107,0 +118,0 @@

@@ -40,2 +40,8 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.packer = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

/**
* Reset the memoization dictionary, allowing consumption by
* new Unpacker instances.
*/
reset: reset,
/**
* Set the maximum dictionary size. Must match the dictionary size

@@ -150,4 +156,11 @@ * used by the unpacker.

}
function reset() {
dict = [];
dictMap = {};
dictIndex = MIN_DICT_INDEX;
sequenceId = -1;
}
};
},{}]},{},[1])(1)
});

@@ -6,3 +6,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.unpacker = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

var OLD_MESSAGE = -1;
var OLD_MESSAGE = -99;
var TYPE_ARRAY = 0;

@@ -23,4 +23,6 @@ var TYPE_VALUE = 1;

* Unpack an packed object to its original input.
* (If this was a string, a string is returned.)
*
* In case you expect messages to be passed in out of order,
* please pass a callback function.
*
* @param {Object} packed

@@ -42,3 +44,3 @@ * @param {Function} [callback]

*/
unpackString: unpackString,
$unpackString: unpackString,

@@ -64,6 +66,20 @@ /**

function unpack(packed, callback) {
if (typeof packed === "string") return unpack(JSON.parse(packed));
if (!packed) return callback ? callback(null, packed) : packed;
function unpack(packed) {
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
if (callback) return unpackAsync(packed, true, callback);
var result = void 0;
unpackAsync(packed, false, function (err, _result) {
if (err) throw err;
result = _result;
});
return result;
}
function unpackAsync(packed, waitForSequence, callback) {
if (typeof packed === "string") return unpackAsync(JSON.parse(packed), waitForSequence, callback);
if (!packed) return callback(null, packed);
if (typeof packed[packed.length - 1] != "number") throw callback(new Error("Packed value expected"));
// Prepare input

@@ -74,3 +90,3 @@ var remoteSequenceId = packed.pop();

} else if (remoteSequenceId !== sequenceId + 1) {
if (callback && remoteSequenceId > sequenceId + 1) {
if (waitForSequence && remoteSequenceId > sequenceId + 1) {
// Try after receiving earlier messages

@@ -81,6 +97,3 @@ packed.push(remoteSequenceId);

var error = new Error("Message unpacked out of sequence");
error.code = "EOLD";
if (!callback) throw error;
return callback(error);
return callback(Object.assign(new Error("Message unpacked out of sequence or already unpacked"), { code: "EOLD" }));
}

@@ -94,3 +107,3 @@ sequenceId = remoteSequenceId;

// Return results
if (callback) callback(null, result);
callback(null, result);

@@ -104,4 +117,2 @@ if (pendingUnpacks.length) {

}
if (!callback) return result;
}

@@ -108,0 +119,0 @@

{
"name": "jsonm",
"version": "1.0.8-pre",
"version": "1.0.8",
"description": "json compressor for packing messages with memoization",

@@ -16,3 +16,3 @@ "main": "./build/node/index.js",

},
"author": "Lennart Kats <lennart add c9.io>",
"author": "Lennart Kats <postcards add lennart.cl>",
"license": "MIT",

@@ -19,0 +19,0 @@ "bugs": {

@@ -99,5 +99,12 @@ jsonm

Note that both the packer and unpacker maintain a stateful dictionary.
Don't lose them! But when the connection ends just start over with a new
packer and unpacker.
Don't lose them! When the connection ends, create a new packer or call
`packer.reset()`.
```
let packer = new jsonm.Packer();
packer.pack(message);
// ... disconnected!
packer.reset();
```
### Working with Strings

@@ -104,0 +111,0 @@

@@ -214,7 +214,7 @@ "use server";

const unpacked = unpacker.unpackString(packed);
const unpacked = unpacker.$unpackString(packed);
assert.deepEqual(unpacked, input);
});
it("has a symmetrical packString() and unpackString() for strings", () => {
it("has a symmetrical packString() and $unpackString() for strings", () => {
const input = "hello there\nthis is\r\na multi-line string";

@@ -224,3 +224,3 @@ const packed = packer.packString(input);

const unpacked = unpacker.unpackString(packed);
const unpacked = unpacker.$unpackString(packed);
assert.deepEqual(unpacked, input);

@@ -560,2 +560,25 @@ });

});
it("supports reset()", () => {
const input = { foo: "bar" };
unpacker.unpack(packer.pack(input));
const memoized = packer.pack(input);
assert.deepEqual(memoized, [3, 4, 1]);
packer.reset();
console.log(packer.$getDict());
const notMemoized = packer.pack(input);
const notMemoizedCopy = Object.assign([], notMemoized);
assert.equal(notMemoized[0], "foo");
assert.equal(notMemoized[1], "bar");
const unpacked1 = unpacker.unpack(notMemoized);
assert.deepEqual(unpacked1, input);
const unpacker2 = new jsonm.Unpacker();
const unpacked2 = unpacker2.unpack(notMemoizedCopy);
assert.deepEqual(unpacked2, input);
});
});
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