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

empower

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

empower - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

.jshintrc

10

Gruntfile.js

@@ -16,2 +16,10 @@ module.exports = function(grunt) {

ver: '<%= pkg.version %>',
jshint: {
files: [
'lib/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
unit: {

@@ -78,3 +86,3 @@ dir: ['test/**/*.js']

grunt.registerTask('test', ['qunit-test']);
grunt.registerTask('test', ['jshint', 'qunit-test']);
};

136

lib/empower.js
/**
* empower.js - Empower your assertions
* empower.js - Power Assert feature enhancer for assert function/object.
*

@@ -29,3 +29,4 @@ * https://github.com/twada/empower

var defaultConfig = {
var DEFAULT_OPTIONS = {
destructive: false,

@@ -36,37 +37,48 @@ formatter: defaultFormatter

// borrowed from qunit.js
function extend (a, b) {
var prop;
for (prop in b) {
if (b.hasOwnProperty(prop)) {
if (typeof b[prop] === 'undefined') {
delete a[prop];
} else {
a[prop] = b[prop];
}
}
/**
* Enhance Power Assert feature to assert function/object.
* @param assert target assert function or object to enhance
* @param options enhancement options
* @return enhanced assert function/object
*/
function empower (assert, options) {
var config;
if (isEmpowered(assert)) {
return assert;
}
return a;
config = extend(extend({}, DEFAULT_OPTIONS), (options || {}));
switch (typeof assert) {
case 'function':
return empowerAssertFunction(assert, config);
case 'object':
return empowerAssertObject(assert, config);
default:
throw new Error('Cannot be here');
}
}
// borrowed from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
function bind (aFunction, oThis) {
if (typeof aFunction !== "function") {
throw new TypeError("bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 2),
fToBind = aFunction,
fNOP = function () {},
fBound = function () {
return fToBind.apply(aFunction instanceof fNOP && oThis
? aFunction
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
function empowerAssertObject (assertObject, config) {
var baseAssert = config.destructive ? assertObject.ok : bind(assertObject.ok, assertObject),
enhancement = enhance(baseAssert, config.formatter),
target = config.destructive ? assertObject : Object.create(assertObject);
return extend(target, enhancement);
}
function empowerAssertFunction (assertFunction, config) {
var enhancement = enhance(assertFunction, config.formatter),
powerAssert = function powerAssert (context, message) {
enhancement.ok(context, message);
};
fNOP.prototype = aFunction.prototype;
fBound.prototype = new fNOP();
return fBound;
extend(powerAssert, assertFunction);
return extend(powerAssert, enhancement);
}
function isEmpowered (assertObjectOrFunction) {
return (typeof assertObjectOrFunction._capt === 'function') && (typeof assertObjectOrFunction._expr === 'function');
}
function enhance (baseAssert, formatter, callback) {

@@ -117,44 +129,40 @@ var events = [];

function isEmpowered (assertObjectOrFunction) {
return (typeof assertObjectOrFunction._capt === 'function') && (typeof assertObjectOrFunction._expr === 'function');
// borrowed from qunit.js
function extend (a, b) {
var prop;
for (prop in b) {
if (b.hasOwnProperty(prop)) {
if (typeof b[prop] === 'undefined') {
delete a[prop];
} else {
a[prop] = b[prop];
}
}
}
return a;
}
function empowerAssertObject (assertObject, config) {
var baseAssert = config['destructive'] ? assertObject.ok : bind(assertObject.ok, assertObject),
enhancement = enhance(baseAssert, config.formatter),
target = config['destructive'] ? assertObject : Object.create(assertObject);
return extend(target, enhancement);
// borrowed from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
function bind (aFunction, oThis) {
if (typeof aFunction !== 'function') {
throw new TypeError('bind - what is trying to be bound is not callable');
}
var aArgs = Array.prototype.slice.call(arguments, 2),
fToBind = aFunction,
NOP = function () {},
fBound = function () {
return fToBind.apply(((aFunction instanceof NOP) && oThis) ? aFunction : oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
NOP.prototype = aFunction.prototype;
fBound.prototype = new NOP();
return fBound;
}
function empowerAssertFunction (assertFunction, config) {
var enhancement = enhance(assertFunction, config.formatter);
var powerAssert = function powerAssert (context, message) {
enhancement.ok(context, message);
};
extend(powerAssert, assertFunction);
return extend(powerAssert, enhancement);
}
function empower (assert, options) {
if (isEmpowered(assert)) {
return assert;
}
var config = extend({}, defaultConfig);
extend(config, (options || {}));
switch (typeof assert) {
case 'function':
return empowerAssertFunction(assert, config);
case 'object':
return empowerAssertObject(assert, config);
default:
throw new Error('Cannot be here');
}
}
// using returnExports UMD pattern with substack pattern
empower.enhance = enhance;
empower.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
return empower;
}));

@@ -24,17 +24,4 @@ /**

var widthOf = function (str) {
var i, c, width = 0;
for(i = 0; i < str.length; i+=1){
c = str.charCodeAt(i);
if ((0x0 <= c && c < 0x81) || (c == 0xf8f0) || (0xff61 <= c && c < 0xffa0) || (0xf8f1 <= c && c < 0xf8f4)) {
width += 1;
} else {
width += 2;
}
}
return width;
};
var newRowFor = (function () {
var createRow = function (numCols, initial) {
function createRow (numCols, initial) {
var row = [], i;

@@ -45,3 +32,3 @@ for(i = 0; i < numCols; i += 1) {

return row;
};
}
return function (assertionLine) {

@@ -52,5 +39,18 @@ return createRow(widthOf(assertionLine), ' ');

var isOverlapped = function (prevCapturing, nextCaputuring, dumpedValue) {
function widthOf (str) {
var i, c, width = 0;
for(i = 0; i < str.length; i+=1){
c = str.charCodeAt(i);
if ((0x0 <= c && c < 0x81) || (c === 0xf8f0) || (0xff61 <= c && c < 0xffa0) || (0xf8f1 <= c && c < 0xf8f4)) {
width += 1;
} else {
width += 2;
}
}
return width;
}
function isOverlapped (prevCapturing, nextCaputuring, dumpedValue) {
return (typeof prevCapturing !== 'undefined') && prevCapturing.location.start.column <= (nextCaputuring.location.start.column + widthOf(dumpedValue));
};
}

@@ -83,4 +83,4 @@ function rightToLeft (a, b) {

PowerAssertContextRenderer.prototype.renderVerticalBarAt = function (columnIndex) {
var lastRowIndex = this.rows.length - 1;
for (var i = 0; i < lastRowIndex; i += 1) {
var i, lastRowIndex = this.rows.length - 1;
for (i = 0; i < lastRowIndex; i += 1) {
this.rows[i].splice(columnIndex, 1, '|');

@@ -90,4 +90,4 @@ }

PowerAssertContextRenderer.prototype.renderValueAt = function (columnIndex, dumpedValue) {
var width = widthOf(dumpedValue);
for (var i = 0; i < width; i += 1) {
var i, width = widthOf(dumpedValue);
for (i = 0; i < width; i += 1) {
this.lastRow().splice(columnIndex + i, 1, dumpedValue.charAt(i));

@@ -130,3 +130,3 @@ }

replacer = function(key, val) {
if (typeof val == "object" && val) {
if (typeof val === 'object' && val) {
if (seen.indexOf(val) !== -1) {

@@ -133,0 +133,0 @@ return '#Circular#';

{
"name": "empower",
"description": "Power Assert feature enhancer for assert function/object",
"version": "0.1.2",
"version": "0.1.3",
"keywords": [

@@ -28,9 +28,10 @@ "test",

"devDependencies": {
"espower": "~0.1.1",
"espower": "~0.1.2",
"esprima": "1.0.3",
"escodegen": "0.0.24",
"escodegen": "0.0.26",
"coffee-script-redux": "2.0.0-beta6",
"qunitjs": "1.10.0",
"qunit-tap": "1.4.0",
"grunt": "~0.4.1"
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.4"
},

@@ -37,0 +38,0 @@ "licenses": [

@@ -7,3 +7,3 @@ empower

Power Assert feature enhancer for assert function/object
Power Assert feature enhancer for assert function/object.

@@ -13,3 +13,3 @@

---------------------------------------
`empower` is a core module of `power-assert` family. `empower` enhances standard `assert` function or any assert-like object to work with power-assert feature added code instrumented by `espower`. `empower` module also provides a default formatter for power-assert output.
`empower` is a core module of [power-assert](http://github.com/twada/power-assert) family. `empower` enhances standard `assert` function or any assert-like object to work with power-assert feature added code instrumented by [espower](http://github.com/twada/espower). `empower` module also provides a default formatter for power-assert output.

@@ -16,0 +16,0 @@

@@ -5,2 +5,15 @@ var q = require('../test_helper').QUnit,

q.module('empower.DEFAULT_OPTIONS');
q.test('destructive: false', function () {
var options = empower.DEFAULT_OPTIONS;
q.equal(options.destructive, false);
});
q.test('formatter: power-assert-formatter module', function () {
var options = empower.DEFAULT_OPTIONS;
q.deepEqual(options.formatter, require('../lib/power-assert-formatter'));
});
q.module('assert object empowerment');

@@ -7,0 +20,0 @@

@@ -234,4 +234,5 @@ var q = require('../test_helper').QUnit,

'assert(5 < actual && actual < 13);',
' | | | | ',
' | 16 16 false ',
' | | | | | ',
' | | | 16 false ',
' | 16 false ',
' true ',

@@ -250,5 +251,6 @@ ''

'assert.ok(actual < 5 || 13 < actual);',
' | | | | ',
' | | | 10 ',
' 10 false false ',
' | | | | | ',
' | | | | 10 ',
' | | false false ',
' 10 false ',
''

@@ -266,4 +268,4 @@ ]);

'assert(2 > actual && actual < 13);',
' | | ',
' | 5 ',
' | | | ',
' | 5 false ',
' false ',

@@ -596,1 +598,116 @@ ''

});
q.test('UnaryExpression of UnaryExpression: assert(typeof + twoStr === -twoStr);', function () {
var twoStr = '2';
assert.ok(eval(instrument('assert(typeof + twoStr === -twoStr);')));
q.deepEqual(powerAssertTextLines, [
'# /path/to/some_test.js:1',
'',
'assert(typeof + twoStr === -twoStr);',
' | | | | || ',
' | | | | |"2" ',
' | | | | -2 ',
' | 2 "2" false ',
' "number" ',
''
]);
});
q.test('AssignmentExpression: assert(minusOne += 1);', function () {
var minusOne = -1;
assert.ok(eval(instrument('assert(minusOne += 1);')));
q.deepEqual(powerAssertTextLines, [
'# /path/to/some_test.js:1',
'',
'assert(minusOne += 1);',
' | ',
' 0 ',
''
]);
});
q.test('AssignmentExpression with MemberExpression: assert((dog.age += 1) === four);', function () {
var dog = { age: 2 }, four = 4;
assert.ok(eval(instrument('assert((dog.age += 1) === four);')));
q.deepEqual(powerAssertTextLines, [
'# /path/to/some_test.js:1',
'',
'assert((dog.age += 1) === four);',
' | | | ',
' | | 4 ',
' 3 false ',
''
]);
});
q.test('ArrayExpression: assert([foo, bar].length === four);', function () {
var foo = 'hoge', bar = 'fuga', four = 4;
assert.ok(eval(instrument('assert([foo, bar].length === four);')));
q.deepEqual(powerAssertTextLines, [
'# /path/to/some_test.js:1',
'',
'assert([foo, bar].length === four);',
' | | | | | ',
' | | | | 4 ',
' | | 2 false ',
' | "fuga" ',
' "hoge" ',
''
]);
});
q.test('various expressions in ArrayExpression: assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");', function () {
var foo = {bar: 'fuga'}, baz = function (arg) { return null; }, moo = 'boo', fourStr = '4';
assert.ok(eval(instrument('assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");')));
q.deepEqual(powerAssertTextLines, [
'# /path/to/some_test.js:1',
'',
'assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");',
' | | | | | | | | ',
' | | | | "boo" 4 "4" false ',
' | | | null ',
' | | "fuga" ',
' "object" {"bar":"fuga"} ',
''
]);
});
q.test('prefix UpdateExpression: assert(++minusOne);', function () {
var minusOne = -1;
assert.ok(eval(instrument('assert(++minusOne);')));
q.deepEqual(powerAssertTextLines, [
'# /path/to/some_test.js:1',
'',
'assert(++minusOne);',
' | ',
' 0 ',
''
]);
});
q.test('suffix UpdateExpression: assert(zero--);', function () {
var zero = 0;
assert.ok(eval(instrument('assert(zero--);')));
q.deepEqual(powerAssertTextLines, [
'# /path/to/some_test.js:1',
'',
'assert(zero--);',
' | ',
' 0 ',
''
]);
});
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