Comparing version
193
index.js
@@ -1,179 +0,132 @@ | ||
var t = require('tcomb'); | ||
// fcomb 0.1.0 | ||
// https://github.com/gcanti/fcomb | ||
// (c) 2014 Giulio Canti <giulio.canti@gmail.com> | ||
// fcomb may be freely distributed under the MIT license. | ||
var format = t.util.format; | ||
'use strict'; | ||
function getDoc(f) { | ||
return f.__doc__ || f.meta.doc; | ||
} | ||
module.exports = { | ||
and: and, | ||
or: or, | ||
not: not, | ||
lt: lt, | ||
lte: lte, | ||
gt: gt, | ||
gte: gte, | ||
minLength: minLength, | ||
maxLength: maxLength, | ||
regexp: regexp | ||
}; | ||
function addDoc(f, doc) { | ||
f.__doc__ = doc; | ||
if (f.meta) { | ||
f.meta.doc = doc; | ||
} else { | ||
f.meta = { | ||
kind: 'irriducible', | ||
doc: doc | ||
}; | ||
} | ||
return f; | ||
} | ||
function and(f, g, doc) { | ||
doc = doc || format('%s and %s', getDoc(f), getDoc(g)); | ||
function and(x) { | ||
function and(f, g) { | ||
var ret = function and(x) { | ||
return f(x) && g(x); | ||
} | ||
and.meta = { | ||
}; | ||
ret.fmeta = { | ||
kind: 'and', | ||
f: f, | ||
g: g, | ||
doc: doc | ||
g: g | ||
}; | ||
and.__doc__ = doc; | ||
return and; | ||
return ret; | ||
} | ||
function or(f, g, doc) { | ||
doc = doc || format('%s or %s', getDoc(f), getDoc(g)); | ||
function or(x) { | ||
function or(f, g) { | ||
var ret = function or(x) { | ||
return f(x) || g(x); | ||
} | ||
or.meta = { | ||
}; | ||
ret.fmeta = { | ||
kind: 'or', | ||
f: f, | ||
g: g, | ||
doc: doc | ||
g: g | ||
}; | ||
or.__doc__ = doc; | ||
return or; | ||
return ret; | ||
} | ||
function not(f, doc) { | ||
doc = doc || format('not %s', getDoc(f)); | ||
function not(x) { | ||
function not(f) { | ||
var ret = function not(x) { | ||
return !f(x); | ||
} | ||
not.meta = { | ||
}; | ||
ret.fmeta = { | ||
kind: 'not', | ||
f: f, | ||
doc: doc | ||
f: f | ||
}; | ||
not.__doc__ = doc; | ||
return not; | ||
return ret; | ||
} | ||
function lt(sup, doc) { | ||
doc = doc || format('less then %s', sup); | ||
function lt(x) { | ||
function lt(sup) { | ||
var ret = function lt(x) { | ||
return x < sup; | ||
} | ||
lt.meta = { | ||
}; | ||
ret.fmeta = { | ||
kind: 'lt', | ||
sup: sup, | ||
doc: doc | ||
sup: sup | ||
}; | ||
lt.__doc__ = doc; | ||
return lt; | ||
return ret; | ||
} | ||
function lte(max, doc) { | ||
doc = doc || format('less or equal to %s', max); | ||
function lte(x) { | ||
function lte(max) { | ||
var ret = function lte(x) { | ||
return x <= max; | ||
} | ||
lte.meta = { | ||
}; | ||
ret.fmeta = { | ||
kind: 'lte', | ||
max: max, | ||
doc: doc | ||
max: max | ||
}; | ||
lte.__doc__ = doc; | ||
return lte; | ||
return ret; | ||
} | ||
function gt(inf, doc) { | ||
doc = doc || format('greater then %s', inf); | ||
function gt(x) { | ||
function gt(inf) { | ||
var ret = function gt(x) { | ||
return x > inf; | ||
} | ||
gt.meta = { | ||
}; | ||
ret.fmeta = { | ||
kind: 'gt', | ||
inf: inf, | ||
doc: doc | ||
inf: inf | ||
}; | ||
gt.__doc__ = doc; | ||
return gt; | ||
return ret; | ||
} | ||
function gte(min, doc) { | ||
doc = doc || format('greater or equal to %s', min); | ||
function gte(x) { | ||
function gte(min) { | ||
var ret = function gte(x) { | ||
return x >= min; | ||
} | ||
gte.meta = { | ||
}; | ||
ret.fmeta = { | ||
kind: 'gte', | ||
min: min, | ||
doc: doc | ||
min: min | ||
}; | ||
gte.__doc__ = doc; | ||
return gte; | ||
return ret; | ||
} | ||
function maxLength(max, doc) { | ||
doc = doc || format('length less or equal to %s', max); | ||
function maxLength(x) { | ||
function maxLength(max) { | ||
var ret = function maxLength(x) { | ||
return x.length <= max; | ||
} | ||
maxLength.meta = { | ||
ret.fmeta = { | ||
kind: 'maxLength', | ||
maxLength: max, | ||
doc: doc | ||
max: max | ||
}; | ||
maxLength.__doc__ = doc; | ||
return maxLength; | ||
return ret; | ||
} | ||
function minLength(min, doc) { | ||
doc = doc || format('length greater or equal to %s', min); | ||
function minLength(x) { | ||
function minLength(min) { | ||
var ret = function minLength(x) { | ||
return x.length >= min; | ||
} | ||
minLength.meta = { | ||
ret.fmeta = { | ||
kind: 'minLength', | ||
minLength: min, | ||
doc: doc | ||
min: min | ||
}; | ||
minLength.__doc__ = doc; | ||
return minLength; | ||
return ret; | ||
} | ||
function regexp(re, doc) { | ||
doc = doc || format('pattern %s', re.toString()); | ||
function regexp(x) { | ||
var ret = function regexp(x) { | ||
return re.test(x); | ||
} | ||
regexp.meta = { | ||
ret.fmeta = { | ||
kind: 'regexp', | ||
re: re, | ||
doc: doc | ||
re: re | ||
}; | ||
regexp.__doc__ = doc; | ||
return regexp; | ||
return ret; | ||
} | ||
module.exports = { | ||
util: { | ||
addDoc: addDoc, | ||
getDoc: getDoc | ||
}, | ||
and: and, | ||
or: or, | ||
not: not, | ||
lt: lt, | ||
lte: lte, | ||
gt: gt, | ||
gte: gte, | ||
maxLength: maxLength, | ||
minLength: minLength, | ||
regexp: regexp | ||
}; |
{ | ||
"name": "fcomb", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Function combinators", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test/test" | ||
}, | ||
@@ -19,14 +20,12 @@ "repository": { | ||
"dependencies": { | ||
"tcomb": "~0.2.1" | ||
}, | ||
"devDependencies": { | ||
"tape": "^3.0.3" | ||
}, | ||
"tags": [ | ||
"function", | ||
"combinators" | ||
], | ||
"keywords": [ | ||
"function", | ||
"combinators" | ||
] | ||
} |
@@ -1,4 +0,1 @@ | ||
fcomb | ||
===== | ||
Function combinators |
0
-100%5
25%3569
-21.85%1
Infinity%119
-27.44%2
-60%- Removed
- Removed