Comparing version 0.4.1 to 0.5.0
var isArray = arg => Array.isArray(arg) | ||
var isEmptyArray = arg => Array.isArray(arg) && !arg.length | ||
var isEmptyArray = arg => isArray(arg) && !arg.length | ||
var isNotEmptyArray = arg => !isEmptyArray(arg) | ||
var isNotEmptyArray = arg => isArray(arg) && !isEmptyArray(arg) | ||
@@ -11,2 +11,2 @@ module.exports = { | ||
isNotEmptyArray: isNotEmptyArray | ||
} | ||
} |
@@ -9,2 +9,6 @@ var isNumber = arg => typeof arg === 'number' && isFinite(arg) | ||
var isEven = arg => isInt(arg) && !(arg % 2) | ||
var isOdd = arg => isInt(arg) && !!(arg % 2) | ||
module.exports = { | ||
@@ -14,3 +18,5 @@ isNumber: isNumber, | ||
isInt: isInt, | ||
isNotInt: isNotInt | ||
isNotInt: isNotInt, | ||
isEven: isEven, | ||
isOdd: isOdd | ||
} |
{ | ||
"name": "isnot", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "All imaginable type checking utils with negation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -54,5 +54,9 @@ # isnot | ||
isEmptyArray(['1']) // false | ||
isEmptyArray({}) // false | ||
isNotEmptyArray([]) // false | ||
isNotEmptyArray([1]) // true | ||
isNotEmptyArray({}) // false | ||
~~~ | ||
@@ -59,0 +63,0 @@ |
var expect = require("chai").expect; | ||
const {isArray, isEmptyArray} = require("../lib/arrays"); | ||
const {isArray, isEmptyArray, isNotEmptyArray} = require("../lib/arrays"); | ||
describe("Test Arrays utilities", function() { | ||
describe("isArray", function() { | ||
it("checks correctly", function() { | ||
expect(isArray([])).to.equal(true); | ||
expect(isArray([1,2,3])).to.equal(true); | ||
expect(isArray(['1','2','3'])).to.equal(true); | ||
expect(isArray({})).to.equal(false); | ||
expect(isArray([{}])).to.equal(true); | ||
expect(isArray(null)).to.equal(false); | ||
expect(isArray(undefined)).to.equal(false); | ||
expect(isArray(()=>{})).to.equal(false); | ||
}); | ||
it("checks correctly", function() { | ||
expect(isArray([])).to.equal(true); | ||
expect(isArray([1,2,3])).to.equal(true); | ||
expect(isArray(['1','2','3'])).to.equal(true); | ||
expect(isArray({})).to.equal(false); | ||
expect(isArray([{}])).to.equal(true); | ||
expect(isArray(null)).to.equal(false); | ||
expect(isArray(undefined)).to.equal(false); | ||
expect(isArray(()=>{})).to.equal(false); | ||
}); | ||
}); | ||
describe("isEmptyArray", function() { | ||
it("checks correctly", function() { | ||
expect(isEmptyArray([])).to.equal(true); | ||
expect(isEmptyArray([1,2,3])).to.equal(false); | ||
expect(isEmptyArray(['1','2','3'])).to.equal(false); | ||
expect(isEmptyArray({})).to.equal(false); | ||
expect(isEmptyArray([{}])).to.equal(false); | ||
expect(isEmptyArray(null)).to.equal(false); | ||
expect(isEmptyArray(undefined)).to.equal(false); | ||
expect(isEmptyArray(()=>{})).to.equal(false); | ||
}); | ||
it("checks correctly", function() { | ||
expect(isEmptyArray([])).to.equal(true); | ||
expect(isEmptyArray([1,2,3])).to.equal(false); | ||
expect(isEmptyArray(['1','2','3'])).to.equal(false); | ||
expect(isEmptyArray({})).to.equal(false); | ||
expect(isEmptyArray([{}])).to.equal(false); | ||
expect(isEmptyArray(null)).to.equal(false); | ||
expect(isEmptyArray(undefined)).to.equal(false); | ||
expect(isEmptyArray(()=>{})).to.equal(false); | ||
}); | ||
}); | ||
}); | ||
describe("isNotEmptyArray", function() { | ||
it("checks correctly", function() { | ||
expect(isNotEmptyArray([])).to.equal(false); | ||
expect(isNotEmptyArray([1,2,3])).to.equal(true); | ||
expect(isNotEmptyArray(['1','2','3'])).to.equal(true); | ||
expect(isNotEmptyArray({})).to.equal(false); | ||
expect(isNotEmptyArray([{}])).to.equal(true); | ||
expect(isNotEmptyArray(null)).to.equal(false); | ||
expect(isNotEmptyArray(undefined)).to.equal(false); | ||
expect(isNotEmptyArray(()=>{})).to.equal(false); | ||
}); | ||
}); | ||
}); |
var expect = require("chai").expect; | ||
const {isInt, isNotInt, isNumber, isNotNumber} = require("../lib/numbers"); | ||
const {isInt, isNotInt, isNumber, isNotNumber, isOdd, isEven} = require("../lib/numbers"); | ||
@@ -29,2 +29,8 @@ | ||
}); | ||
describe("isNotNumber", function() { | ||
it("checks correctly", function() { | ||
expect(isNotNumber('string')).to.equal(true); | ||
expect(isNotNumber(1)).to.equal(false); | ||
}); | ||
}); | ||
describe("isInt", function() { | ||
@@ -53,2 +59,26 @@ it("checks correctly", function() { | ||
}); | ||
describe("isNotInt", function() { | ||
it("checks correctly", function() { | ||
expect(isNotInt('string')).to.equal(true); | ||
expect(isNotInt(1.1)).to.equal(true); | ||
expect(isNotInt(1)).to.equal(false); | ||
}); | ||
}); | ||
describe("isOdd", function() { | ||
it("checks correctly", function() { | ||
expect(isOdd('string')).to.equal(false); | ||
expect(isOdd(1)).to.equal(true); | ||
expect(isOdd(1.1)).to.equal(false); | ||
expect(isOdd(-1-2)).to.equal(true); | ||
}); | ||
}); | ||
describe("isEven", function() { | ||
it("checks correctly", function() { | ||
expect(isEven('string')).to.equal(false); | ||
expect(isEven(1)).to.equal(false); | ||
expect(isEven(0)).to.equal(true); | ||
expect(isEven(Infinity)).to.equal(false); | ||
expect(isEven(-0)).to.equal(true); | ||
}); | ||
}); | ||
}); |
24201
579
160