Comparing version 1.0.3 to 1.0.4
@@ -148,2 +148,12 @@ 'use strict'; | ||
}); | ||
describe('toosmall', () => { | ||
for (const fixture of fixtures) { | ||
if (fixture.strict !== false && typeof fixture.expected === 'number') { | ||
const small = BigInt(fixture.expected); | ||
it(`should encode ${ small }n`, () => { | ||
assert.strictEqual(byteUtils.toHex(encode.encode(BigInt(small))), fixture.data, `encode ${ small }`); | ||
}); | ||
} | ||
} | ||
}); | ||
}); |
@@ -137,2 +137,12 @@ 'use strict'; | ||
}); | ||
describe('toosmall', () => { | ||
for (const fixture of fixtures) { | ||
if (fixture.strict !== false && typeof fixture.expected === 'number') { | ||
const small = BigInt(fixture.expected); | ||
it(`should encode ${ small }n`, () => { | ||
assert.strictEqual(byteUtils.toHex(encode.encode(BigInt(small))), fixture.data, `encode ${ small }`); | ||
}); | ||
} | ||
} | ||
}); | ||
}); |
@@ -72,21 +72,25 @@ 'use strict'; | ||
if (uint < uintBoundaries[0]) { | ||
buf.push([major | uint]); | ||
const nuint = Number(uint); | ||
buf.push([major | nuint]); | ||
} else if (uint < uintBoundaries[1]) { | ||
const nuint = Number(uint); | ||
buf.push([ | ||
major | 24, | ||
uint | ||
nuint | ||
]); | ||
} else if (uint < uintBoundaries[2]) { | ||
const nuint = Number(uint); | ||
buf.push([ | ||
major | 25, | ||
uint >>> 8, | ||
uint & 255 | ||
nuint >>> 8, | ||
nuint & 255 | ||
]); | ||
} else if (uint < uintBoundaries[3]) { | ||
const nuint = Number(uint); | ||
buf.push([ | ||
major | 26, | ||
uint >>> 24 & 255, | ||
uint >>> 16 & 255, | ||
uint >>> 8 & 255, | ||
uint & 255 | ||
nuint >>> 24 & 255, | ||
nuint >>> 16 & 255, | ||
nuint >>> 8 & 255, | ||
nuint & 255 | ||
]); | ||
@@ -93,0 +97,0 @@ } else { |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const useBuffer = !process.browser && global.Buffer && typeof global.Buffer.isBuffer === 'function'; | ||
const useBuffer = typeof process !== 'undefined' && !process.browser && global.Buffer && typeof global.Buffer.isBuffer === 'function'; | ||
const textDecoder = new TextDecoder(); | ||
@@ -8,0 +8,0 @@ const textEncoder = new TextEncoder(); |
@@ -162,3 +162,3 @@ 'use strict'; | ||
if (token$1.value < 24) { | ||
return byteUtils.fromArray([token$1.value]); | ||
return byteUtils.fromArray([Number(token$1.value)]); | ||
} | ||
@@ -168,3 +168,3 @@ return; | ||
if (token$1.value >= -24) { | ||
return byteUtils.fromArray([31 - token$1.value]); | ||
return byteUtils.fromArray([31 - Number(token$1.value)]); | ||
} | ||
@@ -171,0 +171,0 @@ } |
@@ -148,2 +148,12 @@ 'use strict'; | ||
}); | ||
describe('toosmall', () => { | ||
for (const fixture of fixtures) { | ||
if (fixture.strict !== false && typeof fixture.expected === 'number') { | ||
const small = BigInt(fixture.expected); | ||
it(`should encode ${ small }n`, () => { | ||
assert.strictEqual(byteUtils.toHex(encode.encode(BigInt(small))), fixture.data, `encode ${ small }`); | ||
}); | ||
} | ||
} | ||
}); | ||
}); |
@@ -137,2 +137,12 @@ 'use strict'; | ||
}); | ||
describe('toosmall', () => { | ||
for (const fixture of fixtures) { | ||
if (fixture.strict !== false && typeof fixture.expected === 'number') { | ||
const small = BigInt(fixture.expected); | ||
it(`should encode ${ small }n`, () => { | ||
assert.strictEqual(byteUtils.toHex(encode.encode(BigInt(small))), fixture.data, `encode ${ small }`); | ||
}); | ||
} | ||
} | ||
}); | ||
}); |
@@ -145,2 +145,12 @@ import chai from 'chai'; | ||
}); | ||
describe('toosmall', () => { | ||
for (const fixture of fixtures) { | ||
if (fixture.strict !== false && typeof fixture.expected === 'number') { | ||
const small = BigInt(fixture.expected); | ||
it(`should encode ${ small }n`, () => { | ||
assert.strictEqual(toHex(encode(BigInt(small))), fixture.data, `encode ${ small }`); | ||
}); | ||
} | ||
} | ||
}); | ||
}); |
@@ -134,2 +134,12 @@ import chai from 'chai'; | ||
}); | ||
describe('toosmall', () => { | ||
for (const fixture of fixtures) { | ||
if (fixture.strict !== false && typeof fixture.expected === 'number') { | ||
const small = BigInt(fixture.expected); | ||
it(`should encode ${ small }n`, () => { | ||
assert.strictEqual(toHex(encode(BigInt(small))), fixture.data, `encode ${ small }`); | ||
}); | ||
} | ||
} | ||
}); | ||
}); |
@@ -73,21 +73,25 @@ import { | ||
if (uint < uintBoundaries[0]) { | ||
buf.push([major | uint]); | ||
const nuint = Number(uint); | ||
buf.push([major | nuint]); | ||
} else if (uint < uintBoundaries[1]) { | ||
const nuint = Number(uint); | ||
buf.push([ | ||
major | 24, | ||
uint | ||
nuint | ||
]); | ||
} else if (uint < uintBoundaries[2]) { | ||
const nuint = Number(uint); | ||
buf.push([ | ||
major | 25, | ||
uint >>> 8, | ||
uint & 255 | ||
nuint >>> 8, | ||
nuint & 255 | ||
]); | ||
} else if (uint < uintBoundaries[3]) { | ||
const nuint = Number(uint); | ||
buf.push([ | ||
major | 26, | ||
uint >>> 24 & 255, | ||
uint >>> 16 & 255, | ||
uint >>> 8 & 255, | ||
uint & 255 | ||
nuint >>> 24 & 255, | ||
nuint >>> 16 & 255, | ||
nuint >>> 8 & 255, | ||
nuint & 255 | ||
]); | ||
@@ -94,0 +98,0 @@ } else { |
@@ -1,2 +0,2 @@ | ||
export const useBuffer = !process.browser && global.Buffer && typeof global.Buffer.isBuffer === 'function'; | ||
export const useBuffer = typeof process !== 'undefined' && !process.browser && global.Buffer && typeof global.Buffer.isBuffer === 'function'; | ||
const textDecoder = new TextDecoder(); | ||
@@ -3,0 +3,0 @@ const textEncoder = new TextEncoder(); |
@@ -160,3 +160,3 @@ import { | ||
if (token.value < 24) { | ||
return fromArray([token.value]); | ||
return fromArray([Number(token.value)]); | ||
} | ||
@@ -166,5 +166,5 @@ return; | ||
if (token.value >= -24) { | ||
return fromArray([31 - token.value]); | ||
return fromArray([31 - Number(token.value)]); | ||
} | ||
} | ||
} |
@@ -145,2 +145,12 @@ import chai from 'chai'; | ||
}); | ||
describe('toosmall', () => { | ||
for (const fixture of fixtures) { | ||
if (fixture.strict !== false && typeof fixture.expected === 'number') { | ||
const small = BigInt(fixture.expected); | ||
it(`should encode ${ small }n`, () => { | ||
assert.strictEqual(toHex(encode(BigInt(small))), fixture.data, `encode ${ small }`); | ||
}); | ||
} | ||
} | ||
}); | ||
}); |
@@ -134,2 +134,12 @@ import chai from 'chai'; | ||
}); | ||
describe('toosmall', () => { | ||
for (const fixture of fixtures) { | ||
if (fixture.strict !== false && typeof fixture.expected === 'number') { | ||
const small = BigInt(fixture.expected); | ||
it(`should encode ${ small }n`, () => { | ||
assert.strictEqual(toHex(encode(BigInt(small))), fixture.data, `encode ${ small }`); | ||
}); | ||
} | ||
} | ||
}); | ||
}); |
{ | ||
"name": "cborg", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Fast CBOR with a focus on strictness", | ||
@@ -10,3 +10,3 @@ "bin": { | ||
"lint": "standard *.js lib/*.js test/*.js", | ||
"build": "npx ipjs build --tests && cp cli.js dist/", | ||
"build": "npx ipjs build --tests && cp cli.js cborg.d.ts dist/", | ||
"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js dist/cjs/node-test/node-test-*.js", | ||
@@ -13,0 +13,0 @@ "test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/test-*.js test/node-test-*.js", |
414640
102
14265