JSFiddle - React, Tailwind, and code Playground
by ifandelse
JavaScript
// Utilities - to be put in an external file
function isArray(value) {
var s = typeof value;
if (s === 'object') {
if (value) {
if (typeof value.length === 'number' &&
!(value.propertyIsEnumerable('length')) &&
typeof value.splice === 'function') {
s = 'array';
}
}
}
return s === 'array';
};
function simpleCallback(notification) {
document.write("Rule Notification Received: " + notification.message + " [Passed]: " + notification.rulePassing + "<br />");
};
var model = {
username: "Jim"
};
// mikado.js handle...
mk = {};
mk.predicates = {};
// Predicate base
mk['predicate'] = function(exp) {
var _exp = exp;
this['apply'] = function(x) {
return _exp(x);
};
};
// Out-of-the-box predicates you can use if you so desire....
mk['predicates'] = {};
// X should be lte Y
mk['predicates']['shouldBeLessThanOrEqual'] = function(limit) {
return new mk['predicate'](function(x) { return x <= limit; } );
};
// X should be gte Y
mk['predicates']['shouldBeGreaterThanOrEqual'] = function(limit) {
return new mk['predicate'](function(x) { return x >= limit; } );
};
// X should be lt Y
mk['predicates']['shouldBeLessThan'] = function(limit) {
return new mk['predicate'](function(x) { return x < limit; } );
};
//X should be gt Y
mk['predicates']['shouldBeGreaterThan'] = function(limit) {
return new mk['predicate'](function(x) { return x > limit; } );
};
// X should be between Y and Z [Inclusive]
mk['predicates']['shouldBeInRange'] = function(low, high) {
return new mk['predicate'](function(x) { return x >= low && x <= high; } );
};
// X should be between Y and Z [Exclusive]
mk['predicates']['shouldBeInRangeExclusive'] = function(low, high) {
return new mk['predicate'](function(x) { return x > low && x < high; } );
};
// X is required
mk['predicates']['shouldNotBeEmpty'] = function() {
return new...