Socket
Socket
Sign inDemoInstall

bsert

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bsert - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

112

lib/assert.js

@@ -15,27 +15,47 @@ /*!

constructor(options) {
super();
if (typeof options === 'string')
options = { message: options };
if (!options)
if (options === null || typeof options !== 'object')
options = {};
if (typeof options === 'string')
options = { message: options };
let message = '';
let operator = '!=';
let generatedMessage = false;
if (options.message != null)
message = toString(options.message);
if (typeof options.operator === 'string')
operator = options.operator;
if (!message) {
const a = stringify(options.actual);
const b = stringify(options.expected);
message = `${a} ${operator} ${b}`;
generatedMessage = true;
}
super(message);
let start = this.constructor;
if (typeof options.start === 'function')
start = options.start;
else if (typeof options.stackStartFn === 'function')
start = options.stackStartFn;
else if (typeof options.stackStartFunction === 'function')
start = options.stackStartFunction;
this.type = 'AssertionError';
this.name = 'AssertionError';
this.name = 'AssertionError [ERR_ASSERTION]';
this.code = 'ERR_ASSERTION';
this.message = options.message ? String(options.message) : '';
this.generatedMessage = generatedMessage;
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator || '===';
this.operator = operator;
if (!this.message) {
const a = stringify(this.actual);
const b = stringify(this.expected);
this.message = `${a} ${this.operator} ${b}`;
}
if (Error.captureStackTrace)
Error.captureStackTrace(this, options.start || AssertionError);
Error.captureStackTrace(this, start);
}

@@ -60,14 +80,4 @@ }

assert.assert = assert;
assert.AssertionError = AssertionError;
assert.ok = assert;
assert.enforce = function enforce(value, name, type) {
if (!value) {
const err = new TypeError(`'${name}' must be a(n) ${type}.`);
if (Error.captureStackTrace)
Error.captureStackTrace(err, enforce);
throw err;
}
};
assert.equal = function equal(actual, expected, message) {

@@ -98,4 +108,36 @@ if (actual !== expected) {

assert.strictEqual = assert.equal;
assert.notStrictEqual = assert.notEqual;
assert.fail = function fail(message) {
if (message == null || message === '')
message = 'Failed';
throw new AssertionError({
message,
actual: false,
expected: true,
operator: '==',
start: fail
});
};
assert.enforce = function enforce(value, name, type) {
if (!value) {
const err = new TypeError(`'${name}' must be a(n) ${type}.`);
if (Error.captureStackTrace)
Error.captureStackTrace(err, enforce);
throw err;
}
};
assert.range = function range(value, name) {
if (!value) {
const err = new RangeError(`'${name}' is out of range.`);
if (Error.captureStackTrace)
Error.captureStackTrace(err, range);
throw err;
}
};
/*

@@ -114,3 +156,4 @@ * Helpers

if (!value.constructor
|| !value.constructor.name) {
|| typeof value.constructor.name !== 'string'
|| value.constructor.name === 'Object') {
return '[Object]';

@@ -126,3 +169,3 @@ }

if (value.length > 64)
value = value.substring(0, 64);
value = `${value.substring(0, 61)}...`;
return JSON.stringify(value);

@@ -132,3 +175,3 @@ case 'symbol':

case 'function':
if (!value.name)
if (typeof value.name !== 'string')
return '[Function]';

@@ -143,2 +186,9 @@ return `[Function: ${value.name}]`;

function toString(str) {
if (typeof str === 'string')
return str;
return stringify(str);
}
/*

@@ -148,2 +198,6 @@ * Expose

assert.AssertionError = AssertionError;
assert.assert = assert;
assert.strict = assert;
module.exports = assert;
{
"name": "bsert",
"version": "0.0.3",
"version": "0.0.4",
"description": "Minimal assert with type checking",

@@ -5,0 +5,0 @@ "keywords": [

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