Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsan

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsan - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

14

lib/cycle.js

@@ -6,3 +6,3 @@ var pathGetter = require('./path-getter');

exports.decycle = function decycle(object, options) {
exports.decycle = function decycle(object, options, replacer) {
'use strict';

@@ -13,3 +13,3 @@

return (function derez(value, path) {
return (function derez(_value, path, key) {

@@ -25,2 +25,4 @@ // The derez recurses through the object, producing the deep copy.

var value = replacer ? replacer(key || '', _value) : _value;
if (options.date && value instanceof Date) {

@@ -42,2 +44,6 @@ return {$jsan: 'd' + value.getTime()};

if (value && value.toJSON) {
return value.toJSON();
}
if (typeof value === 'object' && value !== null &&

@@ -71,3 +77,3 @@ !(value instanceof Boolean) &&

for (i = 0; i < value.length; i += 1) {
nu[i] = derez(value[i], path + '[' + i + ']');
nu[i] = derez(value[i], path + '[' + i + ']', i);
}

@@ -84,3 +90,3 @@ } else {

'[' + JSON.stringify(name) + ']';
nu[name] = name === '$jsan' ? [derez(value[name], path + nextPath)] : derez(value[name], path + nextPath);
nu[name] = name === '$jsan' ? [derez(value[name], path + nextPath)] : derez(value[name], path + nextPath, name);
}

@@ -87,0 +93,0 @@ }

@@ -26,3 +26,3 @@ var cycle = require('./cycle');

var decycled = cycle.decycle(value, options || {});
var decycled = cycle.decycle(value, options, replacer);
if (arguments.length === 1) {

@@ -29,0 +29,0 @@ return JSON.stringify(decycled);

{
"name": "jsan",
"version": "3.1.0",
"version": "3.1.1",
"description": "handle circular references when stringifying and parsing",

@@ -17,2 +17,3 @@ "main": "index.js",

"circular-json": "^0.3.0",
"immutable": "^3.7.6",
"json-stringify-safe": "^5.0.1",

@@ -19,0 +20,0 @@ "mocha": "^2.2.1",

global at 1000 iterations
jsan took 1244
CircularJSON took 1066
json-stringify-safe took 1673
jsan took 1261
CircularJSON took 1097
json-stringify-safe took 1707
decycledGlobal at 1000 iterations
jsan took 132
CircularJSON took 527
json-stringify-safe took 1077
jsan took 119
CircularJSON took 502
json-stringify-safe took 1098
empty object at 1000000 iterations
jsan took 354
CircularJSON took 480
json-stringify-safe took 660
jsan took 332
CircularJSON took 476
json-stringify-safe took 624
empty array at 1000000 iterations
jsan took 351
CircularJSON took 324
json-stringify-safe took 435
jsan took 341
CircularJSON took 323
json-stringify-safe took 464
small object at 100000 iterations
jsan took 49
CircularJSON took 148
json-stringify-safe took 457
jsan took 54
CircularJSON took 159
json-stringify-safe took 510
self referencing small object at 100000 iterations
jsan took 50
CircularJSON took 151
json-stringify-safe took 472
jsan took 52
CircularJSON took 152
json-stringify-safe took 499
small array at 100000 iterations
jsan took 49
CircularJSON took 129
json-stringify-safe took 502
jsan took 43
CircularJSON took 128
json-stringify-safe took 494
self referencing small array at 100000 iterations
jsan took 43
jsan took 47
CircularJSON took 130
json-stringify-safe took 501
json-stringify-safe took 502
string at 1000000 iterations
jsan took 266
CircularJSON took 291
json-stringify-safe took 420
jsan took 265
CircularJSON took 293
json-stringify-safe took 415
number at 1000000 iterations
jsan took 219
CircularJSON took 193
json-stringify-safe took 318
jsan took 226
CircularJSON took 186
json-stringify-safe took 331
null at 1000000 iterations
jsan took 219
CircularJSON took 191
json-stringify-safe took 340
jsan took 207
CircularJSON took 208
json-stringify-safe took 338
global at 1000 iterations
jsan took 1205
CircularJSON took 1029
json-stringify-safe took 1654
jsan took 1287
CircularJSON took 1049
json-stringify-safe took 1640
decycledGlobal at 1000 iterations
jsan took 116
CircularJSON took 497
json-stringify-safe took 1073
jsan took 129
CircularJSON took 510
json-stringify-safe took 1061
empty object at 1000000 iterations
jsan took 339
CircularJSON took 501
json-stringify-safe took 654
CircularJSON took 486
json-stringify-safe took 652
empty array at 1000000 iterations
jsan took 347
CircularJSON took 299
json-stringify-safe took 464
jsan took 352
CircularJSON took 320
json-stringify-safe took 441
small object at 100000 iterations
jsan took 54
CircularJSON took 160
json-stringify-safe took 450
jsan took 50
CircularJSON took 148
json-stringify-safe took 492
self referencing small object at 100000 iterations
jsan took 44
CircularJSON took 158
json-stringify-safe took 473
jsan took 50
CircularJSON took 152
json-stringify-safe took 492
small array at 100000 iterations
jsan took 47
CircularJSON took 128
json-stringify-safe took 537
jsan took 42
CircularJSON took 129
json-stringify-safe took 528
self referencing small array at 100000 iterations
jsan took 54
CircularJSON took 156
json-stringify-safe took 528
jsan took 45
CircularJSON took 127
json-stringify-safe took 512
string at 1000000 iterations
jsan took 269
CircularJSON took 288
json-stringify-safe took 422
jsan took 278
CircularJSON took 290
json-stringify-safe took 415
number at 1000000 iterations
jsan took 238
CircularJSON took 208
json-stringify-safe took 338
jsan took 227
CircularJSON took 201
json-stringify-safe took 312
null at 1000000 iterations
jsan took 236
CircularJSON took 208
json-stringify-safe took 330
jsan took 203
CircularJSON took 200
json-stringify-safe took 328
global at 1000 iterations
jsan took 1272
CircularJSON took 1052
json-stringify-safe took 1696
jsan took 1257
CircularJSON took 1078
json-stringify-safe took 1705
decycledGlobal at 1000 iterations
jsan took 125
CircularJSON took 494
json-stringify-safe took 1168
jsan took 123
CircularJSON took 510
json-stringify-safe took 1099
empty object at 1000000 iterations
jsan took 337
CircularJSON took 494
json-stringify-safe took 654
jsan took 341
CircularJSON took 481
json-stringify-safe took 643
empty array at 1000000 iterations
jsan took 338
CircularJSON took 323
json-stringify-safe took 468
jsan took 346
CircularJSON took 311
json-stringify-safe took 435
small object at 100000 iterations
jsan took 49
CircularJSON took 155
json-stringify-safe took 526
CircularJSON took 151
json-stringify-safe took 491
self referencing small object at 100000 iterations
jsan took 46
CircularJSON took 159
json-stringify-safe took 543
jsan took 47
CircularJSON took 153
json-stringify-safe took 506
small array at 100000 iterations
jsan took 50
CircularJSON took 129
json-stringify-safe took 552
jsan took 43
CircularJSON took 131
json-stringify-safe took 531
self referencing small array at 100000 iterations
jsan took 50
CircularJSON took 139
json-stringify-safe took 568
jsan took 49
CircularJSON took 125
json-stringify-safe took 519
string at 1000000 iterations
jsan took 271
CircularJSON took 297
json-stringify-safe took 409
jsan took 266
CircularJSON took 287
json-stringify-safe took 425
number at 1000000 iterations
jsan took 233
CircularJSON took 213
json-stringify-safe took 362
jsan took 214
CircularJSON took 187
json-stringify-safe took 316
null at 1000000 iterations
jsan took 221
CircularJSON took 215
json-stringify-safe took 361
jsan took 216
CircularJSON took 195
json-stringify-safe took 328
global at 1000 iterations
jsan took 1242
CircularJSON took 1056
json-stringify-safe took 1725
jsan took 1364
CircularJSON took 1035
json-stringify-safe took 1658
decycledGlobal at 1000 iterations
jsan took 121
CircularJSON took 526
json-stringify-safe took 1106
jsan took 119
CircularJSON took 515
json-stringify-safe took 1081
empty object at 1000000 iterations
jsan took 362
CircularJSON took 499
json-stringify-safe took 651
jsan took 340
CircularJSON took 488
json-stringify-safe took 635
empty array at 1000000 iterations
jsan took 376
CircularJSON took 335
jsan took 333
CircularJSON took 321
json-stringify-safe took 449
small object at 100000 iterations
jsan took 55
CircularJSON took 158
json-stringify-safe took 509
jsan took 48
CircularJSON took 157
json-stringify-safe took 456
self referencing small object at 100000 iterations
jsan took 50
CircularJSON took 162
json-stringify-safe took 501
jsan took 45
CircularJSON took 161
json-stringify-safe took 474
small array at 100000 iterations
jsan took 48
CircularJSON took 136
json-stringify-safe took 532
jsan took 44
CircularJSON took 126
json-stringify-safe took 493
self referencing small array at 100000 iterations
jsan took 49
CircularJSON took 133
json-stringify-safe took 531
jsan took 43
CircularJSON took 127
json-stringify-safe took 497
string at 1000000 iterations
jsan took 286
CircularJSON took 289
json-stringify-safe took 452
jsan took 270
CircularJSON took 295
json-stringify-safe took 412
number at 1000000 iterations
jsan took 232
CircularJSON took 216
json-stringify-safe took 340
jsan took 220
CircularJSON took 197
json-stringify-safe took 321
null at 1000000 iterations
jsan took 211
CircularJSON took 205
json-stringify-safe took 349
jsan took 208
CircularJSON took 187
json-stringify-safe took 317
global at 1000 iterations
jsan took 1286
CircularJSON took 1054
json-stringify-safe took 1838
jsan took 1255
CircularJSON took 1050
json-stringify-safe took 1746
decycledGlobal at 1000 iterations
jsan took 126
CircularJSON took 543
json-stringify-safe took 1211
jsan took 114
CircularJSON took 500
json-stringify-safe took 1175
empty object at 1000000 iterations
jsan took 356
CircularJSON took 505
json-stringify-safe took 678
jsan took 326
CircularJSON took 473
json-stringify-safe took 658
empty array at 1000000 iterations
jsan took 368
CircularJSON took 355
json-stringify-safe took 488
jsan took 349
CircularJSON took 305
json-stringify-safe took 438
small object at 100000 iterations
jsan took 46
CircularJSON took 166
json-stringify-safe took 520
CircularJSON took 155
json-stringify-safe took 516
self referencing small object at 100000 iterations
jsan took 47
CircularJSON took 162
json-stringify-safe took 528
CircularJSON took 151
json-stringify-safe took 537
small array at 100000 iterations
jsan took 51
CircularJSON took 142
json-stringify-safe took 562
jsan took 45
CircularJSON took 124
json-stringify-safe took 554
self referencing small array at 100000 iterations
jsan took 44
CircularJSON took 142
json-stringify-safe took 596
jsan took 45
CircularJSON took 139
json-stringify-safe took 600
string at 1000000 iterations
jsan took 277
CircularJSON took 289
json-stringify-safe took 412
jsan took 275
CircularJSON took 294
json-stringify-safe took 449
number at 1000000 iterations
jsan took 210
CircularJSON took 204
json-stringify-safe took 341
jsan took 231
CircularJSON took 211
json-stringify-safe took 347
null at 1000000 iterations
jsan took 212
CircularJSON took 207
json-stringify-safe took 331
jsan took 207
CircularJSON took 193
json-stringify-safe took 324
global at 1000 iterations
jsan took 1295
CircularJSON took 1113
json-stringify-safe took 1876
jsan took 1315
CircularJSON took 1102
json-stringify-safe took 1834
decycledGlobal at 1000 iterations
jsan took 125
CircularJSON took 590
jsan took 124
CircularJSON took 522
json-stringify-safe took 1162
empty object at 1000000 iterations
jsan took 335
CircularJSON took 559
json-stringify-safe took 791
jsan took 360
CircularJSON took 474
json-stringify-safe took 629
empty array at 1000000 iterations
jsan took 343
CircularJSON took 306
json-stringify-safe took 433
jsan took 366
CircularJSON took 315
json-stringify-safe took 451
small object at 100000 iterations
jsan took 51
CircularJSON took 211
json-stringify-safe took 532
jsan took 50
CircularJSON took 148
json-stringify-safe took 494
self referencing small object at 100000 iterations
jsan took 46
CircularJSON took 202
json-stringify-safe took 546
jsan took 49
CircularJSON took 161
json-stringify-safe took 487
small array at 100000 iterations
jsan took 45
CircularJSON took 133
json-stringify-safe took 522
jsan took 49
CircularJSON took 132
json-stringify-safe took 506
self referencing small array at 100000 iterations
jsan took 47
CircularJSON took 133
json-stringify-safe took 545
jsan took 44
CircularJSON took 129
json-stringify-safe took 510
string at 1000000 iterations
jsan took 295
CircularJSON took 304
json-stringify-safe took 445
jsan took 277
CircularJSON took 297
json-stringify-safe took 438
number at 1000000 iterations
jsan took 217
CircularJSON took 212
json-stringify-safe took 341
jsan took 242
CircularJSON took 206
json-stringify-safe took 333
null at 1000000 iterations
jsan took 222
CircularJSON took 209
jsan took 221
CircularJSON took 202
json-stringify-safe took 344
global at 1000 iterations
jsan took 1287
CircularJSON took 1144
json-stringify-safe took 1786
jsan took 1291
CircularJSON took 1038
json-stringify-safe took 1678
decycledGlobal at 1000 iterations
jsan took 126
CircularJSON took 545
json-stringify-safe took 1128
jsan took 128
CircularJSON took 493
json-stringify-safe took 1105
empty object at 1000000 iterations
jsan took 333
CircularJSON took 483
json-stringify-safe took 691
jsan took 367
CircularJSON took 475
json-stringify-safe took 647
empty array at 1000000 iterations
jsan took 362
CircularJSON took 335
json-stringify-safe took 479
jsan took 382
CircularJSON took 326
json-stringify-safe took 473
small object at 100000 iterations
jsan took 49
CircularJSON took 162
json-stringify-safe took 520
jsan took 55
CircularJSON took 159
json-stringify-safe took 474
self referencing small object at 100000 iterations
jsan took 47
CircularJSON took 168
json-stringify-safe took 511
jsan took 51
CircularJSON took 158
json-stringify-safe took 483
small array at 100000 iterations
jsan took 50
CircularJSON took 136
json-stringify-safe took 512
jsan took 54
CircularJSON took 137
json-stringify-safe took 511
self referencing small array at 100000 iterations
jsan took 44
CircularJSON took 141
json-stringify-safe took 512
jsan took 55
CircularJSON took 127
json-stringify-safe took 514
string at 1000000 iterations
jsan took 257
CircularJSON took 294
json-stringify-safe took 423
jsan took 314
CircularJSON took 284
json-stringify-safe took 407
number at 1000000 iterations
jsan took 226
CircularJSON took 194
json-stringify-safe took 332
jsan took 253
CircularJSON took 193
json-stringify-safe took 325
null at 1000000 iterations
jsan took 207
jsan took 243
CircularJSON took 196
json-stringify-safe took 336
json-stringify-safe took 321
global at 1000 iterations
jsan took 1204
CircularJSON took 1038
json-stringify-safe took 1670
jsan took 1260
CircularJSON took 1090
json-stringify-safe took 1749
decycledGlobal at 1000 iterations
jsan took 114
CircularJSON took 510
json-stringify-safe took 1049
jsan took 113
CircularJSON took 518
json-stringify-safe took 1125
empty object at 1000000 iterations
jsan took 345
CircularJSON took 484
json-stringify-safe took 638
jsan took 357
CircularJSON took 534
json-stringify-safe took 706
empty array at 1000000 iterations
jsan took 347
CircularJSON took 320
json-stringify-safe took 437
jsan took 362
CircularJSON took 370
json-stringify-safe took 507
small object at 100000 iterations
jsan took 49
CircularJSON took 149
json-stringify-safe took 480
CircularJSON took 168
json-stringify-safe took 498
self referencing small object at 100000 iterations
jsan took 50
CircularJSON took 161
json-stringify-safe took 481
CircularJSON took 170
json-stringify-safe took 519
small array at 100000 iterations
jsan took 43
CircularJSON took 122
json-stringify-safe took 510
jsan took 55
CircularJSON took 136
json-stringify-safe took 540
self referencing small array at 100000 iterations
jsan took 46
CircularJSON took 124
json-stringify-safe took 505
jsan took 66
CircularJSON took 150
json-stringify-safe took 514
string at 1000000 iterations
jsan took 272
CircularJSON took 297
json-stringify-safe took 417
jsan took 258
CircularJSON took 293
json-stringify-safe took 415
number at 1000000 iterations
jsan took 215
CircularJSON took 198
json-stringify-safe took 317
jsan took 219
CircularJSON took 192
json-stringify-safe took 316
null at 1000000 iterations
jsan took 213
CircularJSON took 189
json-stringify-safe took 328
jsan took 203
CircularJSON took 205
json-stringify-safe took 329
global at 1000 iterations
jsan took 1227
CircularJSON took 1066
json-stringify-safe took 1663
jsan took 1270
CircularJSON took 1040
json-stringify-safe took 1662
decycledGlobal at 1000 iterations
jsan took 124
CircularJSON took 495
json-stringify-safe took 1067
jsan took 115
CircularJSON took 485
json-stringify-safe took 1063
empty object at 1000000 iterations
jsan took 340
CircularJSON took 481
json-stringify-safe took 649
jsan took 339
CircularJSON took 467
json-stringify-safe took 628
empty array at 1000000 iterations
jsan took 337
CircularJSON took 314
json-stringify-safe took 460
jsan took 348
CircularJSON took 315
json-stringify-safe took 475
small object at 100000 iterations
jsan took 45
CircularJSON took 149
json-stringify-safe took 475
jsan took 50
CircularJSON took 150
json-stringify-safe took 503
self referencing small object at 100000 iterations
jsan took 47
CircularJSON took 165
json-stringify-safe took 464
jsan took 51
CircularJSON took 151
json-stringify-safe took 481
small array at 100000 iterations
jsan took 44
CircularJSON took 121
json-stringify-safe took 519
jsan took 43
CircularJSON took 134
json-stringify-safe took 505
self referencing small array at 100000 iterations
jsan took 43
CircularJSON took 123
json-stringify-safe took 511
jsan took 54
CircularJSON took 129
json-stringify-safe took 505
string at 1000000 iterations
jsan took 278
CircularJSON took 279
json-stringify-safe took 416
jsan took 270
CircularJSON took 298
json-stringify-safe took 437
number at 1000000 iterations
jsan took 221
CircularJSON took 190
json-stringify-safe took 327
jsan took 233
CircularJSON took 198
json-stringify-safe took 326
null at 1000000 iterations
jsan took 221
CircularJSON took 201
json-stringify-safe took 322
jsan took 206
CircularJSON took 198
json-stringify-safe took 318
var assert = require('assert');
var jsan = require('../');
var immutable = require('immutable');

@@ -93,3 +94,36 @@ describe('jsan', function() {

it("doesn't blow up on immutable.js", function() {
var obj = {
i: immutable.Map({
someList: immutable.List(),
someMap: immutable.Map({
foo: function() {},
bar: 123
})
})
};
assert.deepEqual(JSON.stringify(obj), jsan.stringify(obj));
});
it("allows replacer functions when traversing", function() {
var obj1 = {
i: immutable.Map({
someList: immutable.List(),
someMap: immutable.Map({
foo: function() {},
bar: 123
})
})
};
obj1.self = obj1;
var obj2 = jsan.parse(jsan.stringify(obj1, function(key, value) {
if (value && value.toJS) { return value.toJS(); }
return value;
}, null, true));
assert.deepEqual(obj2.i.someList, []);
assert.deepEqual(obj2.self, obj2);
assert(obj2.i.someMap.foo instanceof Function);
});
});

@@ -16,2 +16,7 @@ var assert = require('assert');

it('uses the toJSON() method when possible', function() {
var obj = { toJSON: function() { return 'foobar' } };
assert.equal(jsan.stringify(obj), '"foobar"');
});
it('can handle dates', function() {

@@ -18,0 +23,0 @@ var obj = {

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