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

cborg

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cborg - npm Package Compare versions

Comparing version 1.5.4 to 1.6.0

16

cjs/browser-test/test-7float.js

@@ -201,2 +201,4 @@ 'use strict';

it('can switch off undefined support', () => {
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('f7')), undefined);
assert.throws(() => decode.decode(byteUtils.fromHex('f7'), { allowUndefined: false }), /undefined/);
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('830102f7')), [

@@ -209,2 +211,16 @@ 1,

});
it('can coerce undefined to null', () => {
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('f7'), { coerceUndefinedToNull: false }), undefined);
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('f7'), { coerceUndefinedToNull: true }), null);
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('830102f7'), { coerceUndefinedToNull: false }), [
1,
2,
undefined
]);
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('830102f7'), { coerceUndefinedToNull: true }), [
1,
2,
null
]);
});
it('can switch off Infinity support', () => {

@@ -211,0 +227,0 @@ assert.deepStrictEqual(decode.decode(byteUtils.fromHex('830102f97c00')), [

2

cjs/lib/7float.js

@@ -16,2 +16,4 @@ 'use strict';

throw new Error(`${ common.decodeErrPrefix } undefined values are not supported`);
} else if (options.coerceUndefinedToNull === true) {
return new token.Token(token.Type.null, null, 1);
}

@@ -18,0 +20,0 @@ return new token.Token(token.Type.undefined, undefined, 1);

@@ -201,2 +201,4 @@ 'use strict';

it('can switch off undefined support', () => {
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('f7')), undefined);
assert.throws(() => decode.decode(byteUtils.fromHex('f7'), { allowUndefined: false }), /undefined/);
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('830102f7')), [

@@ -209,2 +211,16 @@ 1,

});
it('can coerce undefined to null', () => {
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('f7'), { coerceUndefinedToNull: false }), undefined);
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('f7'), { coerceUndefinedToNull: true }), null);
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('830102f7'), { coerceUndefinedToNull: false }), [
1,
2,
undefined
]);
assert.deepStrictEqual(decode.decode(byteUtils.fromHex('830102f7'), { coerceUndefinedToNull: true }), [
1,
2,
null
]);
});
it('can switch off Infinity support', () => {

@@ -211,0 +227,0 @@ assert.deepStrictEqual(decode.decode(byteUtils.fromHex('830102f97c00')), [

@@ -198,2 +198,4 @@ import chai from 'chai';

it('can switch off undefined support', () => {
assert.deepStrictEqual(decode(fromHex('f7')), undefined);
assert.throws(() => decode(fromHex('f7'), { allowUndefined: false }), /undefined/);
assert.deepStrictEqual(decode(fromHex('830102f7')), [

@@ -206,2 +208,16 @@ 1,

});
it('can coerce undefined to null', () => {
assert.deepStrictEqual(decode(fromHex('f7'), { coerceUndefinedToNull: false }), undefined);
assert.deepStrictEqual(decode(fromHex('f7'), { coerceUndefinedToNull: true }), null);
assert.deepStrictEqual(decode(fromHex('830102f7'), { coerceUndefinedToNull: false }), [
1,
2,
undefined
]);
assert.deepStrictEqual(decode(fromHex('830102f7'), { coerceUndefinedToNull: true }), [
1,
2,
null
]);
});
it('can switch off Infinity support', () => {

@@ -208,0 +224,0 @@ assert.deepStrictEqual(decode(fromHex('830102f97c00')), [

@@ -14,2 +14,4 @@ import {

throw new Error(`${ decodeErrPrefix } undefined values are not supported`);
} else if (options.coerceUndefinedToNull === true) {
return new Token(Type.null, null, 1);
}

@@ -16,0 +18,0 @@ return new Token(Type.undefined, undefined, 1);

@@ -198,2 +198,4 @@ import chai from 'chai';

it('can switch off undefined support', () => {
assert.deepStrictEqual(decode(fromHex('f7')), undefined);
assert.throws(() => decode(fromHex('f7'), { allowUndefined: false }), /undefined/);
assert.deepStrictEqual(decode(fromHex('830102f7')), [

@@ -206,2 +208,16 @@ 1,

});
it('can coerce undefined to null', () => {
assert.deepStrictEqual(decode(fromHex('f7'), { coerceUndefinedToNull: false }), undefined);
assert.deepStrictEqual(decode(fromHex('f7'), { coerceUndefinedToNull: true }), null);
assert.deepStrictEqual(decode(fromHex('830102f7'), { coerceUndefinedToNull: false }), [
1,
2,
undefined
]);
assert.deepStrictEqual(decode(fromHex('830102f7'), { coerceUndefinedToNull: true }), [
1,
2,
null
]);
});
it('can switch off Infinity support', () => {

@@ -208,0 +224,0 @@ assert.deepStrictEqual(decode(fromHex('830102f97c00')), [

@@ -36,2 +36,3 @@ import { Token } from './lib/token'

allowUndefined?: boolean
coerceUndefinedToNull?: boolean
allowInfinity?: boolean

@@ -38,0 +39,0 @@ allowNaN?: boolean

@@ -29,2 +29,4 @@ // TODO: shift some of the bytes logic to bytes-utils so we can use Buffer

throw new Error(`${decodeErrPrefix} undefined values are not supported`)
} else if (options.coerceUndefinedToNull === true) {
return new Token(Type.null, null, 1)
}

@@ -31,0 +33,0 @@ return new Token(Type.undefined, undefined, 1)

26

package.json
{
"name": "cborg",
"version": "1.5.4",
"version": "1.6.0",
"description": "Fast CBOR with a focus on strictness",

@@ -16,7 +16,9 @@ "main": "./cjs/cborg.js",

"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js dist/cjs/node-test/node-test-*.js",
"test:esm": "npm run build && mocha dist/esm/node-test/test-*.js dist/esm/node-test/node-test-*.js",
"test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/test-*.js test/node-test-*.js",
"test:browser:cjs": "polendina --page --worker --serviceworker --cleanup dist/cjs/node-test/test-*.js",
"test:browser:esm": "polendina --page --worker --serviceworker --cleanup dist/esm/node-test/test-*.js",
"test:browser:cjs": "polendina --page --worker --serviceworker --cleanup dist/cjs/browser-test/test-*.js",
"test:browser:esm": "polendina --page --worker --serviceworker --cleanup dist/esm/browser-test/test-*.js",
"test:browser": "npm run test:browser:cjs && npm run test:browser:cjs",
"test": "npm run lint && npm run test:node && npm run test:cjs && npm run test:browser",
"test": "npm run lint && npm run test:node && npm run test:esm && npm run test:browser:esm",
"test:ci": "npm run lint && npm run test:node && npm run test:cjs && npm run test:esm && npm run test:browser",
"coverage": "c8 --reporter=html mocha test/test-*.js && npx st -d coverage -p 8080"

@@ -34,10 +36,10 @@ },

"devDependencies": {
"c8": "^7.6.0",
"chai": "^4.3.3",
"ipjs": "^5.0.0",
"ipld-garbage": "^4.0.1",
"mocha": "^9.0.0",
"polendina": "^2.0.0",
"standard": "^16.0.3",
"typescript": "^4.2.4"
"c8": "^7.10.0",
"chai": "^4.3.4",
"ipjs": "^5.2.0",
"ipld-garbage": "^4.0.10",
"mocha": "^9.1.3",
"polendina": "~2.0.1",
"standard": "^16.0.4",
"typescript": "~4.5.3"
},

@@ -44,0 +46,0 @@ "exports": {

@@ -146,2 +146,3 @@ # cborg - fast CBOR with a focus on strictness

* `allowUndefined` (boolean, default `true`): when major 7, minor 23 (`undefined`) is encountered, an error will be thrown. To disallow `undefined` on encode, a custom [type encoder](#type-encoders) for `'undefined'` will need to be supplied.
* `coerceUndefinedToNull` (boolean, default `false`): when both `allowUndefined` and `coerceUndefinedToNull` are set to `true`, all `undefined` tokens (major `7` minor `23`: `0xf7`) will be coerced to `null` tokens, such that `undefined` is an allowed token but will not appear in decoded values.
* `allowInfinity` (boolean, default `true`): when an IEEE 754 `Infinity` or `-Infinity` value is encountered when decoding a major 7, an error will be thrown. To disallow `Infinity` and `-Infinity` on encode, a custom [type encoder](#type-encoders) for `'number'` will need to be supplied.

@@ -148,0 +149,0 @@ * `allowNaN` (boolean, default `true`): when an IEEE 754 `NaN` value is encountered when decoding a major 7, an error will be thrown. To disallow `NaN` on encode, a custom [type encoder](#type-encoders) for `'number'` will need to be supplied.

@@ -100,2 +100,4 @@ /* eslint-env mocha */

it('can switch off undefined support', () => {
assert.deepStrictEqual(decode(fromHex('f7')), undefined)
assert.throws(() => decode(fromHex('f7'), { allowUndefined: false }), /undefined/)
assert.deepStrictEqual(decode(fromHex('830102f7')), [1, 2, undefined])

@@ -105,2 +107,9 @@ assert.throws(() => decode(fromHex('830102f7'), { allowUndefined: false }), /undefined/)

it('can coerce undefined to null', () => {
assert.deepStrictEqual(decode(fromHex('f7'), { coerceUndefinedToNull: false }), undefined)
assert.deepStrictEqual(decode(fromHex('f7'), { coerceUndefinedToNull: true }), null)
assert.deepStrictEqual(decode(fromHex('830102f7'), { coerceUndefinedToNull: false }), [1, 2, undefined])
assert.deepStrictEqual(decode(fromHex('830102f7'), { coerceUndefinedToNull: true }), [1, 2, null])
})
it('can switch off Infinity support', () => {

@@ -107,0 +116,0 @@ assert.deepStrictEqual(decode(fromHex('830102f97c00')), [1, 2, Infinity])

@@ -26,2 +26,3 @@ import { Token } from './lib/token';

allowUndefined?: boolean;
coerceUndefinedToNull?: boolean;
allowInfinity?: boolean;

@@ -28,0 +29,0 @@ allowNaN?: boolean;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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