+74
| ## changelog | ||
| #### 0.10.0 | ||
| - Added `is.primitive` ([@tgriesser](https://twitter.com/tgriesser)) | ||
| - Update docs with `is.empty` ([@BlaineBublitz](https://twitter.com/BlaineBublitz)) | ||
| - `is.empty` now throws for invalid types | ||
| #### 0.9.0 | ||
| - Added `is.is` based off polyfill from MDN | ||
| - Added alias for `is.object` and `is.arr` | ||
| - `is.num(NaN)` now returns false | ||
| #### 0.8.2 | ||
| - Correctly test for NaN in `is.contains` | ||
| #### 0.8.1 | ||
| - Fix currying issue with `is.not` | ||
| #### 0.8.0 | ||
| - Added `is.curry` which is used internally | ||
| - Added autocurrying for all functions that are arity 2 | ||
| - `is.complement` can now return a function instead of just `booleans` | ||
| - `is.truthy` and `is.falsey` now respect js falsey values (eg 0, '', etc) | ||
| #### 0.7.3 | ||
| - Refactored file structure | ||
| #### 0.7.2 | ||
| - Update docs | ||
| #### 0.7.1 | ||
| - Converted module to node style package | ||
| - build process uses browserify standalone | ||
| - Tests now in JS instead of CS (run much faster!) | ||
| - Internal changes around chaining | ||
| - Dropped gulp | ||
| #### 0.7.0 | ||
| - Added `even`, `odd` | ||
| - Exposed `mod` | ||
| - Even more improved docs! | ||
| #### 0.6.0 | ||
| - Removed `cmp` | ||
| - Added `is.empty` | ||
| - Alias `is.invert` as `is.complement` | ||
| - Expose `is.partial` from internals | ||
| - Improved docs | ||
| #### 0.5.0 | ||
| - Added `is.zero` | ||
| - Fix `is.object` and `is.error` | ||
| - `is.ternary` now supports partial application | ||
| - `is.gt`, `is.gtEq`, `is.lt`, `is.ltEq` aliases added | ||
| #### 0.4.0 | ||
| - Support for lazy chain evaluation | ||
| #### 0.3.0 | ||
| - Expose `is.invert | ||
| - Added `is.contains | ||
| - Added `is.has | ||
| - Remove bower support | ||
| #### 0.2.0 | ||
| - Added `is.pos` | ||
| - Added `is.neg` | ||
| - Added `is.ternary` | ||
| - Added `is.not`, which inverses all boolean returning predicate methods | ||
| #### 0.1.1 | ||
| - Added is.bool/boolean method | ||
| #### 0.1.0 | ||
| - Release |
| ## How to contribute to is.js | ||
| * Before you open a ticket or send a pull request, [search](https://github.com/landau/is/issues) for previous discussions about the same feature or issue. Add to the earlier ticket if you find one. | ||
| * Before sending a pull request for a feature, be sure to add tests. | ||
| * Use the same coding style as the rest of the codebase. | ||
| * In your pull request, do not add documentation or re-build the distributed versions. I'll do those things before cutting a new release. | ||
+338
| /** | ||
| * @license is.js | ||
| * (c) 2014 Trevor Landau <landautrevor@gmail.com> @trevor_landau | ||
| * is.js may be freely distributed under the MIT license. | ||
| */ | ||
| !function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.is=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
| 'use strict'; | ||
| var utils = _dereq_('./lib/utils'); | ||
| var is = {}; | ||
| is.VERSION = '0.10.1'; | ||
| [ | ||
| utils, | ||
| _dereq_('./lib/predicates'), | ||
| _dereq_('./lib/chain'), | ||
| _dereq_('./lib/other'), | ||
| ].reduce(utils.assign, is); | ||
| module.exports = is; | ||
| },{"./lib/chain":2,"./lib/other":3,"./lib/predicates":4,"./lib/utils":5}],2:[function(_dereq_,module,exports){ | ||
| 'use strict'; | ||
| var utils = _dereq_('./utils'); | ||
| var predicates = _dereq_('./predicates'); | ||
| var is = module.exports; | ||
| // chaining mixin | ||
| function lazy() { | ||
| /* jshint validthis:true */ | ||
| // Enable invocation with operators (+, !, etc) | ||
| this.valueOf = function () { | ||
| return this.val(); | ||
| }; | ||
| this.val = function () { | ||
| return this.lazy.map(function (args) { | ||
| return args[0].apply(null, args[1]); | ||
| })[this.method](predicates.truthy); | ||
| }; | ||
| return this; | ||
| } | ||
| function Every() { | ||
| this.method = 'every'; | ||
| this.lazy = []; | ||
| } | ||
| Every.prototype = Object.keys(predicates).reduce(function (acc, fnName) { | ||
| if (!predicates.fn(predicates[fnName])) return acc; | ||
| acc[fnName] = function() { | ||
| this.lazy.push([predicates[fnName], arguments]); | ||
| return this; | ||
| }; | ||
| return acc; | ||
| }, {}); | ||
| lazy.call(Every.prototype); | ||
| is.all = is.every = function () { | ||
| return new Every(); | ||
| }; | ||
| function Some() { | ||
| this.method = 'some'; | ||
| this.lazy = []; | ||
| } | ||
| Some.prototype = utils.assign({}, Every.prototype); | ||
| lazy.call(Some.prototype); | ||
| is.any = is.some = function () { | ||
| return new Some(); | ||
| }; | ||
| },{"./predicates":4,"./utils":5}],3:[function(_dereq_,module,exports){ | ||
| 'use strict'; | ||
| var predicates = _dereq_('./predicates'); | ||
| var utils = _dereq_('./utils'); | ||
| var is = module.exports; | ||
| is.ternary = function (pred, a, b) { | ||
| if (predicates.bool(pred)) return pred ? a : b; | ||
| if (predicates.undef(a)) return utils.partial(is.ternary, pred); | ||
| if (predicates.undef(b)) return utils.partial(is.ternary, pred, a); | ||
| return is.ternary(pred(a, b), a, b); | ||
| }; | ||
| },{"./predicates":4,"./utils":5}],4:[function(_dereq_,module,exports){ | ||
| 'use strict'; | ||
| var utils = _dereq_('./utils'); | ||
| var is = module.exports; | ||
| var curry = utils.curry; | ||
| if (Object.is) { | ||
| is.is = curry(Object.is); | ||
| } else { | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
| is.is = curry(function(v1, v2) { | ||
| if (v1 === 0 && v2 === 0) { | ||
| return 1 / v1 === 1 / v2; | ||
| } | ||
| if (v1 !== v1) { | ||
| return v2 !== v2; | ||
| } | ||
| return v1 === v2; | ||
| }); | ||
| } | ||
| is.exists = function (val) { | ||
| return val != null; | ||
| }; | ||
| is.truthy = function (val) { | ||
| // coerce for null != null | ||
| return !!(val && is.exists(val)); | ||
| }; | ||
| is.falsey = utils.complement(is.truthy); | ||
| //---- value comparision methods | ||
| is.equal = curry(function (a, b) { | ||
| return a === b; | ||
| }); | ||
| is.eq = curry(function (a, b) { | ||
| return a == b; | ||
| }); | ||
| is.null = is.equal(null); | ||
| is.undef = is.equal(undefined); | ||
| is.lt = is.less = curry(function (a, b) { | ||
| return a < b; | ||
| }); | ||
| is.ltEq = is.lessEq = curry(function (a, b) { | ||
| return is.equal(a, b) || is.less(a, b); | ||
| }); | ||
| is.gt = is.greater = curry(function (a, b) { | ||
| return a > b; | ||
| }); | ||
| is.gtEq = is.greaterEq = curry(function (a, b) { | ||
| return is.equal(a, b) || is.greater(a, b); | ||
| }); | ||
| // --- Type checking predicates | ||
| // Forces objects toString called returned as [object Object] for instance | ||
| var __toString = Object.prototype.toString; | ||
| var eqToStr = curry(function(str, val) { | ||
| return is.equal(str, __toString.call(val)); | ||
| }); | ||
| //---- Object type checks | ||
| is.object = is.obj = function (val) { | ||
| return val === Object(val); | ||
| }; | ||
| is.array = is.arr = Array.isArray || eqToStr('[object Array]'); | ||
| is.date = eqToStr('[object Date]'); | ||
| is.rgx = is.RegExp = eqToStr('[object RegExp]'); | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite | ||
| is.finite = Number.isFinite || function (val) { | ||
| return is.number(val) && isFinite(val); | ||
| }; | ||
| is.NaN = is.is(NaN); | ||
| is.instance = curry(function (Cls, inst) { | ||
| return inst instanceof Cls; | ||
| }); | ||
| is.arguments = eqToStr('[object Arguments]'); | ||
| is.error = is.instance(Error); | ||
| // creates fns for is.string, etc | ||
| var typeofBuilder = curry(function(type, val) { | ||
| return is.equal(type, typeof val); | ||
| }); | ||
| //--- Create typeof methods | ||
| // type of string and alias name | ||
| // is.fn, is.num, etc | ||
| [ | ||
| ['function', 'fn'], | ||
| ['string', 'str'], | ||
| ['boolean', 'bool'] | ||
| ].reduce(function (is, type) { | ||
| is[type[0]] = is[type[1]] = typeofBuilder(type[0]); | ||
| return is; | ||
| }, is); | ||
| is.number = is.num = function(val) { | ||
| return typeof val === 'number' && is.not.NaN(val); | ||
| }; | ||
| is.int = function (val) { | ||
| return is.num(val) && is.zero(utils.mod(val, 1)); | ||
| }; | ||
| is.pos = function (val) { | ||
| return is.num(val) && is.greater(val, 0); | ||
| }; | ||
| is.neg = function (val) { | ||
| return is.num(val) && is.less(val, 0); | ||
| }; | ||
| is.zero = function (val) { | ||
| return is.num(val) && is.equal(val, 0); | ||
| }; | ||
| is.even = function (val) { | ||
| return is.num(val) && | ||
| is.not.zero(val) && | ||
| is.zero(utils.mod(val, 2)); | ||
| }; | ||
| is.odd = function (val) { | ||
| return is.num(val) && | ||
| is.not.zero(val) && | ||
| is.not.zero(utils.mod(val, 2)); | ||
| }; | ||
| is.contains = curry(function (arr, val) { | ||
| if (!is.array(arr)) throw new TypeError('Expected an array'); | ||
| if (is.NaN(val)) { | ||
| return arr.some(is.NaN); | ||
| } | ||
| return !!~arr.indexOf(val); | ||
| }); | ||
| var __has = Object.prototype.hasOwnProperty; | ||
| is.has = curry(function has(o, key) { | ||
| return __has.call(o, key); | ||
| }); | ||
| is.empty = function (o) { | ||
| if (is.not.exists(o)) return true; | ||
| if (is.arr(o) || is.str(o)) return !o.length; | ||
| if (is.obj(o)) { | ||
| for (var k in o) if (is.has(o, k)) return false; | ||
| return true; | ||
| } | ||
| throw new TypeError(); | ||
| }; | ||
| is.primitive = function (val) { | ||
| return is.string(val) || is.num(val) || is.bool(val) || | ||
| is.null(val) || is.undef(val) || is.NaN(val); | ||
| }; | ||
| // Assign inverse of each predicate | ||
| is.not = Object.keys(is).reduce(function (acc, fnName) { | ||
| acc[fnName] = utils.complement(is[fnName]); | ||
| return acc; | ||
| }, {}); | ||
| },{"./utils":5}],5:[function(_dereq_,module,exports){ | ||
| 'use strict'; | ||
| var is = module.exports; | ||
| var _slice = Array.prototype.slice; | ||
| // Useful for debuging curried functions | ||
| function setSrc(curried, src) { | ||
| curried.toString = function() { | ||
| return src.toString(); | ||
| }; | ||
| curried.src = src; | ||
| return curried; | ||
| } | ||
| // Curry's fn's with arity 2 | ||
| var curry = is.curry = function(f) { | ||
| return setSrc(function curried(a, b) { | ||
| switch (arguments.length) { | ||
| case 0: throw new TypeError('Function called with no arguments'); | ||
| case 1: | ||
| return setSrc(function curried(b) { | ||
| return f(a, b); | ||
| }, f); | ||
| } | ||
| return f(a, b); | ||
| }, f); | ||
| }; | ||
| is.partial = function (fn) { | ||
| var args = _slice.call(arguments, 1); | ||
| return function() { | ||
| return fn.apply(null, args.concat(_slice.call(arguments))); | ||
| }; | ||
| }; | ||
| is.complement = is.invert = function (pred) { | ||
| return function () { | ||
| var ret = pred.apply(null, arguments); | ||
| // Handle curried fns | ||
| if (typeof ret === 'function') return is.complement(ret); | ||
| return !ret; | ||
| }; | ||
| }; | ||
| is.mod = curry(function (a, b) { | ||
| return a % b; | ||
| }); | ||
| // assign b's props to a | ||
| is.assign = curry(function(a, b) { | ||
| // use crummy for/in for perf purposes | ||
| for (var prop in b) { | ||
| if (b.hasOwnProperty(prop)) { | ||
| a[prop] = b[prop]; | ||
| } | ||
| } | ||
| return a; | ||
| }); | ||
| },{}]},{},[1]) | ||
| (1) | ||
| }); |
| /** | ||
| * @license is.js | ||
| * (c) 2014 Trevor Landau <landautrevor@gmail.com> @trevor_landau | ||
| * is.js may be freely distributed under the MIT license. | ||
| */ | ||
| !function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.is=e()}}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(_dereq_,module,exports){"use strict";var utils=_dereq_("./lib/utils");var is={};is.VERSION="0.10.1";[utils,_dereq_("./lib/predicates"),_dereq_("./lib/chain"),_dereq_("./lib/other")].reduce(utils.assign,is);module.exports=is},{"./lib/chain":2,"./lib/other":3,"./lib/predicates":4,"./lib/utils":5}],2:[function(_dereq_,module,exports){"use strict";var utils=_dereq_("./utils");var predicates=_dereq_("./predicates");var is=module.exports;function lazy(){this.valueOf=function(){return this.val()};this.val=function(){return this.lazy.map(function(args){return args[0].apply(null,args[1])})[this.method](predicates.truthy)};return this}function Every(){this.method="every";this.lazy=[]}Every.prototype=Object.keys(predicates).reduce(function(acc,fnName){if(!predicates.fn(predicates[fnName]))return acc;acc[fnName]=function(){this.lazy.push([predicates[fnName],arguments]);return this};return acc},{});lazy.call(Every.prototype);is.all=is.every=function(){return new Every};function Some(){this.method="some";this.lazy=[]}Some.prototype=utils.assign({},Every.prototype);lazy.call(Some.prototype);is.any=is.some=function(){return new Some}},{"./predicates":4,"./utils":5}],3:[function(_dereq_,module,exports){"use strict";var predicates=_dereq_("./predicates");var utils=_dereq_("./utils");var is=module.exports;is.ternary=function(pred,a,b){if(predicates.bool(pred))return pred?a:b;if(predicates.undef(a))return utils.partial(is.ternary,pred);if(predicates.undef(b))return utils.partial(is.ternary,pred,a);return is.ternary(pred(a,b),a,b)}},{"./predicates":4,"./utils":5}],4:[function(_dereq_,module,exports){"use strict";var utils=_dereq_("./utils");var is=module.exports;var curry=utils.curry;if(Object.is){is.is=curry(Object.is)}else{is.is=curry(function(v1,v2){if(v1===0&&v2===0){return 1/v1===1/v2}if(v1!==v1){return v2!==v2}return v1===v2})}is.exists=function(val){return val!=null};is.truthy=function(val){return!!(val&&is.exists(val))};is.falsey=utils.complement(is.truthy);is.equal=curry(function(a,b){return a===b});is.eq=curry(function(a,b){return a==b});is.null=is.equal(null);is.undef=is.equal(undefined);is.lt=is.less=curry(function(a,b){return a<b});is.ltEq=is.lessEq=curry(function(a,b){return is.equal(a,b)||is.less(a,b)});is.gt=is.greater=curry(function(a,b){return a>b});is.gtEq=is.greaterEq=curry(function(a,b){return is.equal(a,b)||is.greater(a,b)});var __toString=Object.prototype.toString;var eqToStr=curry(function(str,val){return is.equal(str,__toString.call(val))});is.object=is.obj=function(val){return val===Object(val)};is.array=is.arr=Array.isArray||eqToStr("[object Array]");is.date=eqToStr("[object Date]");is.rgx=is.RegExp=eqToStr("[object RegExp]");is.finite=Number.isFinite||function(val){return is.number(val)&&isFinite(val)};is.NaN=is.is(NaN);is.instance=curry(function(Cls,inst){return inst instanceof Cls});is.arguments=eqToStr("[object Arguments]");is.error=is.instance(Error);var typeofBuilder=curry(function(type,val){return is.equal(type,typeof val)});[["function","fn"],["string","str"],["boolean","bool"]].reduce(function(is,type){is[type[0]]=is[type[1]]=typeofBuilder(type[0]);return is},is);is.number=is.num=function(val){return typeof val==="number"&&is.not.NaN(val)};is.int=function(val){return is.num(val)&&is.zero(utils.mod(val,1))};is.pos=function(val){return is.num(val)&&is.greater(val,0)};is.neg=function(val){return is.num(val)&&is.less(val,0)};is.zero=function(val){return is.num(val)&&is.equal(val,0)};is.even=function(val){return is.num(val)&&is.not.zero(val)&&is.zero(utils.mod(val,2))};is.odd=function(val){return is.num(val)&&is.not.zero(val)&&is.not.zero(utils.mod(val,2))};is.contains=curry(function(arr,val){if(!is.array(arr))throw new TypeError("Expected an array");if(is.NaN(val)){return arr.some(is.NaN)}return!!~arr.indexOf(val)});var __has=Object.prototype.hasOwnProperty;is.has=curry(function has(o,key){return __has.call(o,key)});is.empty=function(o){if(is.not.exists(o))return true;if(is.arr(o)||is.str(o))return!o.length;if(is.obj(o)){for(var k in o)if(is.has(o,k))return false;return true}throw new TypeError};is.primitive=function(val){return is.string(val)||is.num(val)||is.bool(val)||is.null(val)||is.undef(val)||is.NaN(val)};is.not=Object.keys(is).reduce(function(acc,fnName){acc[fnName]=utils.complement(is[fnName]);return acc},{})},{"./utils":5}],5:[function(_dereq_,module,exports){"use strict";var is=module.exports;var _slice=Array.prototype.slice;function setSrc(curried,src){curried.toString=function(){return src.toString()};curried.src=src;return curried}var curry=is.curry=function(f){return setSrc(function curried(a,b){switch(arguments.length){case 0:throw new TypeError("Function called with no arguments");case 1:return setSrc(function curried(b){return f(a,b)},f)}return f(a,b)},f)};is.partial=function(fn){var args=_slice.call(arguments,1);return function(){return fn.apply(null,args.concat(_slice.call(arguments)))}};is.complement=is.invert=function(pred){return function(){var ret=pred.apply(null,arguments);if(typeof ret==="function")return is.complement(ret);return!ret}};is.mod=curry(function(a,b){return a%b});is.assign=curry(function(a,b){for(var prop in b){if(b.hasOwnProperty(prop)){a[prop]=b[prop]}}return a})},{}]},{},[1])(1)}); |
| /** | ||
| * @license is.js | ||
| * (c) 2014 Trevor Landau <landautrevor@gmail.com> @trevor_landau | ||
| * is.js may be freely distributed under the MIT license. | ||
| */ |
| a(name='changelog') | ||
| .changelog | ||
| :markdown | ||
| ## changelog | ||
| #### 0.10.0 | ||
| - Added `is.primitive` ([@tgriesser](https://twitter.com/tgriesser)) | ||
| - Update docs with `is.empty` ([@BlaineBublitz](https://twitter.com/BlaineBublitz)) | ||
| - `is.empty` now throws for invalid types | ||
| #### 0.9.0 | ||
| - Added `is.is` based off polyfill from MDN | ||
| - Added alias for `is.object` and `is.arr` | ||
| - `is.num(NaN)` now returns false | ||
| #### 0.8.2 | ||
| - Correctly test for NaN in `is.contains` | ||
| #### 0.8.1 | ||
| - Fix currying issue with `is.not` | ||
| #### 0.8.0 | ||
| - Added `is.curry` which is used internally | ||
| - Added autocurrying for all functions that are arity 2 | ||
| - `is.complement` can now return a function instead of just `booleans` | ||
| - `is.truthy` and `is.falsey` now respect js falsey values (eg 0, '', etc) | ||
| #### 0.7.3 | ||
| - Refactored file structure | ||
| #### 0.7.2 | ||
| - Update docs | ||
| #### 0.7.1 | ||
| - Converted module to node style package | ||
| - build process uses browserify standalone | ||
| - Tests now in JS instead of CS (run much faster!) | ||
| - Internal changes around chaining | ||
| - Dropped gulp | ||
| #### 0.7.0 | ||
| - Added `even`, `odd` | ||
| - Exposed `mod` | ||
| - Even more improved docs! | ||
| #### 0.6.0 | ||
| - Removed `cmp` | ||
| - Added `is.empty` | ||
| - Alias `is.invert` as `is.complement` | ||
| - Expose `is.partial` from internals | ||
| - Improved docs | ||
| #### 0.5.0 | ||
| - Added `is.zero` | ||
| - Fix `is.object` and `is.error` | ||
| - `is.ternary` now supports partial application | ||
| - `is.gt`, `is.gtEq`, `is.lt`, `is.ltEq` aliases added | ||
| #### 0.4.0 | ||
| - Support for lazy chain evaluation | ||
| #### 0.3.0 | ||
| - Expose `is.invert | ||
| - Added `is.contains | ||
| - Added `is.has | ||
| - Remove bower support | ||
| #### 0.2.0 | ||
| - Added `is.pos` | ||
| - Added `is.neg` | ||
| - Added `is.ternary` | ||
| - Added `is.not`, which inverses all boolean returning predicate methods | ||
| #### 0.1.1 | ||
| - Added is.bool/boolean method | ||
| #### 0.1.0 | ||
| - Release |
+886
| a(name='predicates') | ||
| h1 Predicates | ||
| hr | ||
| .panel.panel-default | ||
| a(name='not') | ||
| .panel-heading | ||
| h4 not | ||
| small: code is.not | ||
| .panel-body | ||
| :markdown | ||
| A complemented version of the `is` predicate functions. | ||
| All predicate functions are available in this namespace. | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.null(null) // true | ||
| is.not.null(null) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='is') | ||
| .panel-heading | ||
| h4 is | ||
| small: code is.is(a, b) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `Object.is(a, b)` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.is(window, window) // true | ||
| is.is(1, 1) // true | ||
| is.is(NaN, 0/0) // true | ||
| is.is(0, -0) // false | ||
| is.is([], []) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='exists') | ||
| .panel-heading | ||
| h4 exists | ||
| small: code is.exists(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if a value is not `null` or `undefined` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.exists(null) // false | ||
| is.exists(false) // true | ||
| is.exists(0) // true | ||
| is.exists('javascript') // true | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='truthy') | ||
| .panel-heading | ||
| h4 truthy | ||
| small: code is.truthy(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if a value `exists` and isn't `false` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.truthy(0) // true | ||
| is.truthy([1, 2]) // true | ||
| is.truthy(false) // false | ||
| is.truthy(null) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='falsey') | ||
| .panel-heading | ||
| h4 falsey | ||
| small: code is.falsey(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if a value is `false` or `doesn't exist` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.falsey(0) // false | ||
| is.falsey([1, 2]) // false | ||
| is.falsey(false) // true | ||
| is.falsey(null) // true | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='null') | ||
| .panel-heading | ||
| h4 null | ||
| small: code is.null(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if a value is `null` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.null(null) // true | ||
| is.null(false) // false | ||
| is.null(undefined) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='undef') | ||
| .panel-heading | ||
| h4 undef | ||
| small: code is.undef(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if a value is `undefined` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.undef(undefined) // true | ||
| is.undef(null) // false | ||
| is.undef(false) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='equal') | ||
| .panel-heading | ||
| h4 equal | ||
| small: code is.equal(a, b) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `a === b` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.equal(1, 1) // true | ||
| is.equal('a', 'a') // true | ||
| is.equal(null, 1) // false | ||
| is.equal([1, 2], [1, 2]) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='eq') | ||
| .panel-heading | ||
| h4 eq | ||
| small: code is.eq(a, b) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `a == b` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.eq('1', 1) // true | ||
| is.eq('a', 'b') // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='less') | ||
| .panel-heading | ||
| h4 less | ||
| small: code is.less(a, b) | ||
| small alias | ||
| code is.lt(a, b) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `a < b` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.less(1, 5) // true | ||
| is.less(5, 5) // false | ||
| is.less(5, 1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='lessEq') | ||
| .panel-heading | ||
| h4 lessEq | ||
| small: code is.lessEq(a, b) | ||
| small alias | ||
| code is.ltEq(a, b) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `a <= b` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.lessEq(1, 5) // true | ||
| is.lessEq(5, 5) // true | ||
| is.lessEq(5, 1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='greater') | ||
| .panel-heading | ||
| h4 greater | ||
| small: code is.greater(a, b) | ||
| small alias | ||
| code is.gt(a, b) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `a > b` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.greater(5, 1) // true | ||
| is.greater(5, 5) // false | ||
| is.greater(1, 5) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='greaterEq') | ||
| .panel-heading | ||
| h4 greaterEq | ||
| small: code is.greaterEq(a, b) | ||
| small alias | ||
| code is.gtEq(a, b) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `a > b` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.greaterEq(5, 1) // true | ||
| is.greaterEq(5, 5) // true | ||
| is.greaterEq(1, 5) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='object') | ||
| .panel-heading | ||
| h4 object | ||
| small: code is.object(val) | ||
| small alias | ||
| code is.obj(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is an object | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.object({}) // true | ||
| is.object([]) // true | ||
| is.object(1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='array') | ||
| .panel-heading | ||
| h4 array | ||
| small: code is.array(val) | ||
| small alias | ||
| code is.arr(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is an array | ||
| *Defaults to native* `Array.isArray` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.array([]) // true | ||
| is.array({}) // false | ||
| is.array(1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='date') | ||
| .panel-heading | ||
| h4 date | ||
| small: code is.date(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is a date | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.date(new Date()) // true | ||
| is.date({}) // false | ||
| is.date(1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='rgx') | ||
| .panel-heading | ||
| h4 rgx | ||
| small: code is.rgx(val) | ||
| small alias | ||
| code is.RegExp(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is a rgx | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.rgx(/\d{1,4}/) // true | ||
| is.rgx(new RegExp("Cosmos", "gi")) // true | ||
| is.rgx({}) // false | ||
| is.rgx("Dark Star") // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='finite') | ||
| .panel-heading | ||
| h4 finite | ||
| small: code is.finite(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is a `number` and `isFinite` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.finite(1) // true | ||
| is.finite(2e64) // true | ||
| is.finite(NaN) // false | ||
| is.finite('1') // false | ||
| is.finite(Infinity) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='NaN') | ||
| .panel-heading | ||
| h4 NaN | ||
| small: code is.NaN(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is `NaN` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.NaN(NaN) // true | ||
| is.NaN("titan") // false | ||
| is.NaN(1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='arguments') | ||
| .panel-heading | ||
| h4 arguments | ||
| small: code is.arguments(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is an `arguments` object | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.arguments(arguments) // true | ||
| is.arguments("titan") // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='error') | ||
| .panel-heading | ||
| h4 error | ||
| small: code is.error(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is an `error` object | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.error(new Error()) // true | ||
| is.error("titan") // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='fn') | ||
| .panel-heading | ||
| h4 fn | ||
| small: code is.fn(val) | ||
| small alias | ||
| code is.function(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `typeof val === 'function'` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.fn(is.fn) // true | ||
| is.fn(Math.max) // true | ||
| is.fn({}) // false | ||
| is.fn("Dark Star") // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='num') | ||
| .panel-heading | ||
| h4 num | ||
| small: code is.num(val) | ||
| small alias | ||
| code is.number(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `typeof val === 'number'` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.num(1) // true | ||
| is.num(NaN) // false | ||
| is.num({}) // false | ||
| is.num("Dark Star") // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='str') | ||
| .panel-heading | ||
| h4 str | ||
| small: code is.str(val) | ||
| small alias | ||
| code is.string(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `typeof val === 'string'` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.str("Dark Star") // true | ||
| is.str(1) // false | ||
| is.str({}) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='bool') | ||
| .panel-heading | ||
| h4 bool | ||
| small: code is.bool(val) | ||
| small alias | ||
| code is.boolean(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `typeof val === 'boolean'` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.bool(true) // false | ||
| is.bool(false) // false | ||
| is.bool("Dark Star") // false | ||
| is.bool(1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='int') | ||
| .panel-heading | ||
| h4 int | ||
| small: code is.int(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is an integer | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.int(1) // true | ||
| is.int(1.5) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='primitive') | ||
| .panel-heading | ||
| h4 primitive | ||
| small: code is.primitive(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is a primitive value | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.primitive(1) // true | ||
| is.primitive('a') // true | ||
| is.primitive(null) // true | ||
| is.primitive(NaN) // true | ||
| is.primitive([]) // false | ||
| is.primitive({}) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='pos') | ||
| .panel-heading | ||
| h4 pos | ||
| small: code is.pos(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val > 0` and is a `number` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.pos(1) // true | ||
| is.pos(-2) // false | ||
| is.pos(0) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='neg') | ||
| .panel-heading | ||
| h4 neg | ||
| small: code is.neg(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val < 0` and is a `number` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.neg(-2) // true | ||
| is.neg(1) // false | ||
| is.neg(0) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='zero') | ||
| .panel-heading | ||
| h4 zero | ||
| small: code is.zero(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val === 0` and is a `number` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.zero(0) // true | ||
| is.zero(-2) // false | ||
| is.zero(1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='even') | ||
| .panel-heading | ||
| h4 even | ||
| small: code is.even(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is a `number`, not `zero`, and it's modulus of 2 is zero | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.even(2) // true | ||
| is.even(0) // false | ||
| is.even(1) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='odd') | ||
| .panel-heading | ||
| h4 odd | ||
| small: code is.odd(val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` is a `number`, not `zero`, and it's modulus of 2 is not zero | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.odd(1) // true | ||
| is.odd(2) // false | ||
| is.odd(0) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='contains') | ||
| .panel-heading | ||
| h4 contains | ||
| small: code is.contains(arr, val) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `val` exists in `arr` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| var arr = [1, 2, 3, 4]; | ||
| is.contains(arr, 2) // true | ||
| is.contains(arr, -5) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='empty') | ||
| .panel-heading | ||
| h4 empty | ||
| small: code is.empty(o) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `o` is an object and has no owned props | ||
| Returns true if `o` is an array or string of length zero | ||
| Throws `TypeError` if `o` is not an `Array`, `Object`, or `String` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.empty([]) // true | ||
| is.empty(['a']) // false | ||
| is.empty({}) // true | ||
| is.empty({foo: 'bar'}) // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='has') | ||
| .panel-heading | ||
| h4 has | ||
| small: code is.has(o, key) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `string` `key` exists on `object` `o` | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| var o = { planet: 'Earth' }; | ||
| is.has(o, 'planet') // true | ||
| is.has(o, 'moon') // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='instance') | ||
| .panel-heading | ||
| h4 instance | ||
| small: code is.instance(Cls, [inst]) | ||
| .panel-body | ||
| :markdown | ||
| Returns true if `inst instanceof Cls` is `true`. | ||
| small curryable | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| function Planet() {} | ||
| var p = new Planet(); | ||
| var isPlanet = is.instance(Planet); | ||
| isPlanet(p); // true | ||
| is.instance(Planet, p); // true | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='ternary') | ||
| .panel-heading | ||
| h4 ternary | ||
| small: code is.ternary(pred, [a [b]]) | ||
| .panel-body | ||
| :markdown | ||
| **If a `pred` is given:** | ||
| Returns a `function(a, b)` that evaluates `pred(a, b)` | ||
| **If `pred` and `a` and is given:** | ||
| Returns a `function(b)` that evaluates `pred(a, b)` | ||
| **If `pred` and `a` and `b` is given:** | ||
| Returns the evaluation of `pred(a, b)` | ||
| **If `pred` is of type `boolean`, `a`, and `b` are given** | ||
| Returns `bool` ? `a` : `b` | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| var pred1 = is.ternary(is.less); | ||
| pred1(1, 2); // 1 | ||
| var pred2 = is.ternary(is.less, 1); | ||
| pred2(2); // 1 | ||
| is.ternary(is.less, 1, 2); // 1 | ||
| is.ternary(1 < 2, 'a', 'b'); // 'a' | ||
| ``` | ||
| a(name='chaining') | ||
| h1 Chaining | ||
| hr | ||
| .panel.panel-default | ||
| a(name='every') | ||
| .panel-heading | ||
| h4 every | ||
| small: code is.every() | ||
| small alias | ||
| code is.all() | ||
| .panel-body | ||
| :markdown | ||
| Returns a chainable interface for lazily executing predicates. | ||
| Invoke `.val()` which returns `true` if all predicates evaluate | ||
| to `true`. | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| var chain = is.every(); | ||
| chain = chain.less(1, 2).fn(is.exists); | ||
| chain.val(); // true | ||
| chain.NaN(1).val(); // false | ||
| is.every().exists('mars').str('asteroid').val(); //true | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='some') | ||
| .panel-heading | ||
| h4 some | ||
| small: code is.some() | ||
| small alias | ||
| code is.any() | ||
| .panel-body | ||
| :markdown | ||
| Returns a chainable interface for lazily executing predicates. | ||
| Invoke `.val()` which returns `true` if at least 1 predicate evaluate | ||
| to `true`. | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| var chain = is.some(); | ||
| chain = chain.equal(1, 2).fn(is.exists); | ||
| chain.val(); // true | ||
| chain.NaN(1).val(); // true | ||
| is.some().exists(null).str('asteroid').val(); // true | ||
| is.some().exists(null).str(1).val(); // false | ||
| ``` | ||
| a(name='utils') | ||
| h1 Utils | ||
| hr | ||
| .panel.panel-default | ||
| a(name='curry') | ||
| .panel-heading | ||
| h4 curry | ||
| small: code is.curry(fn) | ||
| .panel-body | ||
| :markdown | ||
| Returns a new function that curries a given `fn`. | ||
| small Used internally | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| var fn = is.curry(function add(a, b) { | ||
| return a + b; | ||
| }); | ||
| var fn2 = add(1); | ||
| fn2(2); // 3 | ||
| fn2(5); // 6 | ||
| fn(2, 2); // 4 | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='partial') | ||
| .panel-heading | ||
| h4 partial | ||
| small: code is.partial(fn, ...) | ||
| .panel-body | ||
| :markdown | ||
| Returns a partially applied function based on `fn`. | ||
| small Used internally | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| var fn = is.partial(is.less, 1); | ||
| fn(2); // true | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='complement') | ||
| .panel-heading | ||
| h4 complement | ||
| small: code is.complement(fn) | ||
| small alias | ||
| code is.invert(fn) | ||
| .panel-body | ||
| :markdown | ||
| Returns a function a that receives the same args as `fn` and returns | ||
| the opposite truth value. | ||
| small Used internally | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| var fn = is.complement(is.fn); | ||
| fn(is.fn); // false | ||
| ``` | ||
| .panel.panel-default | ||
| a(name='mod') | ||
| .panel-heading | ||
| h4 mod | ||
| small: code is.mod(a, b) | ||
| .panel-body | ||
| :markdown | ||
| Returns the value of `a % b` | ||
| small Used internally | ||
| hr | ||
| p | ||
| small Example | ||
| :markdown | ||
| ```js | ||
| is.mod(6, 5); // 1 | ||
| is.mod(6, 6); // 0 | ||
| ``` |
+613
| <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>is.js</title><meta name="generator" content="Bootply"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"><style type="text/css">@import url(http://fonts.googleapis.com/css?family=Droid+Sans+Mono); | ||
| html,body { | ||
| height: 100%; | ||
| font-family: 'Droid Sans Mono', sans-serif; | ||
| } | ||
| p,h1,h2,h3,h4 { | ||
| font-family: 'Droid Sans Mono', sans-serif; | ||
| } | ||
| hr { | ||
| border-color:#222; | ||
| } | ||
| /* wrapper for page content to push down footer */ | ||
| .page-container { | ||
| min-height: 100%; | ||
| height: auto !important; | ||
| height: 100%; | ||
| /* negative indent footer by its height*/ | ||
| margin: 0 auto -120px; | ||
| /*pad bottom by footer height */ | ||
| padding: 0 0 70px; | ||
| } | ||
| /* set the fixed height of the footer here */ | ||
| #footer { | ||
| border: none; | ||
| font-weight: 100; | ||
| font-family: 'Droid Sans Mono', sans-serif; | ||
| width: 500px; | ||
| background: none; | ||
| color: #efefef; | ||
| } | ||
| body { | ||
| background: #1E1E1E; | ||
| color: #f9f9f9; | ||
| } | ||
| a, small { | ||
| color:#bcbcbc; | ||
| } | ||
| .text-center { | ||
| padding-top: 20px; | ||
| } | ||
| #main { | ||
| padding-top: 30px; | ||
| } | ||
| #sidebar { | ||
| height: 100%; | ||
| padding-right: 0; | ||
| padding-bottom: 100px; | ||
| position: fixed; | ||
| left: 0; | ||
| overflow: scroll; | ||
| } | ||
| #sidebar .affix { | ||
| position:fixed; | ||
| top:55; | ||
| width:220px; | ||
| } | ||
| #sidebar .affix-bottom { | ||
| position:fixed; | ||
| top:55; | ||
| width:220px; | ||
| } | ||
| #sidebar .nav { | ||
| width: 95%; | ||
| } | ||
| #sidebar li { | ||
| border:0 #1e1e1e solid; | ||
| border-bottom-width:1px; | ||
| margin-left: 10px; | ||
| } | ||
| #sidebar li.heading { | ||
| border:0 #1e1e1e solid; | ||
| border-bottom-width:1px; | ||
| margin-left: 0px; | ||
| font-size: 125%; | ||
| } | ||
| #sidebar li a { | ||
| padding-left:1px; | ||
| } | ||
| #sidebar li a:hover { | ||
| background-color:#222222; | ||
| color:#ffffff; | ||
| } | ||
| /* collapsed sidebar styles */ | ||
| @media screen and (max-width: 767px) { | ||
| .row-offcanvas { | ||
| position: relative; | ||
| -webkit-transition: all 0.25s ease-out; | ||
| -moz-transition: all 0.25s ease-out; | ||
| transition: all 0.25s ease-out; | ||
| } | ||
| .row-offcanvas-right | ||
| .sidebar-offcanvas { | ||
| right: -41.6%; | ||
| } | ||
| .row-offcanvas-left | ||
| .sidebar-offcanvas { | ||
| left: -41.6%; | ||
| } | ||
| .row-offcanvas-right.active { | ||
| right: 41.6%; | ||
| } | ||
| .row-offcanvas-left.active { | ||
| left: 41.6%; | ||
| } | ||
| .sidebar-offcanvas { | ||
| position: absolute; | ||
| top: 0; | ||
| width: 41.6%; | ||
| } | ||
| #sidebar { | ||
| padding-top:0; | ||
| } | ||
| #sidebar .nav>li { | ||
| color: #ddd; | ||
| background: linear-gradient(#3E3E3E, #383838); | ||
| border-top: 1px solid #484848; | ||
| border-bottom: 1px solid #2E2E2E; | ||
| padding-left:10px; | ||
| } | ||
| #sidebar .nav>li:first-child { | ||
| border-top:0; | ||
| } | ||
| #sidebar .nav>li>a { | ||
| color: #ddd; | ||
| } | ||
| #sidebar .nav>li>a>img { | ||
| max-width: 14px; | ||
| } | ||
| #sidebar .nav>li>a:hover, #sidebar .nav>li>a:focus { | ||
| text-decoration: none; | ||
| background: linear-gradient(#373737, #323232); | ||
| color: #fff; | ||
| } | ||
| #sidebar .nav .caret { | ||
| border-top-color: #fff; | ||
| border-bottom-color: #fff; | ||
| } | ||
| #sidebar .nav a:hover .caret{ | ||
| border-top-color: #fff; | ||
| border-bottom-color: #fff; | ||
| } | ||
| } | ||
| /* theme */ | ||
| .btn,.form-control,.alert,.progress,.panel,.list-group,.well,.list-group-item:first-child {border-radius:1px;box-shadow:0 0 0;} | ||
| .btn {border-color:transparent;} | ||
| .btn-default,.well { | ||
| background-color:#cccccc; | ||
| border-color:#c0c0c0; | ||
| } | ||
| .btn-primary,.label-primary,.list-group-item.active,.list-group-item.active:hover,.list-group-item.active:focus,.btn.active,a.list-group-item.active, a.list-group-item.active:hover, a.list-group-item.active:focus { | ||
| background-color:#0099CC; | ||
| border-color:transparent; | ||
| } | ||
| .btn-info,.label-info,.progress-bar-info { | ||
| background-color:#33b5e5; | ||
| } | ||
| .btn-success,.label-success,.progress-bar-success { | ||
| background-color:#669900; | ||
| } | ||
| .btn-danger,.label-danger,.progress-bar-danger { | ||
| background-color:#FF4444; | ||
| } | ||
| .btn-warning,.label-warning,.progress-bar-warning { | ||
| background-color:#FFBB33; | ||
| color:#444444; | ||
| } | ||
| .nav-tabs>li>a { | ||
| border-radius:0; | ||
| } | ||
| h3,h4,h5,.panel { | ||
| color:#555555; | ||
| } | ||
| .panel hr { | ||
| border-color:#efefef; | ||
| } | ||
| code { | ||
| color: #58b; | ||
| } | ||
| .jumbotron { | ||
| background-color: transparent; | ||
| border-radius: 1px; | ||
| } | ||
| .jumbotron h1 { | ||
| color: #bbb; | ||
| } | ||
| .jumbotron h4 { | ||
| color: #666; | ||
| } | ||
| .jumbotron a { | ||
| color: #8be; | ||
| } | ||
| .jumbotron small { | ||
| font-size: 16px; | ||
| color: #666; | ||
| } | ||
| .jumbotron p { | ||
| font-size: 14px; | ||
| } | ||
| .changelog code { | ||
| background: #444; | ||
| color: #ddd; | ||
| }</style></head><body><a href="https://github.com/landau/is"><img style="z-index:99999;position: fixed; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png"></a><div class="page-container"><div class="col-sm-12"><div class="row row-offcanvas row-offcanvas-left"><div id="sidebar" role="navigation" class="col-xs-6 col-sm-2 sidebar-offcanvas"><div><ul id="sidebar-nav" class="nav"><li class="heading"><a href="#intro">Intro</a></li><li class="heading"><a href="#predicates">Predicates</a></li><li><a href="#not">is.not</a></li><li><a href="#is">is.is</a></li><li><a href="#exists">is.exists</a></li><li><a href="#truthy">is.truthy</a></li><li><a href="#falsey">is.falsey</a></li><li><a href="#null">is.null</a></li><li><a href="#undef">is.undef</a></li><li><a href="#equal">is.equal</a></li><li><a href="#eq">is.eq</a></li><li><a href="#less">is.less</a></li><li><a href="#lessEq">is.lessEq</a></li><li><a href="#greater">is.greater</a></li><li><a href="#greaterEq">is.greaterEq</a></li><li><a href="#object">is.object</a></li><li><a href="#array">is.array</a></li><li><a href="#date">is.date</a></li><li><a href="#rgx">is.rgx</a></li><li><a href="#finite">is.finite</a></li><li><a href="#NaN">is.NaN</a></li><li><a href="#arguments">is.arguments</a></li><li><a href="#error">is.error</a></li><li><a href="#fn">is.fn</a></li><li><a href="#num">is.num</a></li><li><a href="#str">is.str</a></li><li><a href="#bool">is.bool</a></li><li><a href="#int">is.int</a></li><li><a href="#primitive">is.primitive</a></li><li><a href="#pos">is.pos</a></li><li><a href="#neg">is.neg</a></li><li><a href="#zero">is.zero</a></li><li><a href="#even">is.even</a></li><li><a href="#odd">is.odd</a></li><li><a href="#contains">is.contains</a></li><li><a href="#empty">is.empty</a></li><li><a href="#has">is.has</a></li><li><a href="#instance">is.instance</a></li><li><a href="#ternary">is.ternary</a></li><li class="heading"><a href="#chaining">Chaining</a></li><li><a href="#every">is.every</a></li><li><a href="#some">is.some</a></li><li class="heading"><a href="#utils">Utils</a></li><li><a href="#curry">is.curry</a></li><li><a href="#partial">is.partial</a></li><li><a href="#complement">is.complement</a></li><li><a href="#mod">is.mod</a></li><li class="heading"><a href="#changelog">changelog</a></li></ul></div></div><div id="main" class="col-xs-12 col-sm-7 col-sm-offset-3"><a name="intro"></a><div class="jumbotron"><h1>is<small>v. 0.10.1</small></h1><h5>Adding clarity and conciseness to your JS through predicates</h5><br><p><a href="https://github.com/landau/is">is</a> provides a slew of functions that allow | ||
| you to compare values and test types. This leads to more functional, concise, | ||
| legible, and correct code.</p> | ||
| <p>This is extremely useful when filtering data or comparing against a set of data.</p> | ||
| <pre><code class="lang-js"> ['venus', 'neptune', 1, []].filter(is.str); // ['venus', 'neptune'] | ||
| [1.2, 3, 5].every(is.int) // false | ||
| </code></pre> | ||
| <p>is also offers autocurrying for predicates of arity 2</p> | ||
| <pre><code class="lang-js">var isInSet = is.contains([1, 2, 3]); | ||
| isInSet(1); // true | ||
| isInSet(5); // false | ||
| var hasKey = is.has({ name: 'Trevor', twitter: '@trevor_landau' }); | ||
| hasKey('name'); // true | ||
| hasKey('myspace'); // false | ||
| </code></pre> | ||
| <p>Make room on your utility belt next to <a href="http://underscorejs.org">underscore</a> and <a href="https://github.com/CrossEye/ramda">rambda</a></p> | ||
| <pre><code class="lang-js"> _.filter([1, 2, 3], _.partial(is.less, 1)); // [2, 3] | ||
| _.partition([1, -2, -3, 4], is.pos); // [[1, 4], [-2, -3]] | ||
| </code></pre> | ||
| <p>The project is <a href="https://github.com/landau/is">hosted on GitHub</a>. | ||
| You can report bugs and discuss features on the <a href="https://github.com/landau/is/issues">issues page</a> | ||
| or send tweets to <a href="https://twitter.com/trevor_landau">@trevor_landau</a>.</p> | ||
| <br><h5>Install/Downloads</h5><p>Node <a href="https://www.npmjs.org/package/is-predicate">npm install --save is-predicate</a></p><p>Development <a href="https://raw.githubusercontent.com/landau/is/master/dist/is.js">is.js</a></p><p>Production <a href="https://raw.githubusercontent.com/landau/is/master/dist/is.min.js">is.min.js</a></p></div><a name="predicates"></a><h1>Predicates</h1><hr><div class="panel panel-default"><a name="not"></a><div class="panel-heading"><h4>not<small><code>is.not</code></small></h4></div><div class="panel-body"><p>A complemented version of the <code>is</code> predicate functions. | ||
| All predicate functions are available in this namespace.</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.null(null) // true | ||
| is.not.null(null) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="is"></a><div class="panel-heading"><h4>is<small><code>is.is(a, b)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>Object.is(a, b)</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">is.is(window, window) // true | ||
| is.is(1, 1) // true | ||
| is.is(NaN, 0/0) // true | ||
| is.is(0, -0) // false | ||
| is.is([], []) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="exists"></a><div class="panel-heading"><h4>exists<small><code>is.exists(val)</code></small></h4></div><div class="panel-body"><p>Returns true if a value is not <code>null</code> or <code>undefined</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.exists(null) // false | ||
| is.exists(false) // true | ||
| is.exists(0) // true | ||
| is.exists('javascript') // true | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="truthy"></a><div class="panel-heading"><h4>truthy<small><code>is.truthy(val)</code></small></h4></div><div class="panel-body"><p>Returns true if a value <code>exists</code> and isn't <code>false</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.truthy(0) // true | ||
| is.truthy([1, 2]) // true | ||
| is.truthy(false) // false | ||
| is.truthy(null) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="falsey"></a><div class="panel-heading"><h4>falsey<small><code>is.falsey(val)</code></small></h4></div><div class="panel-body"><p>Returns true if a value is <code>false</code> or <code>doesn't exist</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.falsey(0) // false | ||
| is.falsey([1, 2]) // false | ||
| is.falsey(false) // true | ||
| is.falsey(null) // true | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="null"></a><div class="panel-heading"><h4>null<small><code>is.null(val)</code></small></h4></div><div class="panel-body"><p>Returns true if a value is <code>null</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.null(null) // true | ||
| is.null(false) // false | ||
| is.null(undefined) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="undef"></a><div class="panel-heading"><h4>undef<small><code>is.undef(val)</code></small></h4></div><div class="panel-body"><p>Returns true if a value is <code>undefined</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.undef(undefined) // true | ||
| is.undef(null) // false | ||
| is.undef(false) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="equal"></a><div class="panel-heading"><h4>equal<small><code>is.equal(a, b)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>a === b</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">is.equal(1, 1) // true | ||
| is.equal('a', 'a') // true | ||
| is.equal(null, 1) // false | ||
| is.equal([1, 2], [1, 2]) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="eq"></a><div class="panel-heading"><h4>eq<small><code>is.eq(a, b)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>a == b</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">is.eq('1', 1) // true | ||
| is.eq('a', 'b') // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="less"></a><div class="panel-heading"><h4>less<small><code>is.less(a, b)</code></small></h4><small>alias <code>is.lt(a, b)</code></small></div><div class="panel-body"><p>Returns true if <code>a < b</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">is.less(1, 5) // true | ||
| is.less(5, 5) // false | ||
| is.less(5, 1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="lessEq"></a><div class="panel-heading"><h4>lessEq<small><code>is.lessEq(a, b)</code></small></h4><small>alias <code>is.ltEq(a, b)</code></small></div><div class="panel-body"><p>Returns true if <code>a <= b</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">is.lessEq(1, 5) // true | ||
| is.lessEq(5, 5) // true | ||
| is.lessEq(5, 1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="greater"></a><div class="panel-heading"><h4>greater<small><code>is.greater(a, b)</code></small></h4><small>alias <code>is.gt(a, b)</code></small></div><div class="panel-body"><p>Returns true if <code>a > b</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">is.greater(5, 1) // true | ||
| is.greater(5, 5) // false | ||
| is.greater(1, 5) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="greaterEq"></a><div class="panel-heading"><h4>greaterEq<small><code>is.greaterEq(a, b)</code></small></h4><small>alias <code>is.gtEq(a, b)</code></small></div><div class="panel-body"><p>Returns true if <code>a > b</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">is.greaterEq(5, 1) // true | ||
| is.greaterEq(5, 5) // true | ||
| is.greaterEq(1, 5) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="object"></a><div class="panel-heading"><h4>object<small><code>is.object(val)</code></small></h4><small>alias <code>is.obj(val)</code></small></div><div class="panel-body"><p>Returns true if <code>val</code> is an object</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.object({}) // true | ||
| is.object([]) // true | ||
| is.object(1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="array"></a><div class="panel-heading"><h4>array<small><code>is.array(val)</code></small></h4><small>alias <code>is.arr(val)</code></small></div><div class="panel-body"><p>Returns true if <code>val</code> is an array</p> | ||
| <p><em>Defaults to native</em> <code>Array.isArray</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.array([]) // true | ||
| is.array({}) // false | ||
| is.array(1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="date"></a><div class="panel-heading"><h4>date<small><code>is.date(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is a date</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.date(new Date()) // true | ||
| is.date({}) // false | ||
| is.date(1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="rgx"></a><div class="panel-heading"><h4>rgx<small><code>is.rgx(val)</code></small></h4><small>alias <code>is.RegExp(val)</code></small></div><div class="panel-body"><p>Returns true if <code>val</code> is a rgx</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.rgx(/\d{1,4}/) // true | ||
| is.rgx(new RegExp("Cosmos", "gi")) // true | ||
| is.rgx({}) // false | ||
| is.rgx("Dark Star") // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="finite"></a><div class="panel-heading"><h4>finite<small><code>is.finite(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is a <code>number</code> and <code>isFinite</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.finite(1) // true | ||
| is.finite(2e64) // true | ||
| is.finite(NaN) // false | ||
| is.finite('1') // false | ||
| is.finite(Infinity) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="NaN"></a><div class="panel-heading"><h4>NaN<small><code>is.NaN(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is <code>NaN</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.NaN(NaN) // true | ||
| is.NaN("titan") // false | ||
| is.NaN(1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="arguments"></a><div class="panel-heading"><h4>arguments<small><code>is.arguments(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is an <code>arguments</code> object</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.arguments(arguments) // true | ||
| is.arguments("titan") // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="error"></a><div class="panel-heading"><h4>error<small><code>is.error(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is an <code>error</code> object</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.error(new Error()) // true | ||
| is.error("titan") // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="fn"></a><div class="panel-heading"><h4>fn<small><code>is.fn(val)</code></small></h4><small>alias <code>is.function(val)</code></small></div><div class="panel-body"><p>Returns true if <code>typeof val === 'function'</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.fn(is.fn) // true | ||
| is.fn(Math.max) // true | ||
| is.fn({}) // false | ||
| is.fn("Dark Star") // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="num"></a><div class="panel-heading"><h4>num<small><code>is.num(val)</code></small></h4><small>alias <code>is.number(val)</code></small></div><div class="panel-body"><p>Returns true if <code>typeof val === 'number'</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.num(1) // true | ||
| is.num(NaN) // false | ||
| is.num({}) // false | ||
| is.num("Dark Star") // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="str"></a><div class="panel-heading"><h4>str<small><code>is.str(val)</code></small></h4><small>alias <code>is.string(val)</code></small></div><div class="panel-body"><p>Returns true if <code>typeof val === 'string'</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.str("Dark Star") // true | ||
| is.str(1) // false | ||
| is.str({}) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="bool"></a><div class="panel-heading"><h4>bool<small><code>is.bool(val)</code></small></h4><small>alias <code>is.boolean(val)</code></small></div><div class="panel-body"><p>Returns true if <code>typeof val === 'boolean'</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.bool(true) // false | ||
| is.bool(false) // false | ||
| is.bool("Dark Star") // false | ||
| is.bool(1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="int"></a><div class="panel-heading"><h4>int<small><code>is.int(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is an integer</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.int(1) // true | ||
| is.int(1.5) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="primitive"></a><div class="panel-heading"><h4>primitive<small><code>is.primitive(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is a primitive value</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.primitive(1) // true | ||
| is.primitive('a') // true | ||
| is.primitive(null) // true | ||
| is.primitive(NaN) // true | ||
| is.primitive([]) // false | ||
| is.primitive({}) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="pos"></a><div class="panel-heading"><h4>pos<small><code>is.pos(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val > 0</code> and is a <code>number</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.pos(1) // true | ||
| is.pos(-2) // false | ||
| is.pos(0) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="neg"></a><div class="panel-heading"><h4>neg<small><code>is.neg(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val < 0</code> and is a <code>number</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.neg(-2) // true | ||
| is.neg(1) // false | ||
| is.neg(0) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="zero"></a><div class="panel-heading"><h4>zero<small><code>is.zero(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val === 0</code> and is a <code>number</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.zero(0) // true | ||
| is.zero(-2) // false | ||
| is.zero(1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="even"></a><div class="panel-heading"><h4>even<small><code>is.even(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is a <code>number</code>, not <code>zero</code>, and it's modulus of 2 is zero</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.even(2) // true | ||
| is.even(0) // false | ||
| is.even(1) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="odd"></a><div class="panel-heading"><h4>odd<small><code>is.odd(val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> is a <code>number</code>, not <code>zero</code>, and it's modulus of 2 is not zero</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.odd(1) // true | ||
| is.odd(2) // false | ||
| is.odd(0) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="contains"></a><div class="panel-heading"><h4>contains<small><code>is.contains(arr, val)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>val</code> exists in <code>arr</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">var arr = [1, 2, 3, 4]; | ||
| is.contains(arr, 2) // true | ||
| is.contains(arr, -5) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="empty"></a><div class="panel-heading"><h4>empty<small><code>is.empty(o)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>o</code> is an object and has no owned props</p> | ||
| <p>Returns true if <code>o</code> is an array or string of length zero</p> | ||
| <p>Throws <code>TypeError</code> if <code>o</code> is not an <code>Array</code>, <code>Object</code>, or <code>String</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">is.empty([]) // true | ||
| is.empty(['a']) // false | ||
| is.empty({}) // true | ||
| is.empty({foo: 'bar'}) // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="has"></a><div class="panel-heading"><h4>has<small><code>is.has(o, key)</code></small></h4></div><div class="panel-body"><p>Returns true if <code>string</code> <code>key</code> exists on <code>object</code> <code>o</code></p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">var o = { planet: 'Earth' }; | ||
| is.has(o, 'planet') // true | ||
| is.has(o, 'moon') // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="instance"></a><div class="panel-heading"><h4>instance<small><code>is.instance(Cls, [inst])</code></small></h4></div><div class="panel-body"><p>Returns true if <code>inst instanceof Cls</code> is <code>true</code>.</p> | ||
| <small>curryable </small><hr><p><small>Example</small><pre><code class="lang-js">function Planet() {} | ||
| var p = new Planet(); | ||
| var isPlanet = is.instance(Planet); | ||
| isPlanet(p); // true | ||
| is.instance(Planet, p); // true | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="ternary"></a><div class="panel-heading"><h4>ternary<small><code>is.ternary(pred, [a [b]])</code></small></h4></div><div class="panel-body"><p><strong>If a <code>pred</code> is given:</strong></p> | ||
| <p>Returns a <code>function(a, b)</code> that evaluates <code>pred(a, b)</code></p> | ||
| <p><strong>If <code>pred</code> and <code>a</code> and is given:</strong></p> | ||
| <p>Returns a <code>function(b)</code> that evaluates <code>pred(a, b)</code></p> | ||
| <p><strong>If <code>pred</code> and <code>a</code> and <code>b</code> is given:</strong></p> | ||
| <p>Returns the evaluation of <code>pred(a, b)</code></p> | ||
| <p><strong>If <code>pred</code> is of type <code>boolean</code>, <code>a</code>, and <code>b</code> are given</strong></p> | ||
| <p>Returns <code>bool</code> ? <code>a</code> : <code>b</code></p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">var pred1 = is.ternary(is.less); | ||
| pred1(1, 2); // 1 | ||
| var pred2 = is.ternary(is.less, 1); | ||
| pred2(2); // 1 | ||
| is.ternary(is.less, 1, 2); // 1 | ||
| is.ternary(1 < 2, 'a', 'b'); // 'a' | ||
| </code></pre> | ||
| </p></div></div><a name="chaining"></a><h1>Chaining</h1><hr><div class="panel panel-default"><a name="every"></a><div class="panel-heading"><h4>every<small><code>is.every()</code></small></h4><small>alias <code>is.all()</code></small></div><div class="panel-body"><p>Returns a chainable interface for lazily executing predicates.</p> | ||
| <p>Invoke <code>.val()</code> which returns <code>true</code> if all predicates evaluate | ||
| to <code>true</code>.</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">var chain = is.every(); | ||
| chain = chain.less(1, 2).fn(is.exists); | ||
| chain.val(); // true | ||
| chain.NaN(1).val(); // false | ||
| is.every().exists('mars').str('asteroid').val(); //true | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="some"></a><div class="panel-heading"><h4>some<small><code>is.some()</code></small></h4><small>alias <code>is.any()</code></small></div><div class="panel-body"><p>Returns a chainable interface for lazily executing predicates.</p> | ||
| <p>Invoke <code>.val()</code> which returns <code>true</code> if at least 1 predicate evaluate | ||
| to <code>true</code>.</p> | ||
| <hr><p><small>Example</small><pre><code class="lang-js">var chain = is.some(); | ||
| chain = chain.equal(1, 2).fn(is.exists); | ||
| chain.val(); // true | ||
| chain.NaN(1).val(); // true | ||
| is.some().exists(null).str('asteroid').val(); // true | ||
| is.some().exists(null).str(1).val(); // false | ||
| </code></pre> | ||
| </p></div></div><a name="utils"></a><h1>Utils</h1><hr><div class="panel panel-default"><a name="curry"></a><div class="panel-heading"><h4>curry<small><code>is.curry(fn)</code></small></h4></div><div class="panel-body"><p>Returns a new function that curries a given <code>fn</code>.</p> | ||
| <small>Used internally</small><hr><p><small>Example</small><pre><code class="lang-js">var fn = is.curry(function add(a, b) { | ||
| return a + b; | ||
| }); | ||
| var fn2 = add(1); | ||
| fn2(2); // 3 | ||
| fn2(5); // 6 | ||
| fn(2, 2); // 4 | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="partial"></a><div class="panel-heading"><h4>partial<small><code>is.partial(fn, ...)</code></small></h4></div><div class="panel-body"><p>Returns a partially applied function based on <code>fn</code>.</p> | ||
| <small>Used internally</small><hr><p><small>Example</small><pre><code class="lang-js">var fn = is.partial(is.less, 1); | ||
| fn(2); // true | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="complement"></a><div class="panel-heading"><h4>complement<small><code>is.complement(fn)</code></small></h4><small>alias<code>is.invert(fn)</code></small></div><div class="panel-body"><p>Returns a function a that receives the same args as <code>fn</code> and returns | ||
| the opposite truth value.</p> | ||
| <small>Used internally</small><hr><p><small>Example</small><pre><code class="lang-js">var fn = is.complement(is.fn); | ||
| fn(is.fn); // false | ||
| </code></pre> | ||
| </p></div></div><div class="panel panel-default"><a name="mod"></a><div class="panel-heading"><h4>mod<small><code>is.mod(a, b)</code></small></h4></div><div class="panel-body"><p>Returns the value of <code>a % b</code></p> | ||
| <small>Used internally</small><hr><p><small>Example</small><pre><code class="lang-js">is.mod(6, 5); // 1 | ||
| is.mod(6, 6); // 0 | ||
| </code></pre> | ||
| </p></div></div><hr><a name="changelog"></a><div class="changelog"><h2 id="changelog">changelog</h2> | ||
| <h4 id="0-10-0">0.10.0</h4> | ||
| <ul> | ||
| <li>Added <code>is.primitive</code> (<a href="https://twitter.com/tgriesser">@tgriesser</a>)</li> | ||
| <li>Update docs with <code>is.empty</code> (<a href="https://twitter.com/BlaineBublitz">@BlaineBublitz</a>)</li> | ||
| <li><code>is.empty</code> now throws for invalid types</li> | ||
| </ul> | ||
| <h4 id="0-9-0">0.9.0</h4> | ||
| <ul> | ||
| <li>Added <code>is.is</code> based off polyfill from MDN</li> | ||
| <li>Added alias for <code>is.object</code> and <code>is.arr</code></li> | ||
| <li><code>is.num(NaN)</code> now returns false</li> | ||
| </ul> | ||
| <h4 id="0-8-2">0.8.2</h4> | ||
| <ul> | ||
| <li>Correctly test for NaN in <code>is.contains</code></li> | ||
| </ul> | ||
| <h4 id="0-8-1">0.8.1</h4> | ||
| <ul> | ||
| <li>Fix currying issue with <code>is.not</code></li> | ||
| </ul> | ||
| <h4 id="0-8-0">0.8.0</h4> | ||
| <ul> | ||
| <li>Added <code>is.curry</code> which is used internally</li> | ||
| <li>Added autocurrying for all functions that are arity 2</li> | ||
| <li><code>is.complement</code> can now return a function instead of just <code>booleans</code></li> | ||
| <li><code>is.truthy</code> and <code>is.falsey</code> now respect js falsey values (eg 0, '', etc)</li> | ||
| </ul> | ||
| <h4 id="0-7-3">0.7.3</h4> | ||
| <ul> | ||
| <li>Refactored file structure</li> | ||
| </ul> | ||
| <h4 id="0-7-2">0.7.2</h4> | ||
| <ul> | ||
| <li>Update docs</li> | ||
| </ul> | ||
| <h4 id="0-7-1">0.7.1</h4> | ||
| <ul> | ||
| <li>Converted module to node style package</li> | ||
| <li>build process uses browserify standalone</li> | ||
| <li>Tests now in JS instead of CS (run much faster!)</li> | ||
| <li>Internal changes around chaining</li> | ||
| <li>Dropped gulp</li> | ||
| </ul> | ||
| <h4 id="0-7-0">0.7.0</h4> | ||
| <ul> | ||
| <li>Added <code>even</code>, <code>odd</code></li> | ||
| <li>Exposed <code>mod</code></li> | ||
| <li>Even more improved docs!</li> | ||
| </ul> | ||
| <h4 id="0-6-0">0.6.0</h4> | ||
| <ul> | ||
| <li>Removed <code>cmp</code></li> | ||
| <li>Added <code>is.empty</code></li> | ||
| <li>Alias <code>is.invert</code> as <code>is.complement</code></li> | ||
| <li>Expose <code>is.partial</code> from internals</li> | ||
| <li>Improved docs</li> | ||
| </ul> | ||
| <h4 id="0-5-0">0.5.0</h4> | ||
| <ul> | ||
| <li>Added <code>is.zero</code></li> | ||
| <li>Fix <code>is.object</code> and <code>is.error</code></li> | ||
| <li><code>is.ternary</code> now supports partial application</li> | ||
| <li><code>is.gt</code>, <code>is.gtEq</code>, <code>is.lt</code>, <code>is.ltEq</code> aliases added</li> | ||
| </ul> | ||
| <h4 id="0-4-0">0.4.0</h4> | ||
| <ul> | ||
| <li>Support for lazy chain evaluation</li> | ||
| </ul> | ||
| <h4 id="0-3-0">0.3.0</h4> | ||
| <ul> | ||
| <li>Expose `is.invert</li> | ||
| <li>Added `is.contains</li> | ||
| <li>Added `is.has</li> | ||
| <li>Remove bower support</li> | ||
| </ul> | ||
| <h4 id="0-2-0">0.2.0</h4> | ||
| <ul> | ||
| <li>Added <code>is.pos</code></li> | ||
| <li>Added <code>is.neg</code></li> | ||
| <li>Added <code>is.ternary</code></li> | ||
| <li>Added <code>is.not</code>, which inverses all boolean returning predicate methods</li> | ||
| </ul> | ||
| <h4 id="0-1-1">0.1.1</h4> | ||
| <ul> | ||
| <li>Added is.bool/boolean method</li> | ||
| </ul> | ||
| <h4 id="0-1-0">0.1.0</h4> | ||
| <ul> | ||
| <li>Release</li> | ||
| </ul> | ||
| </div><div id="footer" class="well">Copyright ©  <2013-2014></2013-2014> <a href="http://trevorlandau.net">Trevor λandau</a></div></div></div></div><script src="is.min.js"></script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script><script>$(document).ready(function() { | ||
| $('[data-toggle=offcanvas]').click(function() { | ||
| $('.row-offcanvas').toggleClass('active'); | ||
| }); | ||
| $('.btn-toggle').click(function() { | ||
| $(this).find('.btn').toggleClass('active').toggleClass('btn-default').toggleClass('btn-primary'); | ||
| }); | ||
| });</script><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
| (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
| m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
| })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
| ga('create', 'UA-36148349-8', 'landau.github.io'); | ||
| ga('send', 'pageview');</script></div></body></html> |
| doctype | ||
| html(lang='en') | ||
| head | ||
| meta(charset='UTF-8') | ||
| title is.js | ||
| meta(name='generator' content='Bootply') | ||
| meta(name='viewport', content='width=device-width, initial-scale=1, maximum-scale=1') | ||
| link(rel='stylesheet', href='http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css') | ||
| include ./style | ||
| body | ||
| a(href='https://github.com/landau/is') | ||
| img(style='z-index:99999;position: fixed; top: 0; right: 0; border: 0;', src='https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67', alt='Fork me on GitHub', data-canonical-src='https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png') | ||
| .page-container | ||
| .col-sm-12 | ||
| .row.row-offcanvas.row-offcanvas-left | ||
| include ./sidebar | ||
| //- main area | ||
| #main.col-xs-12.col-sm-7.col-sm-offset-3 | ||
| include ./intro | ||
| include ./docs | ||
| hr | ||
| include ./changelog | ||
| #footer.well | ||
| | Copyright ©  | ||
| #{'2013-' + (new Date).getFullYear()} | ||
| | | ||
| a(href='http://trevorlandau.net') Trevor λandau | ||
| script(src='is.min.js') | ||
| script(src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js') | ||
| script(src='http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js') | ||
| script. | ||
| $(document).ready(function() { | ||
| $('[data-toggle=offcanvas]').click(function() { | ||
| $('.row-offcanvas').toggleClass('active'); | ||
| }); | ||
| $('.btn-toggle').click(function() { | ||
| $(this).find('.btn').toggleClass('active').toggleClass('btn-default').toggleClass('btn-primary'); | ||
| }); | ||
| }); | ||
| script. | ||
| (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
| (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
| m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
| })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
| ga('create', 'UA-36148349-8', 'landau.github.io'); | ||
| ga('send', 'pageview'); | ||
| a(name='intro') | ||
| .jumbotron | ||
| h1 is | ||
| small v. 0.10.1 | ||
| h5 Adding clarity and conciseness to your JS through predicates | ||
| br | ||
| :markdown | ||
| [is](https://github.com/landau/is) provides a slew of functions that allow | ||
| you to compare values and test types. This leads to more functional, concise, | ||
| legible, and correct code. | ||
| This is extremely useful when filtering data or comparing against a set of data. | ||
| ```js | ||
| ['venus', 'neptune', 1, []].filter(is.str); // ['venus', 'neptune'] | ||
| [1.2, 3, 5].every(is.int) // false | ||
| ``` | ||
| is also offers autocurrying for predicates of arity 2 | ||
| ```js | ||
| var isInSet = is.contains([1, 2, 3]); | ||
| isInSet(1); // true | ||
| isInSet(5); // false | ||
| var hasKey = is.has({ name: 'Trevor', twitter: '@trevor_landau' }); | ||
| hasKey('name'); // true | ||
| hasKey('myspace'); // false | ||
| ``` | ||
| Make room on your utility belt next to [underscore](http://underscorejs.org) and [rambda](https://github.com/CrossEye/ramda) | ||
| ```js | ||
| _.filter([1, 2, 3], _.partial(is.less, 1)); // [2, 3] | ||
| _.partition([1, -2, -3, 4], is.pos); // [[1, 4], [-2, -3]] | ||
| ``` | ||
| The project is [hosted on GitHub](https://github.com/landau/is). | ||
| You can report bugs and discuss features on the [issues page](https://github.com/landau/is/issues) | ||
| or send tweets to [@trevor_landau](https://twitter.com/trevor_landau). | ||
| br | ||
| h5 Install/Downloads | ||
| p Node | ||
| a(href='https://www.npmjs.org/package/is-predicate') npm install --save is-predicate | ||
| p Development | ||
| a(href='https://raw.githubusercontent.com/landau/is/master/dist/is.js') is.js | ||
| p Production | ||
| a(href='https://raw.githubusercontent.com/landau/is/master/dist/is.min.js') is.min.js |
| #sidebar.col-xs-6.col-sm-2.sidebar-offcanvas(role='navigation') | ||
| div | ||
| ul#sidebar-nav.nav | ||
| li.heading: a(href='#intro') Intro | ||
| li.heading: a(href='#predicates') Predicates | ||
| li: a(href='#not') is.not | ||
| li: a(href='#is') is.is | ||
| li: a(href='#exists') is.exists | ||
| li: a(href='#truthy') is.truthy | ||
| li: a(href='#falsey') is.falsey | ||
| li: a(href='#null') is.null | ||
| li: a(href='#undef') is.undef | ||
| li: a(href='#equal') is.equal | ||
| li: a(href='#eq') is.eq | ||
| li: a(href='#less') is.less | ||
| li: a(href='#lessEq') is.lessEq | ||
| li: a(href='#greater') is.greater | ||
| li: a(href='#greaterEq') is.greaterEq | ||
| li: a(href='#object') is.object | ||
| li: a(href='#array') is.array | ||
| li: a(href='#date') is.date | ||
| li: a(href='#rgx') is.rgx | ||
| li: a(href='#finite') is.finite | ||
| li: a(href='#NaN') is.NaN | ||
| li: a(href='#arguments') is.arguments | ||
| li: a(href='#error') is.error | ||
| li: a(href='#fn') is.fn | ||
| li: a(href='#num') is.num | ||
| li: a(href='#str') is.str | ||
| li: a(href='#bool') is.bool | ||
| li: a(href='#int') is.int | ||
| li: a(href='#primitive') is.primitive | ||
| li: a(href='#pos') is.pos | ||
| li: a(href='#neg') is.neg | ||
| li: a(href='#zero') is.zero | ||
| li: a(href='#even') is.even | ||
| li: a(href='#odd') is.odd | ||
| li: a(href='#contains') is.contains | ||
| li: a(href='#empty') is.empty | ||
| li: a(href='#has') is.has | ||
| li: a(href='#instance') is.instance | ||
| li: a(href='#ternary') is.ternary | ||
| li.heading: a(href='#chaining') Chaining | ||
| li: a(href='#every') is.every | ||
| li: a(href='#some') is.some | ||
| li.heading: a(href='#utils') Utils | ||
| li: a(href='#curry') is.curry | ||
| li: a(href='#partial') is.partial | ||
| li: a(href='#complement') is.complement | ||
| li: a(href='#mod') is.mod | ||
| li.heading: a(href='#changelog') changelog |
+228
| style(type='text/css'). | ||
| @import url(http://fonts.googleapis.com/css?family=Droid+Sans+Mono); | ||
| html,body { | ||
| height: 100%; | ||
| font-family: 'Droid Sans Mono', sans-serif; | ||
| } | ||
| p,h1,h2,h3,h4 { | ||
| font-family: 'Droid Sans Mono', sans-serif; | ||
| } | ||
| hr { | ||
| border-color:#222; | ||
| } | ||
| /* wrapper for page content to push down footer */ | ||
| .page-container { | ||
| min-height: 100%; | ||
| height: auto !important; | ||
| height: 100%; | ||
| /* negative indent footer by its height*/ | ||
| margin: 0 auto -120px; | ||
| /*pad bottom by footer height */ | ||
| padding: 0 0 70px; | ||
| } | ||
| /* set the fixed height of the footer here */ | ||
| #footer { | ||
| border: none; | ||
| font-weight: 100; | ||
| font-family: 'Droid Sans Mono', sans-serif; | ||
| width: 500px; | ||
| background: none; | ||
| color: #efefef; | ||
| } | ||
| body { | ||
| background: #1E1E1E; | ||
| color: #f9f9f9; | ||
| } | ||
| a, small { | ||
| color:#bcbcbc; | ||
| } | ||
| .text-center { | ||
| padding-top: 20px; | ||
| } | ||
| #main { | ||
| padding-top: 30px; | ||
| } | ||
| #sidebar { | ||
| height: 100%; | ||
| padding-right: 0; | ||
| padding-bottom: 100px; | ||
| position: fixed; | ||
| left: 0; | ||
| overflow: scroll; | ||
| } | ||
| #sidebar .affix { | ||
| position:fixed; | ||
| top:55; | ||
| width:220px; | ||
| } | ||
| #sidebar .affix-bottom { | ||
| position:fixed; | ||
| top:55; | ||
| width:220px; | ||
| } | ||
| #sidebar .nav { | ||
| width: 95%; | ||
| } | ||
| #sidebar li { | ||
| border:0 #1e1e1e solid; | ||
| border-bottom-width:1px; | ||
| margin-left: 10px; | ||
| } | ||
| #sidebar li.heading { | ||
| border:0 #1e1e1e solid; | ||
| border-bottom-width:1px; | ||
| margin-left: 0px; | ||
| font-size: 125%; | ||
| } | ||
| #sidebar li a { | ||
| padding-left:1px; | ||
| } | ||
| #sidebar li a:hover { | ||
| background-color:#222222; | ||
| color:#ffffff; | ||
| } | ||
| /* collapsed sidebar styles */ | ||
| @media screen and (max-width: 767px) { | ||
| .row-offcanvas { | ||
| position: relative; | ||
| -webkit-transition: all 0.25s ease-out; | ||
| -moz-transition: all 0.25s ease-out; | ||
| transition: all 0.25s ease-out; | ||
| } | ||
| .row-offcanvas-right | ||
| .sidebar-offcanvas { | ||
| right: -41.6%; | ||
| } | ||
| .row-offcanvas-left | ||
| .sidebar-offcanvas { | ||
| left: -41.6%; | ||
| } | ||
| .row-offcanvas-right.active { | ||
| right: 41.6%; | ||
| } | ||
| .row-offcanvas-left.active { | ||
| left: 41.6%; | ||
| } | ||
| .sidebar-offcanvas { | ||
| position: absolute; | ||
| top: 0; | ||
| width: 41.6%; | ||
| } | ||
| #sidebar { | ||
| padding-top:0; | ||
| } | ||
| #sidebar .nav>li { | ||
| color: #ddd; | ||
| background: linear-gradient(#3E3E3E, #383838); | ||
| border-top: 1px solid #484848; | ||
| border-bottom: 1px solid #2E2E2E; | ||
| padding-left:10px; | ||
| } | ||
| #sidebar .nav>li:first-child { | ||
| border-top:0; | ||
| } | ||
| #sidebar .nav>li>a { | ||
| color: #ddd; | ||
| } | ||
| #sidebar .nav>li>a>img { | ||
| max-width: 14px; | ||
| } | ||
| #sidebar .nav>li>a:hover, #sidebar .nav>li>a:focus { | ||
| text-decoration: none; | ||
| background: linear-gradient(#373737, #323232); | ||
| color: #fff; | ||
| } | ||
| #sidebar .nav .caret { | ||
| border-top-color: #fff; | ||
| border-bottom-color: #fff; | ||
| } | ||
| #sidebar .nav a:hover .caret{ | ||
| border-top-color: #fff; | ||
| border-bottom-color: #fff; | ||
| } | ||
| } | ||
| /* theme */ | ||
| .btn,.form-control,.alert,.progress,.panel,.list-group,.well,.list-group-item:first-child {border-radius:1px;box-shadow:0 0 0;} | ||
| .btn {border-color:transparent;} | ||
| .btn-default,.well { | ||
| background-color:#cccccc; | ||
| border-color:#c0c0c0; | ||
| } | ||
| .btn-primary,.label-primary,.list-group-item.active,.list-group-item.active:hover,.list-group-item.active:focus,.btn.active,a.list-group-item.active, a.list-group-item.active:hover, a.list-group-item.active:focus { | ||
| background-color:#0099CC; | ||
| border-color:transparent; | ||
| } | ||
| .btn-info,.label-info,.progress-bar-info { | ||
| background-color:#33b5e5; | ||
| } | ||
| .btn-success,.label-success,.progress-bar-success { | ||
| background-color:#669900; | ||
| } | ||
| .btn-danger,.label-danger,.progress-bar-danger { | ||
| background-color:#FF4444; | ||
| } | ||
| .btn-warning,.label-warning,.progress-bar-warning { | ||
| background-color:#FFBB33; | ||
| color:#444444; | ||
| } | ||
| .nav-tabs>li>a { | ||
| border-radius:0; | ||
| } | ||
| h3,h4,h5,.panel { | ||
| color:#555555; | ||
| } | ||
| .panel hr { | ||
| border-color:#efefef; | ||
| } | ||
| code { | ||
| color: #58b; | ||
| } | ||
| .jumbotron { | ||
| background-color: transparent; | ||
| border-radius: 1px; | ||
| } | ||
| .jumbotron h1 { | ||
| color: #bbb; | ||
| } | ||
| .jumbotron h4 { | ||
| color: #666; | ||
| } | ||
| .jumbotron a { | ||
| color: #8be; | ||
| } | ||
| .jumbotron small { | ||
| font-size: 16px; | ||
| color: #666; | ||
| } | ||
| .jumbotron p { | ||
| font-size: 14px; | ||
| } | ||
| .changelog code { | ||
| background: #444; | ||
| color: #ddd; | ||
| } |
+57
| 'use strict'; | ||
| var utils = require('./utils'); | ||
| var predicates = require('./predicates'); | ||
| var is = module.exports; | ||
| // chaining mixin | ||
| function lazy() { | ||
| /* jshint validthis:true */ | ||
| // Enable invocation with operators (+, !, etc) | ||
| this.valueOf = function () { | ||
| return this.val(); | ||
| }; | ||
| this.val = function () { | ||
| return this.lazy.map(function (args) { | ||
| return args[0].apply(null, args[1]); | ||
| })[this.method](predicates.truthy); | ||
| }; | ||
| return this; | ||
| } | ||
| function Every() { | ||
| this.method = 'every'; | ||
| this.lazy = []; | ||
| } | ||
| Every.prototype = Object.keys(predicates).reduce(function (acc, fnName) { | ||
| if (!predicates.fn(predicates[fnName])) return acc; | ||
| acc[fnName] = function() { | ||
| this.lazy.push([predicates[fnName], arguments]); | ||
| return this; | ||
| }; | ||
| return acc; | ||
| }, {}); | ||
| lazy.call(Every.prototype); | ||
| is.all = is.every = function () { | ||
| return new Every(); | ||
| }; | ||
| function Some() { | ||
| this.method = 'some'; | ||
| this.lazy = []; | ||
| } | ||
| Some.prototype = utils.assign({}, Every.prototype); | ||
| lazy.call(Some.prototype); | ||
| is.any = is.some = function () { | ||
| return new Some(); | ||
| }; |
+12
| 'use strict'; | ||
| var predicates = require('./predicates'); | ||
| var utils = require('./utils'); | ||
| var is = module.exports; | ||
| is.ternary = function (pred, a, b) { | ||
| if (predicates.bool(pred)) return pred ? a : b; | ||
| if (predicates.undef(a)) return utils.partial(is.ternary, pred); | ||
| if (predicates.undef(b)) return utils.partial(is.ternary, pred, a); | ||
| return is.ternary(pred(a, b), a, b); | ||
| }; |
| 'use strict'; | ||
| var utils = require('./utils'); | ||
| var is = module.exports; | ||
| var curry = utils.curry; | ||
| if (Object.is) { | ||
| is.is = curry(Object.is); | ||
| } else { | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
| is.is = curry(function(v1, v2) { | ||
| if (v1 === 0 && v2 === 0) { | ||
| return 1 / v1 === 1 / v2; | ||
| } | ||
| if (v1 !== v1) { | ||
| return v2 !== v2; | ||
| } | ||
| return v1 === v2; | ||
| }); | ||
| } | ||
| is.exists = function (val) { | ||
| return val != null; | ||
| }; | ||
| is.truthy = function (val) { | ||
| // coerce for null != null | ||
| return !!(val && is.exists(val)); | ||
| }; | ||
| is.falsey = utils.complement(is.truthy); | ||
| //---- value comparision methods | ||
| is.equal = curry(function (a, b) { | ||
| return a === b; | ||
| }); | ||
| is.eq = curry(function (a, b) { | ||
| return a == b; | ||
| }); | ||
| is.null = is.equal(null); | ||
| is.undef = is.equal(undefined); | ||
| is.lt = is.less = curry(function (a, b) { | ||
| return a < b; | ||
| }); | ||
| is.ltEq = is.lessEq = curry(function (a, b) { | ||
| return is.equal(a, b) || is.less(a, b); | ||
| }); | ||
| is.gt = is.greater = curry(function (a, b) { | ||
| return a > b; | ||
| }); | ||
| is.gtEq = is.greaterEq = curry(function (a, b) { | ||
| return is.equal(a, b) || is.greater(a, b); | ||
| }); | ||
| // --- Type checking predicates | ||
| // Forces objects toString called returned as [object Object] for instance | ||
| var __toString = Object.prototype.toString; | ||
| var eqToStr = curry(function(str, val) { | ||
| return is.equal(str, __toString.call(val)); | ||
| }); | ||
| //---- Object type checks | ||
| is.object = is.obj = function (val) { | ||
| return val === Object(val); | ||
| }; | ||
| is.array = is.arr = Array.isArray || eqToStr('[object Array]'); | ||
| is.date = eqToStr('[object Date]'); | ||
| is.rgx = is.RegExp = eqToStr('[object RegExp]'); | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite | ||
| is.finite = Number.isFinite || function (val) { | ||
| return is.number(val) && isFinite(val); | ||
| }; | ||
| is.NaN = is.is(NaN); | ||
| is.instance = curry(function (Cls, inst) { | ||
| return inst instanceof Cls; | ||
| }); | ||
| is.arguments = eqToStr('[object Arguments]'); | ||
| is.error = is.instance(Error); | ||
| // creates fns for is.string, etc | ||
| var typeofBuilder = curry(function(type, val) { | ||
| return is.equal(type, typeof val); | ||
| }); | ||
| //--- Create typeof methods | ||
| // type of string and alias name | ||
| // is.fn, is.num, etc | ||
| [ | ||
| ['function', 'fn'], | ||
| ['string', 'str'], | ||
| ['boolean', 'bool'] | ||
| ].reduce(function (is, type) { | ||
| is[type[0]] = is[type[1]] = typeofBuilder(type[0]); | ||
| return is; | ||
| }, is); | ||
| is.number = is.num = function(val) { | ||
| return typeof val === 'number' && is.not.NaN(val); | ||
| }; | ||
| is.int = function (val) { | ||
| return is.num(val) && is.zero(utils.mod(val, 1)); | ||
| }; | ||
| is.pos = function (val) { | ||
| return is.num(val) && is.greater(val, 0); | ||
| }; | ||
| is.neg = function (val) { | ||
| return is.num(val) && is.less(val, 0); | ||
| }; | ||
| is.zero = function (val) { | ||
| return is.num(val) && is.equal(val, 0); | ||
| }; | ||
| is.even = function (val) { | ||
| return is.num(val) && | ||
| is.not.zero(val) && | ||
| is.zero(utils.mod(val, 2)); | ||
| }; | ||
| is.odd = function (val) { | ||
| return is.num(val) && | ||
| is.not.zero(val) && | ||
| is.not.zero(utils.mod(val, 2)); | ||
| }; | ||
| is.contains = curry(function (arr, val) { | ||
| if (!is.array(arr)) throw new TypeError('Expected an array'); | ||
| if (is.NaN(val)) { | ||
| return arr.some(is.NaN); | ||
| } | ||
| return !!~arr.indexOf(val); | ||
| }); | ||
| var __has = Object.prototype.hasOwnProperty; | ||
| is.has = curry(function has(o, key) { | ||
| return __has.call(o, key); | ||
| }); | ||
| is.empty = function (o) { | ||
| if (is.not.exists(o)) return true; | ||
| if (is.arr(o) || is.str(o)) return !o.length; | ||
| if (is.obj(o)) { | ||
| for (var k in o) if (is.has(o, k)) return false; | ||
| return true; | ||
| } | ||
| throw new TypeError(); | ||
| }; | ||
| is.primitive = function (val) { | ||
| return is.string(val) || is.num(val) || is.bool(val) || | ||
| is.null(val) || is.undef(val) || is.NaN(val); | ||
| }; | ||
| // Assign inverse of each predicate | ||
| is.not = Object.keys(is).reduce(function (acc, fnName) { | ||
| acc[fnName] = utils.complement(is[fnName]); | ||
| return acc; | ||
| }, {}); |
+60
| 'use strict'; | ||
| var is = module.exports; | ||
| var _slice = Array.prototype.slice; | ||
| // Useful for debuging curried functions | ||
| function setSrc(curried, src) { | ||
| curried.toString = function() { | ||
| return src.toString(); | ||
| }; | ||
| curried.src = src; | ||
| return curried; | ||
| } | ||
| // Curry's fn's with arity 2 | ||
| var curry = is.curry = function(f) { | ||
| return setSrc(function curried(a, b) { | ||
| switch (arguments.length) { | ||
| case 0: throw new TypeError('Function called with no arguments'); | ||
| case 1: | ||
| return setSrc(function curried(b) { | ||
| return f(a, b); | ||
| }, f); | ||
| } | ||
| return f(a, b); | ||
| }, f); | ||
| }; | ||
| is.partial = function (fn) { | ||
| var args = _slice.call(arguments, 1); | ||
| return function() { | ||
| return fn.apply(null, args.concat(_slice.call(arguments))); | ||
| }; | ||
| }; | ||
| is.complement = is.invert = function (pred) { | ||
| return function () { | ||
| var ret = pred.apply(null, arguments); | ||
| // Handle curried fns | ||
| if (typeof ret === 'function') return is.complement(ret); | ||
| return !ret; | ||
| }; | ||
| }; | ||
| is.mod = curry(function (a, b) { | ||
| return a % b; | ||
| }); | ||
| // assign b's props to a | ||
| is.assign = curry(function(a, b) { | ||
| // use crummy for/in for perf purposes | ||
| for (var prop in b) { | ||
| if (b.hasOwnProperty(prop)) { | ||
| a[prop] = b[prop]; | ||
| } | ||
| } | ||
| return a; | ||
| }); | ||
+22
| Copyright (c) 2013-2014 Trevor Landau | ||
| Permission is hereby granted, free of charge, to any person | ||
| obtaining a copy of this software and associated documentation | ||
| files (the "Software"), to deal in the Software without | ||
| restriction, including without limitation the rights to use, | ||
| copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the | ||
| Software is furnished to do so, subject to the following | ||
| conditions: | ||
| The above copyright notice and this permission notice shall be | ||
| included in all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
| OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
| HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| OTHER DEALINGS IN THE SOFTWARE. |
+68
| [](https://travis-ci.org/landau/is) | ||
| [](https://nodei.co/npm/is-predicate/) | ||
| # is.js - Adding clarity and conciseness to your JS through predicates | ||
| `is.js` is a predicate library for JS. `is` doesn't have any dependencies which makes it easy to integrate into new and existing projects. | ||
| ## Docs | ||
| [landau.github.io/is](http://landau.github.io/is/) | ||
| ## install | ||
| > npm install --save is-predicate | ||
| or | ||
| download the file from the [dist](https://github.com/landau/is/dist/is.js) directory | ||
| ## Usage | ||
| ```js | ||
| is.equal(1, 1); // true | ||
| is.not.pos(-1); // true | ||
| is.ternary(true, 'foo', 'bar'); // foo | ||
| is.fn(function () {}); // true | ||
| is.not.equal(1, 3); // true | ||
| ``` | ||
| ### Every/Some | ||
| Every and some are functions that allow you to chain predicate calls. The calls are not evaluated until `.val()` is executed on the chain. | ||
| ```js | ||
| // All evaluations must be true | ||
| is.every().equal(1, 1).contains([1, 2, 3], 2).val(); // true | ||
| is.all().equal(1, 5).contains([1, 2, 3], 2).val(); // false | ||
| // At least one eval must be true | ||
| is.some().equal(1, 1).contains([1, 2, 3], 2).val(); // true | ||
| is.any().equal(1, 5).contains([1, 2, 3], 2).val(); // true | ||
| is.some().equal(1, 5).contains([1, 2, 3], 5).val(); // false | ||
| ``` | ||
| Alternaively to `.val` you can execute `valueOf` | ||
| ```js | ||
| // All evaluations must be true | ||
| !!is.every().equal(1, 1).contains([1, 2, 3], 2); // true | ||
| ``` | ||
| > Notice the alias of `all/any` if you prefer that flavor | ||
| > NOTE: Chaining doesnt work with `.not` yet. | ||
| ## Author | ||
| [Trevor Landau](http://trevorlandau.net) | ||
| ## contributing | ||
| - Suggestions welcome! | ||
| - Tests! | ||
| - Ping me on [twitter](http://twitter.com/trevor_landau) if I take too long to respond! That probably means I missed the alert/email. | ||
| ## Tests | ||
| To run tests, install devDeps and type `npm ts` | ||
| ## Building | ||
| To build, type `npm run build`. | ||
| This will create a UMDified version of is in the `dist` directory along with a minified version. |
| /* jshint expr: true */ | ||
| 'use strict'; | ||
| // Some old coffeescript stuff that is still useful | ||
| var Bar, Foo, addNotTest, addTest, falses, testClasses, truths, _, | ||
| __hasProp = {}.hasOwnProperty, | ||
| __extends = function(child, parent) { | ||
| for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } | ||
| function Ctor() { /*jshint validthis:true */ | ||
| this.constructor = child; | ||
| } | ||
| Ctor.prototype = parent.prototype; | ||
| child.prototype = new Ctor(); | ||
| child.__super__ = parent.prototype; | ||
| return child; | ||
| }; | ||
| var _ = require('lodash'); | ||
| var is = require('../'); | ||
| require('should'); | ||
| testClasses = { | ||
| Foo: Foo = (function() { | ||
| function Foo() {} | ||
| return Foo; | ||
| })() | ||
| }; | ||
| testClasses.Bar = Bar = (function(_super) { | ||
| /*jshint validthis:true */ | ||
| function _Bar() { | ||
| return _Bar.__super__.constructor.apply(this, arguments); | ||
| } | ||
| __extends(_Bar, _super); | ||
| return _Bar; | ||
| })(testClasses.Foo); | ||
| // Wow this is really shit lol. | ||
| // FIXME ditch this shit | ||
| var addTest = function(fn, val, expected, shorthand) { | ||
| if (Array.isArray(val) && val.length) { | ||
| it('should return `' + expected + '` for values `' + val + '`', function() { | ||
| (is[fn].apply(null, val)).should.be[expected]; | ||
| }); | ||
| } else { | ||
| it('should return `' + expected + '` for value `' + val + '`', function() { | ||
| (is[fn](val)).should.be[expected]; | ||
| }); | ||
| } | ||
| if (_.isString(shorthand)) { | ||
| it('should have a shorthand method `' + shorthand + '` for method `' + fn + '`', function() { | ||
| is[shorthand].should.equal(is[fn]); | ||
| }); | ||
| } | ||
| }; | ||
| var addNotTest = function(fn, val, expected) { | ||
| if (Array.isArray(val) && val.length) { | ||
| return it('should return `' + expected + '` for values `' + val + '`', function() { | ||
| return (is.not[fn].apply(null, val)).should.be[expected]; | ||
| }); | ||
| } else { | ||
| return it('should return `' + expected + '` for value `' + val + '`', function() { | ||
| return (is.not[fn](val)).should.be[expected]; | ||
| }); | ||
| } | ||
| }; | ||
| truths = ['dog', 1, [], {}]; | ||
| falses = [null, void 0]; | ||
| describe('is', function() { | ||
| var tests; | ||
| tests = { | ||
| is: { | ||
| truthy: [[undefined, undefined], [null, null], | ||
| [testClasses.Foo, testClasses.Foo], | ||
| [0, 0], [NaN, 0/0]], | ||
| falsey: [[0, -0], [0, false], [NaN, 0]] | ||
| }, | ||
| exists: { | ||
| truthy: truths.concat([0]), | ||
| falsey: falses | ||
| }, | ||
| truthy: { | ||
| truthy: truths, | ||
| falsey: falses | ||
| }, | ||
| falsey: { | ||
| truthy: falses, | ||
| falsey: truths | ||
| }, | ||
| 'null': { | ||
| truthy: [null], | ||
| falsey: [void 0, 'dog', 1, []] | ||
| }, | ||
| undef: { | ||
| truthy: [void 0], | ||
| falsey: [null, '', 'dog', 1, []] | ||
| }, | ||
| equal: { | ||
| truthy: [[0, 0], ['dog', 'dog']], | ||
| falsey: [[0, 1], ['cat', 'dog'], [0, '0']] | ||
| }, | ||
| eq: { | ||
| truthy: [[0, '0']], | ||
| falsey: [[0, 1], ['cat', 'dog']] | ||
| }, | ||
| less: { | ||
| truthy: [[0, 1]], | ||
| falsey: [[1, 0]] | ||
| }, | ||
| greater: { | ||
| truthy: [[1, 0]], | ||
| falsey: [[0, 1]] | ||
| }, | ||
| lessEq: { | ||
| truthy: [[0, 1], [0, 0]], | ||
| falsey: [[1, 0]] | ||
| }, | ||
| greaterEq: { | ||
| truthy: [[1, 0], [0, 0]], | ||
| falsey: [[0, 1]] | ||
| }, | ||
| object: { | ||
| truthy: [{}, [], new Date()], | ||
| falsey: [null, 'a', 1] | ||
| }, | ||
| array: { | ||
| truthy: [[]], | ||
| falsey: [{}, 'a', 1, new Date()] | ||
| }, | ||
| date: { | ||
| truthy: [new Date()], | ||
| falsey: [{}, 'a', 1] | ||
| }, | ||
| RegExp: { | ||
| truthy: [/\d/], | ||
| falsey: [{}, 'a', 1, [], new Date()], | ||
| shorthand: 'rgx' | ||
| }, | ||
| NaN: { | ||
| truthy: [NaN], | ||
| falsey: falses.concat([], 1, /\d/, '1', {}) | ||
| }, | ||
| 'function': { | ||
| truthy: [function() {}], | ||
| falsey: [{}, 'a', 1, new Date()], | ||
| shorthand: 'fn' | ||
| }, | ||
| number: { | ||
| truthy: [1], | ||
| falsey: ['1', new Date(), NaN], | ||
| shorthand: 'num' | ||
| }, | ||
| string: { | ||
| truthy: ['dog'], | ||
| falsey: [[], 1], | ||
| shorthand: 'str' | ||
| }, | ||
| finite: { | ||
| truthy: [1, 2e64], | ||
| falsey: [NaN, -Infinity, Infinity, '1', new Date()] | ||
| }, | ||
| int: { | ||
| truthy: [1, 2e64, -5, 0], | ||
| falsey: [1.2, -Infinity, Infinity, '1', new Date()] | ||
| }, | ||
| pos: { | ||
| truthy: [1, 5, 10.2], | ||
| falsey: [0, -1, 'a', {}] | ||
| }, | ||
| neg: { | ||
| truthy: [-1, -5, -10.2], | ||
| falsey: [0, 1, 'a', {}] | ||
| }, | ||
| zero: { | ||
| truthy: [0], | ||
| falsey: [1, 'foo', '0', {}] | ||
| }, | ||
| even: { | ||
| truthy: [2, -6], | ||
| falsey: [0, 3, 'foo'] | ||
| }, | ||
| odd: { | ||
| truthy: [1, -11], | ||
| falsey: [0, 4, 'foo'] | ||
| }, | ||
| 'instance': { | ||
| truthy: [[Object, {}], [Array, []], | ||
| [testClasses.Foo, new testClasses.Foo()], [testClasses.Foo, new testClasses.Bar()], | ||
| [testClasses.Bar, new testClasses.Bar()]], | ||
| falsey: [[Array, {}], [testClasses.Bar, new testClasses.Foo()]] | ||
| }, | ||
| primitive: { | ||
| truthy: [1, null, undefined, NaN, true, false, 'foo'], | ||
| falsey: [{}, [], function() {}, new testClasses.Foo()] | ||
| }, | ||
| empty: { | ||
| truthy: [{}, ''], | ||
| falsey: [{ foo: 'bar' }, 'hi'] | ||
| } | ||
| }; | ||
| _.each(tests, function(expectations, methodName) { | ||
| return describe('normal tests', function() { | ||
| return describe('' + methodName, function() { | ||
| var shorthand = expectations.shorthand; | ||
| var truthy = expectations.truthy; | ||
| var falsey = expectations.falsey; | ||
| _.each(truthy, function(val) { | ||
| addTest(methodName, val, true, shorthand); | ||
| }); | ||
| _.each(falsey, function(val) { | ||
| addTest(methodName, val, false, shorthand); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| _.each(tests, function(expectations, methodName) { | ||
| return describe('not tests', function() { | ||
| return describe('' + methodName, function() { | ||
| var shorthand = expectations.shorthand; | ||
| var truthy = expectations.truthy; | ||
| var falsey = expectations.falsey; | ||
| _.each(truthy, function(val) { | ||
| addNotTest(methodName, val, false, shorthand); | ||
| }); | ||
| _.each(falsey, function(val) { | ||
| addNotTest(methodName, val, true, shorthand); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| describe('#arguments', function() { | ||
| it('should return true for arguments', function() { | ||
| var fn = function() { | ||
| return (is.arguments(arguments)).should.be.true; | ||
| }; | ||
| fn(); | ||
| }); | ||
| _.each(falses.concat(truths), function(val) { | ||
| addTest('arguments', val, false); | ||
| }); | ||
| }); | ||
| describe('#invert', function() { | ||
| before(function() { | ||
| this.testFn = is.invert(is.fn); | ||
| }); | ||
| it('should return a function', function() { | ||
| this.testFn.should.be.instanceof(Function); | ||
| }); | ||
| it('should return an inverted value', function() { | ||
| this.testFn(is.equal).should.false; | ||
| }); | ||
| it('should alias complement', function() { | ||
| is.invert.should.equal(is.complement); | ||
| }); | ||
| }); | ||
| describe('#contains', function() { | ||
| var arr; | ||
| arr = [1, 2, 3]; | ||
| it('should return false if the value is not found', function() { | ||
| is.contains(arr, 5).should.be.false; | ||
| }); | ||
| it('should return true if the value is found', function() { | ||
| is.contains(arr, 1).should.be.true; | ||
| is.contains(arr, 2).should.be.true; | ||
| is.contains(arr, 3).should.be.true; | ||
| is.contains([0, NaN], NaN).should.be.true; | ||
| }); | ||
| }); | ||
| describe('#empty', function() { | ||
| it('should return true for an empty array', function() { | ||
| is.empty([]).should.be.true; | ||
| }); | ||
| it('should return false for a non-empty array', function() { | ||
| is.empty([1]).should.be.false; | ||
| }); | ||
| it('should throw for non str/arr/obj', function() { | ||
| var err = null; | ||
| try { | ||
| is.empty(true); | ||
| } catch(e) { err = e; } | ||
| err.should.be.instanceOf(TypeError); | ||
| }); | ||
| }); | ||
| describe('#has', function() { | ||
| it('should return true if the key is found', function() { | ||
| is.has({ | ||
| foo: 3 | ||
| }, 'foo').should.be.true; | ||
| }); | ||
| it('should return false if the key is not on on the obj', function() { | ||
| is.has({ | ||
| foo: 3 | ||
| }, 'toString').should.be.false; | ||
| }); | ||
| }); | ||
| describe('#ternary', function() { | ||
| it('should return 1 for a truthy value', function() { | ||
| is.ternary(true, 1, 2).should.equal(1); | ||
| }); | ||
| it('should return 2 for a falsey value', function() { | ||
| is.ternary(false, 1, 2).should.equal(2); | ||
| }); | ||
| it('should return 1 for a lesser value', function() { | ||
| is.ternary(is.less, 1, 2).should.equal(1); | ||
| }); | ||
| it('should return 1 for a greater value', function() { | ||
| is.ternary(is.less, 2, 1).should.equal(1); | ||
| }); | ||
| it('should return a function for a pred given', function() { | ||
| var fn = is.ternary(is.less); | ||
| fn.should.be.a.function; | ||
| fn(1, 2).should.equal(1); | ||
| fn(2, 1).should.equal(1); | ||
| }); | ||
| it('should return a function for a pred and arg given', function() { | ||
| var fn = is.ternary(is.less, 1); | ||
| fn.should.be.a.function; | ||
| fn(2).should.equal(1); | ||
| }); | ||
| }); | ||
| describe('#every', function() { | ||
| it('should map to .all', function() { | ||
| is.every.should.equal(is.all); | ||
| }); | ||
| it('should return an object', function() { | ||
| is.every().should.be.an.object; | ||
| }); | ||
| it('should allow chaining', function() { | ||
| is.every().equal(1, 1).str('5').val().should.be.ok; | ||
| is.every().str('foo').contains([1, 2, 3], 1).val().should.be.ok; | ||
| is.every().str(1).contains([1, 2, 3], 1).val().should.be.false; | ||
| is.every().str('foo').contains([1, 2, 3], 5).val().should.be.false; | ||
| }); | ||
| }); | ||
| describe('#some', function() { | ||
| it('should map to .any', function() { | ||
| is.some.should.equal(is.any); | ||
| }); | ||
| it('should return an object', function() { | ||
| is.some().should.be.an.object; | ||
| }); | ||
| it('should allow chaining', function() { | ||
| is.some().equal(1, 1).str('5').val().should.be.ok; | ||
| is.some().str('foo').contains([1, 2, 3], 1).val().should.be.ok; | ||
| is.some().str(1).contains([1, 2, 3], 1).val().should.be.ok; | ||
| is.some().str('foo').contains([1, 2, 3], 5).val().should.be.ok; | ||
| is.some().num('foo').contains([1, 2, 3], 5).val().should.be.false; | ||
| }); | ||
| }); | ||
| describe('#Lazy', function() { | ||
| it('should call `val` when valueOf is called', function() { | ||
| +(is.some().equal(1, 1).str('5')).should.be.ok; | ||
| !!(is.some().equal(1, 1).str('5')).should.be.ok; | ||
| }); | ||
| }); | ||
| describe('#partial', function() { | ||
| var fn = null; | ||
| before(function() { | ||
| fn = is.partial(is.less, 1); | ||
| }); | ||
| it('should return a fn', function() { | ||
| fn.should.be.a.function; | ||
| }); | ||
| it('should exec the fn as expected', function() { | ||
| fn(2).should.be.ok; | ||
| }); | ||
| }); | ||
| describe('#curry', function() { | ||
| before(function() { | ||
| this.add = function(a, b) { | ||
| return a + b; | ||
| }; | ||
| this.fn = is.curry(this.add); | ||
| }); | ||
| it('should return an fn', function() { | ||
| this.fn.should.be.a.function; | ||
| }); | ||
| it('should source the original function', function() { | ||
| this.fn.src.should.equal(this.add); | ||
| }); | ||
| it('should throw a TypeError if no args are provided', function() { | ||
| var err = null; | ||
| try { | ||
| this.fn(); | ||
| } catch(e) { | ||
| err = e; | ||
| } | ||
| err.should.be.instanceof(TypeError); | ||
| }); | ||
| it('should return a new curried fn for arity 1', function() { | ||
| var fn = this.fn(1); | ||
| fn.should.be.a.function; | ||
| fn.src.should.equal(this.add); | ||
| fn(2).should.equal(3); | ||
| }); | ||
| it('should execute an arity 2 fn', function() { | ||
| this.fn(1, 2).should.equal(3); | ||
| }); | ||
| it('should curry with is.not', function() { | ||
| var fn = is.not.equal(1); | ||
| fn.should.be.a.function; | ||
| fn(1).should.be.false; | ||
| fn(2).should.be.true; | ||
| }); | ||
| }); | ||
| describe('#mod', function() { | ||
| it('should return a modulus value', function() { | ||
| is.mod(6, 5).should.equal(1); | ||
| is.mod(6, 6).should.equal(0); | ||
| }); | ||
| }); | ||
| describe('#assign', function() { | ||
| it('should copy values to a new object', function() { | ||
| var x = { foo: 'bar' }; | ||
| var y = { bar: 'foo' }; | ||
| var z = is.assign(x, y); | ||
| z.foo.should.equal('bar'); | ||
| z.bar.should.equal('foo'); | ||
| }); | ||
| }); | ||
| }); |
+11
-57
@@ -0,60 +1,14 @@ | ||
| 'use strict'; | ||
| { | ||
| { | ||
| var utils = require('./lib/utils'); | ||
| var is = {}; | ||
| is.VERSION = '0.10.1'; | ||
| function every7(ee){ | ||
| for(var i=0,l=ee.length;i<l;i++){ | ||
| if(!ee[i]) return false} | ||
| return true} | ||
| [ | ||
| utils, | ||
| require('./lib/predicates'), | ||
| require('./lib/chain'), | ||
| require('./lib/other'), | ||
| ].reduce(utils.assign, is); | ||
| function empty7(ee){ | ||
| return ee.length===0} | ||
| function any7(fn,ee){ | ||
| for(var i=0,l=ee.length;i<l;i++){ | ||
| var r=fn(ee[i]) | ||
| if(r) return r;}} | ||
| function member7(it,ee){ | ||
| for(var i=0,l=ee;i<l;i++){ | ||
| if(ee[i]===it) return true} | ||
| return false} | ||
| function head(ee){ | ||
| return ee[0]} | ||
| function tail(ee){ | ||
| return ee.slice(1)} | ||
| function reverse(ee){ | ||
| return ee.reverse()} | ||
| function map(fn,ee){ | ||
| var r=Array(ee.length); | ||
| for(var i=0,l=ee.length;i<l;i++){ | ||
| r[i]=fn(ee[i])} | ||
| return r[i]} | ||
| function pair(it,ee){ | ||
| ee.unshift(it); | ||
| return ee} | ||
| function concatenate(l1,l2){ | ||
| return l1.concat(l2)} | ||
| module.exports={ | ||
| every7:every7, | ||
| empty7:empty7, | ||
| any7:any7, | ||
| member7:member7, | ||
| reverse:reverse, | ||
| tail:tail, | ||
| head:head, | ||
| map:map, | ||
| pair:pair, | ||
| concatenate:concatenate, | ||
| } | ||
| } | ||
| } | ||
| module.exports = is; |
+54
-10
| { | ||
| "author": "Dmitry Unkovksy <oil.crayons@gmail.com>", | ||
| "name": "predicate", | ||
| "description": "trivial predicates to aid list tossing", | ||
| "version": "0.0.1", | ||
| "homepage": "http://nojs.be/predicate", | ||
| "version": "0.10.1", | ||
| "description": "A set of predicate functions to improve your value testing and comparisons.", | ||
| "scripts": { | ||
| "pretest": "jshint --reporter node_modules/jshint-stylish/stylish.js index.js ./test", | ||
| "test": "mocha -R spec --recursive test", | ||
| "docs": "jade ./docs/index.jade --out ./docs", | ||
| "changelog": "tail -n +4 ./docs/changelog.jade > CHANGELOG.md", | ||
| "build-docs": "npm run docs && npm run changelog", | ||
| "build-dev": "cat ./docs/banner.txt > ./dist/is.js && browserify -s is index.js >> ./dist/is.js", | ||
| "build-prod": "cat ./docs/banner.txt > ./dist/is.min.js && uglifyjs ./dist/is.js >> ./dist/is.min.js", | ||
| "build": "npm run build-dev && npm run build-prod", | ||
| "clean": "rm ./dist/* ./docs/index.html CHANGELOG.md", | ||
| "prepare": "npm ts && npm run build && npm run build-docs" | ||
| }, | ||
| "main": "index.js", | ||
| "author": { | ||
| "name": "Trevor Landau", | ||
| "email": "landautrevor@gmail.com", | ||
| "url": "http://trevorlandau.net" | ||
| }, | ||
| "homepage": "http://landau.github.io/is", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git://github.com/nojs/predicate.git" | ||
| "url": "http://github.com/landau/is" | ||
| }, | ||
| "main":"./index.js", | ||
| "engines": { | ||
| "node": ">=0.4" | ||
| "bugs": { | ||
| "url": "http://github.com/landau/is/issues" | ||
| }, | ||
| "dependencies": {}, | ||
| "devDependencies": {} | ||
| "keywords": [ | ||
| "functional", | ||
| "predicates", | ||
| "predicate", | ||
| "pred", | ||
| "type", | ||
| "instance", | ||
| "comparator", | ||
| "compare", | ||
| "curry", | ||
| "partial", | ||
| "is", | ||
| "testing", | ||
| "test", | ||
| "chain", | ||
| "chaining" | ||
| ], | ||
| "license": "MIT", | ||
| "devDependencies": { | ||
| "browserify": "^3.44.2", | ||
| "jade": "^1.5.0", | ||
| "jshint": "^2.5.2", | ||
| "jshint-stylish": "^0.4.0", | ||
| "lodash": "~2.4.1", | ||
| "marked": "^0.3.2", | ||
| "matcha": "^0.5.0", | ||
| "mocha": "^1.21.4", | ||
| "should": "^4.0.4", | ||
| "uglify-js": "^2.4.13" | ||
| } | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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 bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
103563
6930.75%21
950%943
1950%0
-100%69
Infinity%0
-100%10
Infinity%2
Infinity%