@ipld/dag-json
Advanced tools
Comparing version 7.0.8 to 8.0.0
@@ -125,2 +125,24 @@ 'use strict'; | ||
}); | ||
test('bigints', () => { | ||
const verify = inp => { | ||
assert.strictEqual(index.decode(new TextEncoder().encode(String(inp))), inp); | ||
}; | ||
verify(0); | ||
verify(1); | ||
verify(-1); | ||
verify(Math.pow(2, 50)); | ||
verify(-Math.pow(2, 50)); | ||
verify(Number.MAX_SAFE_INTEGER); | ||
verify(-Number.MAX_SAFE_INTEGER); | ||
verify(BigInt('9007199254740992')); | ||
verify(BigInt('9007199254740993')); | ||
verify(BigInt('11959030306112471731')); | ||
verify(BigInt('18446744073709551615')); | ||
verify(BigInt('9223372036854775807')); | ||
verify(BigInt('-9007199254740992')); | ||
verify(BigInt('-9007199254740993')); | ||
verify(BigInt('-9223372036854776000')); | ||
verify(BigInt('-11959030306112471732')); | ||
verify(BigInt('-18446744073709551616')); | ||
}); | ||
test('error on circular references', () => { | ||
@@ -127,0 +149,0 @@ const circularObj = {}; |
@@ -149,3 +149,3 @@ 'use strict'; | ||
const decode = data => { | ||
const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(data) }); | ||
const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(data, decodeOptions) }); | ||
return cborgJson__namespace.decode(data, options); | ||
@@ -152,0 +152,0 @@ }; |
@@ -125,2 +125,24 @@ 'use strict'; | ||
}); | ||
test('bigints', () => { | ||
const verify = inp => { | ||
assert.strictEqual(index.decode(new TextEncoder().encode(String(inp))), inp); | ||
}; | ||
verify(0); | ||
verify(1); | ||
verify(-1); | ||
verify(Math.pow(2, 50)); | ||
verify(-Math.pow(2, 50)); | ||
verify(Number.MAX_SAFE_INTEGER); | ||
verify(-Number.MAX_SAFE_INTEGER); | ||
verify(BigInt('9007199254740992')); | ||
verify(BigInt('9007199254740993')); | ||
verify(BigInt('11959030306112471731')); | ||
verify(BigInt('18446744073709551615')); | ||
verify(BigInt('9223372036854775807')); | ||
verify(BigInt('-9007199254740992')); | ||
verify(BigInt('-9007199254740993')); | ||
verify(BigInt('-9223372036854776000')); | ||
verify(BigInt('-11959030306112471732')); | ||
verify(BigInt('-18446744073709551616')); | ||
}); | ||
test('error on circular references', () => { | ||
@@ -127,0 +149,0 @@ const circularObj = {}; |
@@ -124,2 +124,24 @@ 'use strict'; | ||
}); | ||
test('bigints', () => { | ||
const verify = inp => { | ||
assert.strictEqual(decode(new TextEncoder().encode(String(inp))), inp); | ||
}; | ||
verify(0); | ||
verify(1); | ||
verify(-1); | ||
verify(Math.pow(2, 50)); | ||
verify(-Math.pow(2, 50)); | ||
verify(Number.MAX_SAFE_INTEGER); | ||
verify(-Number.MAX_SAFE_INTEGER); | ||
verify(BigInt('9007199254740992')); | ||
verify(BigInt('9007199254740993')); | ||
verify(BigInt('11959030306112471731')); | ||
verify(BigInt('18446744073709551615')); | ||
verify(BigInt('9223372036854775807')); | ||
verify(BigInt('-9007199254740992')); | ||
verify(BigInt('-9007199254740993')); | ||
verify(BigInt('-9223372036854776000')); | ||
verify(BigInt('-11959030306112471732')); | ||
verify(BigInt('-18446744073709551616')); | ||
}); | ||
test('error on circular references', () => { | ||
@@ -126,0 +148,0 @@ const circularObj = {}; |
@@ -125,4 +125,4 @@ import { CID } from 'multiformats'; | ||
export const decode = data => { | ||
const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(data) }); | ||
const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(data, decodeOptions) }); | ||
return cborgJson.decode(data, options); | ||
}; |
@@ -124,2 +124,24 @@ 'use strict'; | ||
}); | ||
test('bigints', () => { | ||
const verify = inp => { | ||
assert.strictEqual(decode(new TextEncoder().encode(String(inp))), inp); | ||
}; | ||
verify(0); | ||
verify(1); | ||
verify(-1); | ||
verify(Math.pow(2, 50)); | ||
verify(-Math.pow(2, 50)); | ||
verify(Number.MAX_SAFE_INTEGER); | ||
verify(-Number.MAX_SAFE_INTEGER); | ||
verify(BigInt('9007199254740992')); | ||
verify(BigInt('9007199254740993')); | ||
verify(BigInt('11959030306112471731')); | ||
verify(BigInt('18446744073709551615')); | ||
verify(BigInt('9223372036854775807')); | ||
verify(BigInt('-9007199254740992')); | ||
verify(BigInt('-9007199254740993')); | ||
verify(BigInt('-9223372036854776000')); | ||
verify(BigInt('-11959030306112471732')); | ||
verify(BigInt('-18446744073709551616')); | ||
}); | ||
test('error on circular references', () => { | ||
@@ -126,0 +148,0 @@ const circularObj = {}; |
@@ -214,4 +214,4 @@ import { CID } from 'multiformats' | ||
// the tokenizer is stateful so we need a single instance of it | ||
const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(data) }) | ||
const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(data, decodeOptions) }) | ||
return cborgJson.decode(data, options) | ||
} |
{ | ||
"name": "@ipld/dag-json", | ||
"version": "7.0.8", | ||
"version": "8.0.0", | ||
"description": "JSON Directed Acrylic Graph (DAG-JSON) for IPLD", | ||
@@ -40,3 +40,3 @@ "main": "./cjs/index.js", | ||
"dependencies": { | ||
"cborg": "^1.3.1", | ||
"cborg": "^1.4.0", | ||
"multiformats": "^9.0.0" | ||
@@ -43,0 +43,0 @@ }, |
@@ -83,2 +83,28 @@ 'use strict' | ||
test('bigints', () => { | ||
const verify = (inp) => { | ||
assert.strictEqual(decode(new TextEncoder().encode(String(inp))), inp) | ||
} | ||
// plain Number objects | ||
verify(0) | ||
verify(1) | ||
verify(-1) | ||
verify(Math.pow(2, 50)) | ||
verify(-Math.pow(2, 50)) | ||
verify(Number.MAX_SAFE_INTEGER) | ||
verify(-Number.MAX_SAFE_INTEGER) | ||
// should round-trip as BigInts | ||
verify(BigInt('9007199254740992')) // Number.MAX_SAFE_INTEGER+1 | ||
verify(BigInt('9007199254740993')) | ||
verify(BigInt('11959030306112471731')) | ||
verify(BigInt('18446744073709551615')) // max uint64 | ||
verify(BigInt('9223372036854775807')) // max int64 | ||
verify(BigInt('-9007199254740992')) | ||
verify(BigInt('-9007199254740993')) | ||
verify(BigInt('-9223372036854776000')) // min int64 | ||
verify(BigInt('-11959030306112471732')) | ||
verify(BigInt('-18446744073709551616')) // min -uint64 | ||
}) | ||
test('error on circular references', () => { | ||
@@ -85,0 +111,0 @@ const circularObj = {} |
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
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
56691
1563
Updatedcborg@^1.4.0