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

jsum

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsum - npm Package Compare versions

Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4

3

CHANGELOG.md
# Changelog
* `2.0.0-alpha.4`:
* Fix hash collision (see issue #8)
* Update mocha (dev dependency)
* `2.0.0-alpha.3`: Remove `.github` files from `npm`.

@@ -3,0 +6,0 @@ * `2.0.0-alpha.2`: Use GitHub Actions instead of Travis CI.

25

index.js

@@ -5,18 +5,16 @@ 'use strict'

function _serialize (obj) {
function _serialize(obj) {
if (Array.isArray(obj)) {
for (let i = 0; i < obj.length; i++) {
obj[i] = _serialize(obj[i])
return `[${obj.map(el => _serialize(el)).join(',')}]`
} else if (typeof obj === 'object' && obj !== null) {
let acc = ''
const keys = Object.keys(obj).sort()
acc += `{${JSON.stringify(keys)}`
for (let i = 0; i < keys.length; i++) {
acc += `${_serialize(obj[keys[i]])},`
}
return obj
} else if (typeof obj === 'object' && obj != null) {
const sortedKeys = Object.keys(obj).sort()
for (let i = 0; i < sortedKeys.length; i++) {
const k = sortedKeys[i]
obj[k] = _serialize(obj[k])
}
return JSON.stringify(obj, sortedKeys)
return `${acc}}`
}
return obj
return `${JSON.stringify(obj)}`
}

@@ -35,4 +33,3 @@

function serialize (obj) {
const ser = _serialize(obj)
return (typeof ser !== 'string') ? JSON.stringify(ser) : ser
return _serialize(obj, '')
}

@@ -39,0 +36,0 @@

{
"name": "jsum",
"version": "2.0.0-alpha.3",
"version": "2.0.0-alpha.4",
"description": "Consistent checksum calculation of JSON objects.",

@@ -22,4 +22,4 @@ "main": "index.js",

"chai": "^3.5.0",
"mocha": "^9.0.3"
"mocha": "^9.2.0"
}
}

@@ -67,7 +67,7 @@ # JSum

# benchmark/fixtures/medium.json (77986 bytes)
fast-json-stable-stringify x 629 ops/sec ±1.67% (81 runs sampled)
json-checksum x 236 ops/sec ±0.88% (82 runs sampled)
json-hash x 83.40 ops/sec ±1.25% (60 runs sampled)
json-stable-stringify x 609 ops/sec ±0.80% (87 runs sampled)
jsum x 1,118 ops/sec ±0.68% (89 runs sampled)
fast-json-stable-stringify x 1,191 ops/sec ±1.11% (89 runs sampled)
json-checksum x 406 ops/sec ±2.04% (89 runs sampled)
json-hash x 148 ops/sec ±2.08% (75 runs sampled)
json-stable-stringify x 1,051 ops/sec ±2.29% (88 runs sampled)
jsum x 1,339 ops/sec ±0.77% (93 runs sampled)

@@ -77,9 +77,9 @@ fastest is jsum

# benchmark/fixtures/small.json (456 bytes)
fast-json-stable-stringify x 67,381 ops/sec ±1.16% (84 runs sampled)
json-checksum x 21,372 ops/sec ±1.21% (89 runs sampled)
json-hash x 7,409 ops/sec ±1.17% (75 runs sampled)
json-stable-stringify x 54,015 ops/sec ±0.89% (83 runs sampled)
jsum x 90,816 ops/sec ±1.06% (87 runs sampled)
fast-json-stable-stringify x 116,709 ops/sec ±2.25% (91 runs sampled)
json-checksum x 36,311 ops/sec ±1.66% (91 runs sampled)
json-hash x 12,051 ops/sec ±3.62% (77 runs sampled)
json-stable-stringify x 91,078 ops/sec ±2.08% (89 runs sampled)
jsum x 116,130 ops/sec ±1.46% (90 runs sampled)
fastest is jsum
```
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