Skip to content
Functional conditions and compositions.
Branch: develop
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.


Functional conditions and compositions (uses Formi).


Codeship Status for krambuhl/Kondico

Code Climate

Test Coverage

API Docs

Kondico exposes the Kondico function.

  • Kondico(boolean, [options]) -> Function
  • Kondico(func, [options]) -> Function

####Kondico(boolean, [options])

Defines function that returns input boolean.


var isTrue = Kondico(true);
isTrue(); // ==> true

####Kondico(func, [options])

Defines function that returns result of a called function.


var isDefined = Kondico(function(val) { return val !== undefined;  }); 
isDefined(640) // true
isDefined(undefined) // false

###Kondico Options

Option Value Description
once Boolean Only run function body once, cache result
memoize Boolean/Function Only run function body once per input value

####Kondico(func, { once: true })

Defines a function that runs it's body a single time, any subsequent calls will return that same value without running that function body.


var hasJquery = Kondico(function() {
    return typeof jQuery === 'function';
}, { once: true });

if (hasJquery()) {
    alert('has jquery: ' + hasJquery());

####Kondico(func, { memoize: true })

Defines a function that runs it's body a single time for each unique input, any subsequent calls with the same input will return the same value without running the function body.

memoize option can be a boolean value or a hashFunction that returns an id used to cache a functions return; hashFunction will return first argument by default.


var has = Kondico(function(val) {
    return typeof val === 'function';
}, { memoize: true });

if (has(jQuery)) {
    alert('has jquery: ' + has(jQuery));

##Compositions (Logic Gates)

Kondico defines logic gate function for composing more complex conditions. All functions will operate on any number of arguments. not returns an array if more than one argument is passed.

  • Kondico.not
  • Kondico.or
  • Kondico.and
  • Kondico.nor
  • Kondico.nand
  • Kondico.xor
  • Kondico.xnor

Example Useages

####Media Queries

var smallSize = Kondico(function(val) { return val < 720;  }); 
var largeSize = Kondico(function(val) { return val > 1280; });
var mediumSize = Kondico.nor(smallSize, largeSize);

// example window size (960x720)
smallSize(window.innerWidth) // false
mediumSize(window.innerWidth) // true
largeSize(window.innerWidth) // false

####Feature Detection

var hasCanvas = Kondico(function() {
    var elem = createElement('canvas');
    return !!(elem.getContext && elem.getContext('2d'));
}, { once: true }); 
You can’t perform that action at this time.