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

lazy-ass

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy-ass - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

bower.json
{
"name": "lazy-ass",
"main": "index.js",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "https://github.com/bahmutov/lazy-ass",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -6,11 +6,17 @@ (function initLazyAss() {

if (!condition) {
var msg = args.reduce(function (total, arg) {
var msg = args.reduce(function (total, arg, k) {
if (k) {
total += ' ';
}
if (typeof arg === 'string') {
return total + ' ' + arg;
return total + arg;
}
if (typeof arg === 'function') {
return total + ' ' + arg();
return total + arg();
}
return total;
});
if (Array.isArray(arg)) {
return total + JSON.stringify(arg);
}
return total + JSON.stringify(arg, null, 2);
}, '');
throw new Error(msg);

@@ -17,0 +23,0 @@ }

{
"name": "lazy-ass",
"description": "Lazy assertions without performance penalty",
"version": "0.1.0",
"version": "0.1.1",
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",

@@ -13,3 +13,3 @@ "bugs": {

"expect.js": "0.3.1",
"grunt": "0.4.4",
"grunt": "0.4.5",
"grunt-banner": "0.2.2",

@@ -19,19 +19,19 @@ "grunt-clean-console": "0.1.1",

"grunt-contrib-copy": "0.5.0",
"grunt-contrib-jshint": "0.9.2",
"grunt-contrib-jshint": "0.10.0",
"grunt-contrib-uglify": "0.4.0",
"grunt-contrib-watch": "0.6.1",
"grunt-deps-ok": "0.1.8",
"grunt-karma": "0.8.2",
"grunt-mocha-test": "0.10.0",
"grunt-nice-package": "0.3.0",
"grunt-npm2bower-sync": "^0.3.0",
"jshint-stylish": "^0.1.5",
"karma": "0.12.3",
"karma-coverage": "0.2.1",
"grunt-deps-ok": "0.2.0",
"grunt-karma": "0.8.3",
"grunt-mocha-test": "0.10.2",
"grunt-nice-package": "0.5.2",
"grunt-npm2bower-sync": "0.3.0",
"jshint-stylish": "0.2.0",
"karma": "0.12.16",
"karma-coverage": "0.2.2",
"karma-mocha": "0.1.3",
"karma-phantomjs-launcher": "0.1.4",
"matchdep": "0.3.0",
"mocha": "1.18.2",
"pre-git": "0.0.15",
"time-grunt": "0.2.10"
"mocha": "1.19.0",
"pre-git": "0.0.16",
"time-grunt": "0.3.1"
},

@@ -38,0 +38,0 @@ "engines": {

@@ -14,12 +14,15 @@ # lazy-ass

Regular assertions evaluate all arguments and concatenate message
EVERY time, even if the condition is true.
```js
console.assert(typeof foo === 'object,
console.assert(typeof foo === 'object',
'expected ' + JSON.stringify(foo, null, 2) + ' to be an object');
// message is stringified and concatenated EVERY time no matter the condition
```
// vs
Lazy assertion function only evaluates its arguments and forms
a message if condition is false
```js
lazyAss(typeof foo === 'object', 'expected', foo, 'to be an object');
// foo variable is stringified and message is concatenated ONLY
// if condition is false
```

@@ -26,0 +29,0 @@

@@ -14,3 +14,65 @@ if (typeof lazyAss === 'undefined') {

});
it('does not throw if condition is true', function () {
expect(function () {
lazyAss(true);
}).not.to.throwError();
});
it('does not evaluate function if condition is true', function () {
function foo() {
throw new Error('Foo has been called');
}
lazyAss(true, foo);
});
it('throws error with string', function () {
expect(function () {
lazyAss(false, 'foo');
}).to.throwException(/^foo$/);
});
it('adds spaces', function () {
expect(function () {
lazyAss(false, 'foo', 'bar');
}).to.throwException(/^foo bar$/);
});
it('calls functions to form message', function () {
var called = 0;
function foo() {
called += 1;
return 'foo';
}
expect(function () {
lazyAss(false, foo, 'bar', foo);
}).to.throwException(/^foo bar foo$/);
});
it('calls function each time', function () {
var called = 0;
function foo() {
called += 1;
return 'foo';
}
expect(function () {
lazyAss(false, foo, 'bar', foo);
}).to.throwException(function () {
expect(called).to.equal(2);
});
});
it('JSON stringifies arrays', function () {
expect(function () {
lazyAss(false, [1, 2, 3]);
}).to.throwException(/^\[1,2,3\]$/);
});
it('JSON stringifies objects', function () {
var obj = { foo: 'foo' };
expect(function () {
lazyAss(false, obj);
}).to.throwException(JSON.stringify(obj, null, 2));
});
});
});
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