functional-lite
Advanced tools
Comparing version 0.3.1 to 0.3.2
/*! litejs.com/MIT-LICENSE.txt */ | ||
!function(r,f){function n(a,b,c){if(a&&a.constructor===f){b={};for(c in a)k.call(a,c)&&(b[c]=n(a[c]));a=b}return a}function t(){return!0}function u(){return!1}function m(a,b){for(var c="_",d=a,h=a.split("->");1<h.length;)d=h.pop(),c=h.pop().match(/\w+/g)||"",h.length&&h.push("(function("+c+"){return("+d+")})");return new Function(c,(b&&(a=a.replace(v,"").match(/\b[a-z]\w*|\b_\w+/g))?"var "+a.uniq().join("='',")+"='';with("+b+"||{})":"")+"return("+d+")")}var e=Array.prototype,g=Function.prototype, | ||
p=String.prototype,k=f.prototype.hasOwnProperty,l=g.call.bind(e.slice),q={},v=/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|this|arguments|\.\w+|\w+:/g;g.construct=function(a,b){return(b=a.length)?(q[b]||(q[b]=m("t a->new t(a["+f.keys(a).join("],a[")+"])")))(this,a):new this};g.partial=function(){var a=this,b=l(arguments);return function(){return a.apply(this,b.concat.apply(b,arguments))}};g.byWords=function(a,b){var c=this;return function(){var d=this,h=d,e=arguments;(e[a|=0]||"").replace(b||/\S+/g,function(b){e[a]= | ||
b;h=c.apply(d,e)});return h}};g.byKeyVal=function(){var a=this;return function(b){var c,d=l(arguments);if("object"==typeof b)for(c in b)d[0]=c,d[1]=b[c],c=a.apply(this,d);else c=a.apply(this,d);return c}};g.cache=function(a,b,c){var d=this,e=c||{},f=function(){var c=arguments,g=!!a||this instanceof f,k=b?b.apply(d,c):g+":"+c.length+":"+l(c);return k in e?e[k]:e[k]=g?d.construct(c):d.apply(this,c)};f.origin=d;f.cached=e;f.extend=function(){return d.extend.apply(d,arguments).cache(a,b,c)};f.prototype= | ||
d.prototype;return f};g.extend=function(){function a(){return c.apply(this,arguments)}var b,c=this,d=0;for(a.prototype=f.create(c.prototype);b=arguments[d++];)f.merge(a.prototype,b);return a.prototype.constructor=a};f.each=function(a,b,c,d){if(a)for(d in a)k.call(a,d)&&b.call(c,a[d],d,a)};f.merge=function(a,b){for(var c,d=1;b=arguments[d++];)for(c in b)k.call(b,c)&&(a[c]=b[c]);return a};f.clone=n;f.zip=function(a,b){return a.fold(function(a,d,e){a[d]=b[e];return a},{})};e.remove=function(){for(var a= | ||
this.length,b=l(arguments),c=-1;a--;)~b.indexOf(this[a])&&this.splice(c=a,1);return c};e.each=e.forEach;e.fold=e.reduce;e.foldr=e.reduceRight;e.uniq=e.filter.partial(function(a,b,c){return b==c.indexOf(a)});e.pushUniq=function(a){return-1==this.indexOf(a)?this.push(a):!1};!function(a){g[a]=p[a]=function(){var b=arguments,c=b[0];b[0]=this.fn();return e[a].apply(c,b)}}.byWords()("every filter each map fold foldr some");g.fn=function(){return this};p.fn=function(a){return m(this,a)};Boolean.prototype.fn= | ||
function(){return this.valueOf()?t:u};r.Fn=m.cache()}(this,Object); | ||
!function(t,f){function n(a,b,c){if(a&&a.constructor===f){b={};for(c in a)k.call(a,c)&&(b[c]=n(a[c]));a=b}return a}function p(){for(var a=this.length,b=l(arguments),c=-1;a--;)~b.indexOf(this[a])&&this.splice(c=a,1);return c}function m(a,b){for(var c=["_"],d=a,h=a.split("->");1<h.length;)d=h.pop(),c=h.pop().match(/\w+/g)||[],h.length&&h.push("(function("+c+"){return("+d+")})");return new Function(c,(b&&(a=a.replace(u,"").match(/\b[a-z]\w*|\b_\w+/g))?(p.apply(a,c),a[0]?"var "+a.uniq().join("='',")+ | ||
"='';":"")+"with("+b+"||{})":"")+"return("+d+")")}function v(){return!0}function w(){return!1}var e=Array.prototype,g=Function.prototype,q=String.prototype,k=f.prototype.hasOwnProperty,l=g.call.bind(e.slice),r={},u=/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|this|arguments|window|\.\w+|\w+:/g;g.construct=function(a,b){return(b=a.length)?(r[b]||(r[b]=m("t a->new t(a["+f.keys(a).join("],a[")+"])")))(this,a):new this};g.partial=function(){var a=this,b=l(arguments);return function(){return a.apply(this,b.concat.apply(b, | ||
arguments))}};g.byWords=function(a,b){var c=this;return function(){var d=this,h=d,e=arguments;(e[a|=0]||"").replace(b||/\S+/g,function(b){e[a]=b;h=c.apply(d,e)});return h}};g.byKeyVal=function(){var a=this;return function(b){var c,d=l(arguments);if("object"==typeof b)for(c in b)d[0]=c,d[1]=b[c],c=a.apply(this,d);else c=a.apply(this,d);return c}};g.cache=function(a,b,c){var d=this,e=c||{},f=function(){var c=arguments,g=!!a||this instanceof f,k=b?b.apply(d,c):g+":"+c.length+":"+l(c);return k in e?e[k]: | ||
e[k]=g?d.construct(c):d.apply(this,c)};f.origin=d;f.cached=e;f.extend=function(){return d.extend.apply(d,arguments).cache(a,b,c)};f.prototype=d.prototype;return f};g.extend=function(){function a(){return c.apply(this,arguments)}var b,c=this,d=0;for(a.prototype=f.create(c.prototype);b=arguments[d++];)f.merge(a.prototype,b);return a.prototype.constructor=a};f.each=function(a,b,c,d){if(a)for(d in a)k.call(a,d)&&b.call(c,a[d],d,a)};f.merge=function(a,b){for(var c,d=1;b=arguments[d++];)for(c in b)k.call(b, | ||
c)&&(a[c]=b[c]);return a};f.clone=n;f.zip=function(a,b){return a.fold(function(a,d,e){a[d]=b[e];return a},{})};e.remove=p;e.each=e.forEach;e.fold=e.reduce;e.foldr=e.reduceRight;e.uniq=e.filter.partial(function(a,b,c){return b==c.indexOf(a)});e.pushUniq=function(a){return-1==this.indexOf(a)?this.push(a):!1};!function(a){g[a]=q[a]=function(){var b=arguments,c=b[0];b[0]=this.fn();return e[a].apply(c,b)}}.byWords()("every filter each map fold foldr some");g.fn=function(){return this};q.fn=function(a){return m(this, | ||
a)};Boolean.prototype.fn=function(){return this.valueOf()?v:w};t.Fn=m.cache()}(this,Object); |
84
index.js
@@ -5,4 +5,4 @@ | ||
/* | ||
* @version 0.3.1 | ||
* @date 2015-03-23 | ||
* @version 0.3.2 | ||
* @date 2015-05-11 | ||
* @stability 2 - Unstable | ||
@@ -21,3 +21,3 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
, fns = {} | ||
, fnRe = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|this|arguments|\.\w+|\w+:/g | ||
, fnRe = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|this|arguments|window|\.\w+|\w+:/g | ||
@@ -130,2 +130,38 @@ | ||
/* | ||
if (!Array.from) Array.from = arrayFrom | ||
function arrayFrom(obj) { | ||
for (var arr = [], i = 0, len = obj.length; i < len; ) { | ||
arr[i] = obj[i++] | ||
} | ||
return arr | ||
} | ||
Object.values = function(obj) { | ||
return Object.keys(obj).map(function(e) { | ||
return obj[e] | ||
}) | ||
} | ||
Object.values({a:1, b:2, c:3}); //[1, 2, 3] | ||
Array.prototype.flatten = function(){ | ||
var arr = this, i = arr.length; | ||
while (i--) if (arr[i] instanceof Array) | ||
arr[i].unshift(i,1) && arr.splice.apply(arr,arr[i].flatten() ) | ||
return arr | ||
} | ||
function argsToArray(){ | ||
return Array.apply(null, arguments).flatten() | ||
} | ||
argsToArray([[1],3,[4,5]],2) | ||
Array.flatten = function(arr) { | ||
for(var i=arr.length;i--;) | ||
0 in arr[i] && A.splice.apply(arr, [i, 1].concat(Array.flatten(arr[i]))) | ||
return arr | ||
} | ||
flat([1,2,[3,4,[5,6]],7]) | ||
*/ | ||
// Note: use for Object literals only, | ||
@@ -157,13 +193,6 @@ // as it returns false for custom objects, | ||
/* | ||
Array.flatten = function(arr) { | ||
for(var i=arr.length;i--;) | ||
0 in arr[i] && A.splice.apply(arr, [i, 1].concat(Array.flatten(arr[i]))) | ||
return arr | ||
} | ||
flat([1,2,[3,4,[5,6]],7]) | ||
*/ | ||
// Non-standard | ||
// // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12" | ||
A.remove = function() { | ||
// IE<9 bug: [1,2].splice(0).join("") == "" but should be "12" | ||
A.remove = arrayRemove | ||
function arrayRemove() { | ||
var arr = this | ||
@@ -208,10 +237,2 @@ , len = arr.length | ||
function True() { | ||
return true | ||
} | ||
function False() { | ||
return false | ||
} | ||
Boolean.prototype.fn = function() { | ||
@@ -223,6 +244,6 @@ return this.valueOf() ? True : False | ||
function Fn(expr, scope) { | ||
for (var args = "_", body = expr, arr = expr.split("->"); arr.length > 1; ) { | ||
for (var args = ["_"], body = expr, arr = expr.split("->"); arr.length > 1; ) { | ||
body = arr.pop() | ||
args = arr.pop().match(/\w+/g) || "" | ||
if (arr.length) arr.push("(function("+args+"){return("+body+")})") | ||
args = arr.pop().match(/\w+/g) || [] | ||
if (arr.length) arr.push("(function(" + args + "){return(" + body + ")})") | ||
} | ||
@@ -234,3 +255,8 @@ // `replace` removes symbols that follow '.', | ||
return new Function(args, (scope && (expr = expr.replace(fnRe, "").match(/\b[a-z]\w*|\b_\w+/g)) ? | ||
"var " + expr.uniq().join("='',") + "='';with(" + scope + "||{})" : "") + "return(" + body + ")") | ||
( | ||
arrayRemove.apply(expr, args), | ||
expr[0] ? "var " + expr.uniq().join("='',") + "='';" : "" | ||
) + "with(" + scope + "||{})" : "") | ||
+ "return(" + body + ")" | ||
) | ||
} | ||
@@ -240,2 +266,10 @@ | ||
function True() { | ||
return true | ||
} | ||
function False() { | ||
return false | ||
} | ||
}(this, Object) | ||
@@ -242,0 +276,0 @@ |
{ | ||
"name": "functional-lite", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"stability": 2, | ||
@@ -5,0 +5,0 @@ "author": "Lauri Rooden <lauri@rooden.ee>", |
@@ -13,4 +13,4 @@ [GitHub repo]: https://github.com/litejs/functional-lite | ||
@version 0.3.1 | ||
@date 2015-03-23 | ||
@version 0.3.2 | ||
@date 2015-05-11 | ||
@stability 2 - Unstable | ||
@@ -17,0 +17,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12997
321