functional-lite
Advanced tools
Comparing version 0.2.9 to 0.3.0
@@ -1,7 +0,8 @@ | ||
!function(r){function n(a,b){for(var c="_",d=a,e=a.split("->");1<e.length;)d=e.pop(),c=e.pop().match(/\w+/g)||"",e.length&&e.push("(function("+c+"){return("+d+")})");return new Function(c,(b&&(a=a.replace(s,"").match(/\b[a-z]\w*|\b_\w+/g))?"var "+a.uniq().join("='',")+"='';with("+b+"||{})":"")+"return("+d+")")}var h=Array.prototype,k=Function.prototype,p=String.prototype,f=Object,m=f.prototype.hasOwnProperty,l=k.call.bind(h.slice),q=[],s=/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|this|arguments|\.\w+|\w+:/g; | ||
k.construct=function(a){var b=a.length;return b?(q[b]||(q[b]=n("t a->new t(a["+f.keys(l(a)).join("],a[")+"])")))(this,a):new this};k.partial=function(){var a=this,b=l(arguments);return function(){return a.apply(this,b.concat.apply(b,arguments))}};k.byWords=function(a,b){var c=this;return function(){var d=this,e=d,g=arguments;(g[a|=0]||"").replace(b||/\S+/g,function(b){g[a]=b;e=c.apply(d,g)});return e}};k.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}};k.cache=function(a,b,c){var d=this,e=c||{},g=function(){var c=arguments,f=!!a||this instanceof g,h=b?b.apply(d,c):f+":"+c.length+":"+l(c);return h in e?e[h]:e[h]=f?d.construct(c):d.apply(this,c)};g.origin=d;g.cached=e;g.extend=function(){return d.extend.apply(d,arguments).cache(a,b,c)};g.prototype=d.prototype;return g};k.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};k.ttl=function(a,b){var c=this,d=setTimeout(function(){a=0;b&&b()},a);return function(){clearTimeout(d);a&&c.apply(null,arguments)}};k.once=function(a){var b,c,d=this;return function(){clearTimeout(b);c=arguments;b=setTimeout(function(){d.apply(null,c)},a)}};k.rate=function(a,b){var c,d,e=this,g=0;return function(){var f=+new Date;clearTimeout(c);f>g?(g=f+a,e.apply(null,arguments)):b&&(d=arguments,c=setTimeout(function(){e.apply(null, | ||
d)},g-f))}};f.each=function(a,b,c,d){if(a)for(d in a)m.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)m.call(b,c)&&(a[c]=b[c]);return a};f.clone=function(a,b,c){if(a&&a.constructor===f){b={};for(c in a)m.call(a,c)&&(b[c]=f.clone(a[c]));a=b}return a};f.deepMerge=f.deepCopy=function(a,b,c,d,e,g){c=c||"";d=d||[];for(e in b)if(m.call(b,e)&&a[e]!==b[e])if(g=b[e],d.push(c+e),null===g)delete a[e];else if(g&&g.constructor===f){var h=a[e];h&&h.constructor=== | ||
f||(a[e]={});f.deepMerge(a[e],g,c+e+".",d)}else a[e]=g;return d};f.zip=function(a,b){return a.fold(function(a,d,e){a[d]=b[e];return a},{})};h.remove=function(){for(var a=this.length,b=l(arguments),c=-1;a--;)~b.indexOf(this[a])&&this.splice(c=a,1);return c};h.each=h.forEach;h.fold=h.reduce;h.foldr=h.reduceRight;h.uniq=h.filter.partial(function(a,b,c){return b==c.lastIndexOf(a)});h.pushUniq=function(a){return-1==this.indexOf(a)?this.push(a):!1};!function(a){k[a]=p[a]=function(){var b=arguments,c=b[0]; | ||
b[0]=this.fn();return h[a].apply(c,b)}}.byWords()("every filter each map fold foldr some");k.fn=function(){return this};p.fn=function(a){return n(this,a)};r.Fn=n.cache()}(this); | ||
/* | ||
MIT License | ||
*/ | ||
!function(q){function k(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(r,"").match(/\b[a-z]\w*|\b_\w+/g))?"var "+a.uniq().join("='',")+"='';with("+b+"||{})":"")+"return("+d+")")}var e=Array.prototype,g=Function.prototype,n=String.prototype,f=Object,m=f.prototype.hasOwnProperty,l=g.call.bind(e.slice),p=[],r=/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|this|arguments|\.\w+|\w+:/g; | ||
g.construct=function(a){var b=a.length;return b?(p[b]||(p[b]=k("t a->new t(a["+f.keys(l(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)m.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)m.call(b,c)&&(a[c]=b[c]);return a};f.clone=function(a,b,c){if(a&&a.constructor===f){b={};for(c in a)m.call(a,c)&&(b[c]=f.clone(a[c]));a=b}return a};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]=n[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};n.fn=function(a){return k(this,a)};q.Fn=k.cache()}(this); |
27
index.js
@@ -5,4 +5,4 @@ | ||
/** | ||
* @version 0.2.8 | ||
* @date 2014-08-24 | ||
* @version 0.3.0 | ||
* @date 2014-12-08 | ||
* @stability 2 - Unstable | ||
@@ -148,19 +148,2 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
O.deepMerge = O.deepCopy = function(target, source, path, changed, key, val) { | ||
path = path || "" | ||
changed = changed || [] | ||
for (key in source) if (hasOwn.call(source, key) && target[key] !== source[key]) { | ||
val = source[key] | ||
changed.push(path + key) | ||
if (val === null) delete target[key] | ||
else if (isObject(val)) { | ||
if (!isObject(target[key])) target[key] = {} | ||
O.deepMerge(target[key], val, path + key + ".", changed) | ||
} | ||
else target[key] = val | ||
} | ||
return changed | ||
} | ||
O.zip = function(keys, vals) { | ||
@@ -197,4 +180,6 @@ return keys.fold(function(_, key, i) { | ||
// uniq | ||
// last item preserved | ||
A.uniq = A.filter.partial(function(s,i,a){return i == a.lastIndexOf(s)}) | ||
// first item preserved | ||
A.uniq = A.filter.partial(function(elem, i, arr) { | ||
return i == arr.indexOf(elem) | ||
}) | ||
@@ -201,0 +186,0 @@ A.pushUniq = function(item) { |
{ | ||
"name": "functional-lite", | ||
"version": "0.2.9", | ||
"version": "0.3.0", | ||
"stability": 2, | ||
@@ -29,28 +29,3 @@ "license": "MIT", | ||
"dist/index-min.js": "index.js" | ||
}, | ||
"testling": { | ||
"files": "tests/run.js", | ||
"browsers": [ | ||
"ie/6..10", | ||
"ff/3", | ||
"ff/4", | ||
"ff/5", | ||
"ff/20", | ||
"ff/25", | ||
"chrome/4", | ||
"chrome/10", | ||
"chrome/20", | ||
"chrome/30", | ||
"chrome/31", | ||
"opera/10", | ||
"opera/11", | ||
"opera/11.6", | ||
"opera/12", | ||
"opera/16", | ||
"safari/4..6", | ||
"android-browser/4.2", | ||
"iphone/6", | ||
"ipad/6" | ||
] | ||
} | ||
} |
@@ -11,9 +11,6 @@ [GitHub repo]: https://github.com/litejs/functional-lite | ||
[7]: https://ci.testling.com/litejs/functional-lite.png | ||
[8]: https://ci.testling.com/litejs/functional-lite | ||
@version 0.2.8 | ||
@date 2014-08-24 | ||
@version 0.3.0 | ||
@date 2014-12-08 | ||
@stability 2 - Unstable | ||
@@ -48,3 +45,3 @@ | ||
[![browser support][7]][8] | ||
It should work IE6 and up but automated testing is currently broken. | ||
@@ -61,5 +58,5 @@ | ||
Copyright (c) 2012 Lauri Rooden <lauri@rooden.ee> | ||
Copyright (c) 2013-2014 Lauri Rooden <lauri@rooden.ee> | ||
[The MIT License](http://lauri.rooden.ee/mit-license.txt) | ||
@@ -92,23 +92,2 @@ | ||
}). | ||
it ("should have Object.deepMerge"). | ||
run(function(){ | ||
a = { a:"A" | ||
, b:null | ||
, c:"C" | ||
, d:null | ||
, e:{ea:"EA", eb:null, ec:"EC", ed:null} | ||
, f:null | ||
, g:{ga:1} | ||
} | ||
b = { b:"B" | ||
, c:null | ||
, e: {eb:"EB", ec:null} | ||
, f: {fa:1} | ||
, g: null | ||
} | ||
c = Object.deepMerge(a, b) | ||
}). | ||
equal(JSON.stringify(a), '{"a":"A","b":"B","d":null,"e":{"ea":"EA","eb":"EB","ed":null},"f":{"fa":1}}'). | ||
equal(JSON.stringify(b), '{"b":"B","c":null,"e":{"eb":"EB","ec":null},"f":{"fa":1},"g":null}'). | ||
equal(JSON.stringify(c), '["b","c","e","e.eb","e.ec","f","f.fa","g"]'). | ||
it ("should eval stings"). | ||
@@ -297,4 +276,4 @@ equal(' -> 3'.fn()(), 3). | ||
equal(""+[1,2,3,4,5].uniq(), "1,2,3,4,5"). | ||
equal(""+[1,2,4,3,4,5].uniq(), "1,2,3,4,5"). | ||
equal(""+[1,2,4,3,4,5,4].uniq(), "1,2,3,5,4"). | ||
equal(""+[1,2,4,3,4,5].uniq(), "1,2,4,3,5"). | ||
equal(""+[1,2,4,3,4,5,4].uniq(), "1,2,4,3,5"). | ||
it ( "should have pushUniq" ). | ||
@@ -301,0 +280,0 @@ equal([1,2,3].pushUniq(1), false). |
19802
581
60