functional-lite
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -5,3 +5,3 @@ | ||
/* | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
* @author Lauri Rooden - https://github.com/litejs/fn-lite | ||
@@ -12,2 +12,6 @@ * @license MIT License - http://lauri.rooden.ee/mit-license.txt | ||
function Nop() {} | ||
function True() { return true } | ||
function False() { return false } | ||
function This() { return this } | ||
@@ -22,3 +26,2 @@ !function(root) { | ||
function Nop(){} | ||
@@ -41,12 +44,12 @@ | ||
F.partial = function() { | ||
var t = this, a = sl(arguments) | ||
return function() {return t.apply(this, A.concat.apply(a, arguments))} | ||
var self = this, a = sl(arguments) | ||
return function() {return self.apply(this, A.concat.apply(a, arguments))} | ||
} | ||
F.byWords = function(i) { | ||
var t = this | ||
var self = this | ||
i |= 0 | ||
return function() { | ||
var s = this, r = s, a = arguments | ||
;(a[i]||"").replace(/[-\w]+/g, function(w){a[i]=w;r=t.apply(s, a)}) | ||
;(a[i]||"").replace(/[-\w]+/g, function(w){a[i]=w;r=self.apply(s, a)}) | ||
return r | ||
@@ -57,3 +60,3 @@ } | ||
F.byKeyVal = function() { | ||
var t = this | ||
var self = this | ||
return function(o) { | ||
@@ -64,4 +67,4 @@ var r, s = this, a = sl(arguments) | ||
a[1] = o[r] | ||
r = t.apply(s, a) | ||
} else r = t.apply(s, a) | ||
r = self.apply(s, a) | ||
} else r = self.apply(s, a) | ||
return r | ||
@@ -73,15 +76,15 @@ } | ||
F.cache = function(instance, keyFn, cache) { | ||
var t = this, c = cache || {}, f = function() { | ||
var self = this, c = cache || {}, f = function() { | ||
var a = arguments | ||
, i = !!instance || this instanceof f | ||
, k = keyFn ? keyFn(a, t) : i + ":" + a.length + ":" + A.join.call(a) | ||
, k = keyFn ? keyFn(a, self) : i + ":" + a.length + ":" + A.join.call(a) | ||
return k in c ? c[k] : (c[k] = i ? t.construct(a) : t.apply(this, a)) | ||
return k in c ? c[k] : (c[k] = i ? self.construct(a) : self.apply(this, a)) | ||
} | ||
f.origin = t | ||
f.origin = self | ||
f.cached = c | ||
f.extend = function() { | ||
return t.extend.apply(t, arguments).cache(instance, keyFn, c) | ||
return self.extend.apply(self, arguments).cache(instance, keyFn, c) | ||
} | ||
f[P] = t[P] // prototype for better access on extending | ||
f[P] = self[P] // prototype for better access on extending | ||
return f | ||
@@ -91,6 +94,6 @@ } | ||
F.extend = function() { | ||
var a, t = this, i = 0, f = function() { | ||
return t.apply(this, arguments) | ||
var a, self = this, i = 0, f = function() { | ||
return self.apply(this, arguments) | ||
} | ||
f[P] = Object.create(t[P]) | ||
f[P] = Object.create(self[P]) | ||
f[P].constructor = f | ||
@@ -113,3 +116,3 @@ while (a = arguments[i++]) Object.merge(f[P], a) | ||
F.guard = function(test, or) { | ||
var t = this | ||
var self = this | ||
, f = test.fn() | ||
@@ -119,3 +122,3 @@ , o = (or||Nop).fn() | ||
return function() { | ||
return (f.apply(this, arguments) ? t : o).apply(this, arguments) | ||
return (f.apply(this, arguments) ? self : o).apply(this, arguments) | ||
} | ||
@@ -127,6 +130,6 @@ } | ||
F.ttl = function(ms, fun) { | ||
var t = this, s = setTimeout(function(){ms=0;fun&&fun()}, ms) | ||
var self = this, tick = setTimeout(function(){ms=0;fun&&fun()}, ms) | ||
return function() { | ||
clearTimeout(s) | ||
ms && t.apply(null, arguments) | ||
clearTimeout(tick) | ||
ms && self.apply(null, arguments) | ||
} | ||
@@ -137,7 +140,7 @@ } | ||
F.once = function(ms) { | ||
var s, args, t = this | ||
var tick, args, self = this | ||
return function() { | ||
clearTimeout(s) | ||
clearTimeout(tick) | ||
args = arguments | ||
s = setTimeout(function(){t.apply(null, args)}, ms) | ||
tick = setTimeout(function(){self.apply(null, args)}, ms) | ||
} | ||
@@ -148,3 +151,3 @@ } | ||
F.rate = function(ms, last_call) { | ||
var tick, args, t = this, next = 0 | ||
var tick, args, self = this, next = 0 | ||
return function() { | ||
@@ -155,6 +158,6 @@ var now = +new Date() | ||
next = now + ms | ||
t.apply(null, arguments) | ||
self.apply(null, arguments) | ||
} else if (last_call) { | ||
args = arguments | ||
tick = setTimeout(function(){t.apply(null, args)}, next-now) | ||
tick = setTimeout(function(){self.apply(null, args)}, next-now) | ||
} | ||
@@ -173,12 +176,12 @@ } | ||
F.trace = function(n) { | ||
var t = this | ||
n = n || t | ||
var self = this | ||
n = n || self | ||
return "console" in w ? | ||
function() { | ||
console.info('[', n, 'apply(', this!=w && this, ',', arguments, ')') | ||
var result = t.apply(this, arguments) | ||
var result = self.apply(this, arguments) | ||
console.info(']', n, ' -> ', result) | ||
return result | ||
} : | ||
t | ||
self | ||
} | ||
@@ -220,8 +223,8 @@ //*/ | ||
A.remove = function() { | ||
var t = this | ||
, l = t.length | ||
var self = this | ||
, l = self.length | ||
, o = sl(arguments) | ||
while (l--) if (~o.indexOf(t[l])) t.splice(l, 1) | ||
return t | ||
while (l--) if (~o.indexOf(self[l])) self.splice(l, 1) | ||
return self | ||
} | ||
@@ -266,10 +269,7 @@ | ||
Fn.Nop = Nop | ||
Fn.This = F.fn = function() {return this} | ||
Fn.True = function() {return true} | ||
Fn.False = function() {return false} | ||
Fn.Init = function() { | ||
var t = this | ||
return t.init && t.init.apply(t, arguments) || t | ||
var self = this | ||
return self.init && self.init.apply(self, arguments) || self | ||
} | ||
F.fn = This | ||
@@ -276,0 +276,0 @@ |
11
min.js
@@ -1,6 +0,7 @@ | ||
!function(p){function g(a){if(k[a])return k[a];for(var b="_",d=a,c=a.split("->");1<c.length;)d=c.pop(),b=c.pop().match(/\w+/g)||"",c.length&&c.push("(function("+b+"){return("+d+")})");return k[a]=new Function(b,"return("+d+")")}var k={},f=Array.prototype,e=Function.prototype,m=String.prototype,l=Object,j=e.call.bind(f.slice),n=[];e.construct=function(a){var b=a.length;return b?(n[b]||(n[b]=g("t a->new t(a["+Object.keys(j(a)).join("],a[")+"])")))(this,a):new this};e.partial=function(){var a=this,b= | ||
j(arguments);return function(){return a.apply(this,f.concat.apply(b,arguments))}};e.byWords=function(a){var b=this;a|=0;return function(){var d=this,c=d,h=arguments;(h[a]||"").replace(/[-\w]+/g,function(f){h[a]=f;c=b.apply(d,h)});return c}};e.byKeyVal=function(){var a=this;return function(b){var d,c=j(arguments);if("object"==typeof b)for(d in b)c[0]=d,c[1]=b[d],d=a.apply(this,c);else d=a.apply(this,c);return d}};e.cache=function(a,b,d){var c=this,h=d||{},e=function(){var d=arguments,g=!!a||this instanceof | ||
e,j=b?b(d,c):g+":"+d.length+":"+f.join.call(d);return j in h?h[j]:h[j]=g?c.construct(d):c.apply(this,d)};e.origin=c;e.cached=h;e.extend=function(){return c.extend.apply(c,arguments).cache(a,b,h)};e.prototype=c.prototype;return e};e.extend=function(){var a,b=this,d=0,c=function(){return b.apply(this,arguments)};c.prototype=Object.create(b.prototype);for(c.prototype.constructor=c;a=arguments[d++];)Object.merge(c.prototype,a);return c};e.ttl=function(a,b){var d=this,c=setTimeout(function(){a=0;b&&b()}, | ||
function Nop(){}function True(){return!0}function False(){return!1}function This(){return this} | ||
!function(p){function j(a){if(k[a])return k[a];for(var b="_",d=a,c=a.split("->");1<c.length;)d=c.pop(),b=c.pop().match(/\w+/g)||"",c.length&&c.push("(function("+b+"){return("+d+")})");return k[a]=new Function(b,"return("+d+")")}var k={},f=Array.prototype,e=Function.prototype,m=String.prototype,l=Object,g=e.call.bind(f.slice),n=[];e.construct=function(a){var b=a.length;return b?(n[b]||(n[b]=j("t a->new t(a["+Object.keys(g(a)).join("],a[")+"])")))(this,a):new this};e.partial=function(){var a=this,b= | ||
g(arguments);return function(){return a.apply(this,f.concat.apply(b,arguments))}};e.byWords=function(a){var b=this;a|=0;return function(){var d=this,c=d,h=arguments;(h[a]||"").replace(/[-\w]+/g,function(f){h[a]=f;c=b.apply(d,h)});return c}};e.byKeyVal=function(){var a=this;return function(b){var d,c=g(arguments);if("object"==typeof b)for(d in b)c[0]=d,c[1]=b[d],d=a.apply(this,c);else d=a.apply(this,c);return d}};e.cache=function(a,b,d){var c=this,h=d||{},e=function(){var d=arguments,j=!!a||this instanceof | ||
e,g=b?b(d,c):j+":"+d.length+":"+f.join.call(d);return g in h?h[g]:h[g]=j?c.construct(d):c.apply(this,d)};e.origin=c;e.cached=h;e.extend=function(){return c.extend.apply(c,arguments).cache(a,b,h)};e.prototype=c.prototype;return e};e.extend=function(){var a,b=this,d=0,c=function(){return b.apply(this,arguments)};c.prototype=Object.create(b.prototype);for(c.prototype.constructor=c;a=arguments[d++];)Object.merge(c.prototype,a);return c};e.ttl=function(a,b){var d=this,c=setTimeout(function(){a=0;b&&b()}, | ||
a);return function(){clearTimeout(c);a&&d.apply(null,arguments)}};e.once=function(a){var b,d,c=this;return function(){clearTimeout(b);d=arguments;b=setTimeout(function(){c.apply(null,d)},a)}};e.rate=function(a,b){var d,c,e=this,f=0;return function(){var g=+new Date;clearTimeout(d);g>f?(f=g+a,e.apply(null,arguments)):b&&(c=arguments,d=setTimeout(function(){e.apply(null,c)},f-g))}};l.each=function(a,b,d,c){if(a)for(c in a)a.hasOwnProperty(c)&&b.call(d,a[c],c,a)};l.merge=function(a){for(var b,d,c=1;d= | ||
arguments[c++];)for(b in d)d.hasOwnProperty(b)&&(a[b]=d[b]);return a};l.zip=function(a,b){return a.fold(function(a,c,e){a[c]=b[e];return a},{})};f.remove=function(){for(var a=this.length,b=j(arguments);a--;)~b.indexOf(this[a])&&this.splice(a,1);return this};f.each=f.forEach;f.fold=f.reduce;f.foldr=f.reduceRight;f.unique=f.filter.partial(function(a,b,d){return b==d.lastIndexOf(a)});!function(a){e[a]=m[a]=function(){var b=arguments,d=b[0];b[0]=this.fn();return f[a].apply(d,b)}}.byWords()("every filter each map fold foldr some"); | ||
p.Fn=g;g.Nop=function(){};g.This=e.fn=function(){return this};g.True=function(){return!0};g.False=function(){return!1};g.Init=function(){return this.init&&this.init.apply(this,arguments)||this};m.fn=function(){return g(this)}}(this); | ||
arguments[c++];)for(b in d)d.hasOwnProperty(b)&&(a[b]=d[b]);return a};l.zip=function(a,b){return a.fold(function(a,c,e){a[c]=b[e];return a},{})};f.remove=function(){for(var a=this.length,b=g(arguments);a--;)~b.indexOf(this[a])&&this.splice(a,1);return this};f.each=f.forEach;f.fold=f.reduce;f.foldr=f.reduceRight;f.unique=f.filter.partial(function(a,b,d){return b==d.lastIndexOf(a)});!function(a){e[a]=m[a]=function(){var b=arguments,d=b[0];b[0]=this.fn();return f[a].apply(d,b)}}.byWords()("every filter each map fold foldr some"); | ||
p.Fn=j;j.Init=function(){return this.init&&this.init.apply(this,arguments)||this};e.fn=This;m.fn=function(){return j(this)}}(this); |
{ | ||
"name": "functional-lite", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"license": "MIT", | ||
@@ -18,6 +18,3 @@ "description": "Functional Javascript", | ||
], | ||
"directories": { | ||
"util": "util" | ||
}, | ||
"readmeFilename": "README.md" | ||
} |
@@ -11,6 +11,7 @@ | ||
Download [compressed][1] | ||
(2790 bytes, 1194 bytes gzipped) | ||
(2784 bytes, 1199 bytes gzipped) | ||
or [uncompressed][2] source. | ||
[![Build Status](https://travis-ci.org/litejs/functional-lite.png?branch=master)](https://travis-ci.org/litejs/functional-lite) | ||
@@ -17,0 +18,0 @@ ### Licence |
Sorry, the diff of this file is not supported yet
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
15
571
23
20004