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

assert

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert - npm Package Compare versions

Comparing version 0.4.9 to 1.0.0

.npmignore

103

assert.js

@@ -1,4 +0,1 @@

(function () {
"use strict"
// http://wiki.commonjs.org/wiki/Unit_Testing/1.0

@@ -28,4 +25,7 @@ //

// UTILITY
var util = require('util');
// when used in node, this will actually load the util module we depend on
// versus loading the builtin util module as happens otherwise
// this is a bug in node module loading as far as I am concerned
var util = require('./node_modules/util');
var pSlice = Array.prototype.slice;

@@ -37,3 +37,3 @@

var assert = exports;
var assert = module.exports = ok;

@@ -47,6 +47,12 @@ // 2. The AssertionError is defined in assert.

this.name = 'AssertionError';
this.message = options.message;
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
if (options.message) {
this.message = options.message;
this.generatedMessage = false;
} else {
this.message = getMessage(this);
this.generatedMessage = true;
}
var stackStartFunction = options.stackStartFunction || fail;

@@ -58,19 +64,33 @@

};
// assert.AssertionError instanceof Error
util.inherits(assert.AssertionError, Error);
assert.AssertionError.prototype.toString = function() {
if (this.message) {
return [this.name + ':', this.message].join(' ');
function replacer(key, value) {
if (util.isUndefined(value)) {
return '' + value;
}
if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
return value.toString();
}
if (util.isFunction(value) || util.isRegExp(value)) {
return value.toString();
}
return value;
}
function truncate(s, n) {
if (util.isString(s)) {
return s.length < n ? s : s.slice(0, n);
} else {
return [this.name + ':',
JSON.stringify(this.expected),
this.operator,
JSON.stringify(this.actual)].join(' ');
return s;
}
};
}
// assert.AssertionError instanceof Error
function getMessage(self) {
return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
self.operator + ' ' +
truncate(JSON.stringify(self.expected, replacer), 128);
}
assert.AssertionError.__proto__ = Error.prototype;
// At present only the three keys mentioned above are used and

@@ -103,9 +123,10 @@ // understood by the spec. Implementations or sub modules can pass

// assert.ok(guard, message_opt);
// This statement is equivalent to assert.equal(true, guard,
// This statement is equivalent to assert.equal(true, !!guard,
// message_opt);. To test strictly for the value true, use
// assert.strictEqual(true, guard, message_opt);.
assert.ok = function ok(value, message) {
if (!!!value) fail(value, true, message, '==', assert.ok);
};
function ok(value, message) {
if (!value) fail(value, true, message, '==', assert.ok);
}
assert.ok = ok;

@@ -143,3 +164,3 @@ // 5. The equality assertion tests shallow, coercive equality with

} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
} else if (util.isBuffer(actual) && util.isBuffer(expected)) {
if (actual.length != expected.length) return false;

@@ -155,11 +176,21 @@

// equivalent if it is also a Date object that refers to the same time.
} else if (actual instanceof Date && expected instanceof Date) {
} else if (util.isDate(actual) && util.isDate(expected)) {
return actual.getTime() === expected.getTime();
// 7.3. Other pairs that do not both pass typeof value == 'object',
// 7.3 If the expected value is a RegExp object, the actual value is
// equivalent if it is also a RegExp object with the same source and
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
} else if (util.isRegExp(actual) && util.isRegExp(expected)) {
return actual.source === expected.source &&
actual.global === expected.global &&
actual.multiline === expected.multiline &&
actual.lastIndex === expected.lastIndex &&
actual.ignoreCase === expected.ignoreCase;
// 7.4. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
} else if (typeof actual != 'object' && typeof expected != 'object') {
} else if (!util.isObject(actual) && !util.isObject(expected)) {
return actual == expected;
// 7.4. For all other Object pairs, including Array objects, equivalence is
// 7.5 For all other Object pairs, including Array objects, equivalence is
// determined by having the same number of owned properties (as verified

@@ -175,6 +206,2 @@ // with Object.prototype.hasOwnProperty.call), the same set of keys

function isUndefinedOrNull(value) {
return value === null || value === undefined;
}
function isArguments(object) {

@@ -185,3 +212,3 @@ return Object.prototype.toString.call(object) == '[object Arguments]';

function objEquiv(a, b) {
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
return false;

@@ -260,3 +287,3 @@ // an identical 'prototype' property.

if (expected instanceof RegExp) {
if (Object.prototype.toString.call(expected) == '[object RegExp]') {
return expected.test(actual);

@@ -275,3 +302,3 @@ } else if (actual instanceof expected) {

if (typeof expected === 'string') {
if (util.isString(expected)) {
message = expected;

@@ -291,7 +318,7 @@ expected = null;

if (shouldThrow && !actual) {
fail('Missing expected exception' + message);
fail(actual, expected, 'Missing expected exception' + message);
}
if (!shouldThrow && expectedException(actual, expected)) {
fail('Got unwanted exception' + message);
fail(actual, expected, 'Got unwanted exception' + message);
}

@@ -313,3 +340,3 @@

// EXTENSION! This is annoying to write outside this module.
assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
assert.doesNotThrow = function(block, /*optional*/message) {
_throws.apply(this, [false].concat(pSlice.call(arguments)));

@@ -319,3 +346,1 @@ };

assert.ifError = function(err) { if (err) {throw err;}};
}());
{
"author": "narwhal.js (http://narwhaljs.org)",
"name": "assert",
"description": "Node.JS assert module",
"keywords": ["ender", "assert"],
"version": "0.4.9",
"homepage": "http://nodejs.org/docs/v0.4.9/api/assert.html",
"description": "commonjs assert - node.js api compatible",
"keywords": [
"assert"
],
"version": "1.0.0",
"homepage": "https://github.com/defunctzombie/commonjs-assert",
"repository": {
"type": "git",
"url": "git://github.com/coolaj86/nodejs-libs-4-browser.git"
"url": "git://github.com/defunctzombie/commonjs-assert.git"
},
"main": "./assert.js",
"directories": {
"lib": "."
"dependencies": {
"util": "0.10.0"
},
"engines": {
"node": ">= 0.2.0",
"ender": ">= 0.5.0"
"devDependencies": {
"mocha": "1.14.0"
},
"dependencies": {
"util": ">= 0.4.9"
},
"devDependencies": {}
"scripts": {
"test": "mocha --ui qunit test.js"
}
}
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