Comparing version 0.4.9 to 1.0.0
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" | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
24763
7
547
0
0
65
0
1
2
1
+ Addedutil@0.10.0(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-arguments@1.1.1(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-generator-function@1.0.10(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedutil@0.12.5(transitive)
- Removedwhich-typed-array@1.1.15(transitive)
Updatedutil@0.10.0