Comparing version 0.3.1 to 0.3.2
271
benchmark.js
@@ -1,2 +0,2 @@ | ||
const R = require("./") | ||
const R = require("./rambda") | ||
const Ramda = require("ramda") | ||
@@ -9,2 +9,3 @@ const _ = require("lodash") | ||
const adjust = new Benchmark.Suite | ||
const append = new Benchmark.Suite | ||
const any = new Benchmark.Suite | ||
@@ -14,3 +15,2 @@ const flatten = new Benchmark.Suite | ||
const compose = new Benchmark.Suite | ||
const contains = new Benchmark.Suite | ||
const equals = new Benchmark.Suite | ||
@@ -25,16 +25,35 @@ const find = new Benchmark.Suite | ||
const options = { | ||
add: true, | ||
adjust: true, | ||
any: true, | ||
compose: true, | ||
equals: true, | ||
filter: true, | ||
find: true, | ||
add: false, | ||
adjust: false, | ||
append: false, | ||
any: false, | ||
compose: false, | ||
equals: false, | ||
filter: false, | ||
find: false, | ||
first: false, | ||
flatten: true, | ||
flatten: false, | ||
second: false, | ||
type: true, | ||
update: true, | ||
type: false, | ||
update: false, | ||
} | ||
if(0){ | ||
firstExample.add("1", () => { | ||
const a = "" | ||
const b = typeof a === "string" | ||
}) | ||
.add("2", () => { | ||
const a = "" | ||
const b = a.bold !== undefined | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
if (options.add) { | ||
@@ -94,2 +113,100 @@ add.add("Rambda#add", () => { | ||
if (options.append) { | ||
append.add("Rambda#append", () => { | ||
R.append(0)([ 1, 2, 3, 4 ]) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.append(0)([ 1, 2, 3, 4 ]) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
if (options.compose) { | ||
compose.add("Rambda#compose", () => { | ||
R.compose(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.compose(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
}) | ||
.add("Lodash.flowRight", () => { | ||
_.flowRight(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
const contains = new Benchmark.Suite | ||
options.contains = false | ||
if (options.contains) { | ||
const holder = [1,2,3,4] | ||
const a = 2 | ||
contains.add("Rambda#contains", () => { | ||
R.contains(a)(holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.contains(a)(holder) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
const drop = new Benchmark.Suite | ||
options.drop = false | ||
if (options.drop) { | ||
const holder = [1,2,3,4] | ||
const a = 3 | ||
drop.add("Rambda#drop", () => { | ||
R.drop(a)(holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.drop(a)(holder) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
const dropLast = new Benchmark.Suite | ||
options.dropLast = false | ||
if (options.dropLast) { | ||
const holder = [1,2,3,4] | ||
const a = 3 | ||
dropLast.add("Rambda#dropLast", () => { | ||
R.dropLast(a)(holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.dropLast(a)(holder) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
if (options.equals) { | ||
@@ -152,2 +269,26 @@ equals.add("Rambda#equals", () => { | ||
const findIndex = new Benchmark.Suite | ||
options.findIndex = false | ||
if (options.findIndex) { | ||
const holder = [1,2,3,4] | ||
const a = val => val === 3 | ||
append.add("Rambda#findIndex", () => { | ||
R.findIndex(a,holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.findIndex(a,holder) | ||
}) | ||
.add("Lodash", () => { | ||
_.findIndex(holder, a) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
if (options.flatten) { | ||
@@ -172,11 +313,15 @@ flatten.add("Rambda#flatten", () => { | ||
if (options.compose) { | ||
compose.add("Rambda#compose", () => { | ||
R.compose(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
const head = new Benchmark.Suite | ||
options.head = false | ||
if (options.head) { | ||
const holder = [1,2,3,4] | ||
head.add("Rambda#head", () => { | ||
R.head(holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.compose(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
Ramda.head(holder) | ||
}) | ||
.add("Lodash.flowRight", () => { | ||
_.flowRight(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
.add("Lodash", () => { | ||
_.head(holder) | ||
}) | ||
@@ -192,2 +337,92 @@ .on("cycle", event => { | ||
const headString = new Benchmark.Suite | ||
options.headString = false | ||
if (options.headString) { | ||
const holder = "" | ||
headString.add("Rambda#head when string", () => { | ||
R.head(holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.head(holder) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
const indexOf = new Benchmark.Suite | ||
options.indexOf = false | ||
if (options.indexOf) { | ||
const holder = [1,2,3,4] | ||
const a = 4 | ||
indexOf.add("Rambda#indexOf", () => { | ||
R.indexOf(a,holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.indexOf(a,holder) | ||
}) | ||
.add("Lodash", () => { | ||
_.indexOf(holder, a) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
const init = new Benchmark.Suite | ||
options.init = false | ||
if (options.init) { | ||
const holder = [1,2,3,4] | ||
init.add("Rambda#init", () => { | ||
R.init(holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.init(holder) | ||
}) | ||
.add("Lodash", () => { | ||
_.initial(holder) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
const initString = new Benchmark.Suite | ||
options.initString = true | ||
if (options.initString) { | ||
const holder = "foo" | ||
initString.add("Rambda#init when string", () => { | ||
R.init(holder) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.init(holder) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
if (options.update) { | ||
@@ -194,0 +429,0 @@ update.add("Rambda#update", () => { |
@@ -1,1 +0,1 @@ | ||
const add=(a,b)=>{if(b===void 0){return c=>add(a,c);}return a+b;},adjust=(d,e,f)=>{if(e===void 0){return(g,h)=>adjust(d,g,h);}else if(f===void 0){return j=>adjust(d,e,j);}return f.map((k,l)=>{if(l===e){return d(f[e]);}return k;});},any=(m,n)=>{if(n===void 0){return o=>any(m,o);}let p=0;while(p<n.length){if(m(n[p])){return!0;}p++;}return!1;},append=(q,r)=>{if(r===void 0){return s=>append(q,s);}const t=r;t.unshift(q);return t;},isFunction=u=>typeof u==="function";function compose(){const v=arguments;let w=v.length;while(w--){if(!isFunction(v[w])){throw new TypeError();}}return function(){let x=arguments,y=v.length;while(y--){x=[v[y].apply(this,x)];}return x[0];};}const contains=(z,A)=>{if(A===void 0){return B=>contains(z,B);}return any(C=>z===C,A);},filter=(D,E)=>{if(E===void 0){return F=>filter(D,F);}let G=-1,H=0;const I=E===null?0:E.length,J=[];while(++G<I){const K=E[G];if(D(K)){J[H++]=K;}}return J;},find=(L,M)=>{if(M===void 0){return N=>find(L,N);}return M.find(L);},findIndex=(O,P)=>{if(P===void 0){return Q=>findIndex(O,Q);}return P.findIndex(O);},flatten=(R,S)=>{S=S===void 0?[]:S;for(let i=0;i<R.length;i++){if(Array.isArray(R[i])){flatten(R[i],S);}else{S.push(R[i]);}}return S;},drop=(T,U)=>{if(U===void 0){return V=>drop(T,V);}const W=U;return W.slice(T);},dropLast=(X,Y)=>{if(Y===void 0){return Z=>dropLast(X,Z);}const a1=Y;return a1.slice(0,-X);},equals=(a,b)=>{if(b===void 0){return b1=>equals(a,b1);}else if(a===b){return a!==0||1/a===1/b;}const c1=type(a);if(c1!==type(b)){return!1;}if(c1==="Array"){const d1=a,e1=b;return d1.sort().toString()===e1.sort().toString();}if(c1==="Object"){const f1=Object.keys(a);if(f1.length===Object.keys(b).length){if(f1.length===0){return!0;}let g1=!0;f1.map(h1=>{if(g1){const i1=type(a[h1]),j1=type(b[h1]);if(i1===j1){if(i1==="Object"){if(Object.keys(a[h1]).length===Object.keys(b[h1]).length){if(Object.keys(a[h1]).length!==0){if(!equals(a[h1],b[h1])){g1=!1;}}}else{g1=!1;}}else if(!equals(a[h1],b[h1])){g1=!1;}}else{g1=!1;}}});return g1;}}return!1;},head=k1=>dropLast(k1.length-1,k1),indexOf=(l1,m1)=>{if(m1===void 0){return n1=>indexOf(l1,n1);}return m1.indexOf(l1);},init=o1=>dropLast(1,o1),join=(p1,q1)=>{if(q1===void 0){return r1=>join(p1,r1);}return q1.join(p1);},map=(fn,t1)=>{if(t1===void 0){return u1=>map(fn,u1);}return t1.map(fn);},last=v1=>v1[v1.length-1],length=w1=>w1.length,match=(x1,y1)=>{if(y1===void 0){return z1=>match(x1,z1);}const A1=y1.match(x1);return A1===null?[]:A1;},merge=(B1,C1)=>{if(C1===void 0){return D1=>merge(B1,D1);}return Object.assign({},B1,C1);},omit=(E1,F1)=>{if(F1===void 0){return G1=>omit(E1,G1);}const H1={};for(key in F1){if(!E1.includes(key)){H1[key]=F1[key];}}return H1;},path=(I1,J1)=>{if(J1===void 0){return K1=>path(I1,K1);}let L1=J1,M1=0;while(M1<I1.length){if(L1===null){return void 0;}L1=L1[I1[M1]];M1++;}return L1;},prepend=(N1,O1)=>{if(O1===void 0){return P1=>prepend(N1,P1);}const Q1=O1;Q1.push(N1);return Q1;},pick=(R1,S1)=>{if(S1===void 0){return T1=>pick(R1,T1);}const U1={};for(key in S1){if(R1.includes(key)){U1[key]=S1[key];}}return U1;},prop=(V1,W1)=>{if(W1===void 0){return X1=>prop(V1,X1);}return W1[V1];},propEq=(Y1,Z1,a2)=>{if(Z1===void 0){return(b2,c2)=>propEq(Y1,b2,c2);}else if(a2===void 0){return d2=>propEq(Y1,Z1,d2);}return a2[Y1]===Z1;},range=(e2,f2)=>{const g2=[];for(let i=e2;i<f2;i++){g2.push(i);}return g2;},repeat=(a,h2)=>{if(h2===void 0){return i2=>repeat(a,i2);}const j2=range(0,h2);return j2.fill(a);},replace=(k2,l2,m2)=>{if(l2===void 0){return(n2,o2)=>replace(k2,n2,o2);}else if(m2===void 0){return p2=>replace(k2,l2,p2);}return m2.replace(k2,l2);},subtract=(a,b)=>{if(b===void 0){return c=>subtract(a,c);}return a-b;},sort=(fn,r2)=>{if(r2===void 0){return s2=>sort(fn,s2);}const t2=r2;return t2.sort(fn);},sortBy=(fn,v2)=>{if(v2===void 0){return w2=>sortBy(fn,w2);}const x2=v2;return x2.sort((a,b)=>{const y2=fn(a),z2=fn(b);return y2<z2?-1:y2>z2?1:0;});},split=(A2,B2)=>{if(B2===void 0){return C2=>split(A2,C2);}return B2.split(A2);},splitEvery=(D2,a)=>{if(a===void 0){return E2=>splitEvery(D2,E2);}D2=D2>1?D2:1;const F2=[];let G2=0;while(G2<a.length){F2.push(a.slice(G2,G2+=D2));}return F2;},tail=H2=>drop(1,H2),take=(I2,J2)=>{if(J2===void 0){return K2=>take(I2,K2);}const L2=J2;return L2.slice(0,I2);},takeLast=(M2,N2)=>{if(N2===void 0){return O2=>dropLast(M2,O2);}const P2=N2;M2=M2>P2.length?P2.length:M2;return P2.slice(P2.length-M2);},toLower=a=>a.toLowerCase(),toUpper=a=>a.toUpperCase(),test=(Q2,R2)=>{if(R2===void 0){return S2=>test(Q2,S2);}return R2.search(Q2)===-1?!1:!0;},trim=T2=>T2.trim(),type=a=>{if(a===null){return"Null";}else if(Array.isArray(a)){return"Array";}else if(typeof a==="boolean"){return"Boolean";}else if(typeof a==="number"){return"Number";}else if(typeof a==="string"){return"String";}else if(a===void 0){return"Undefined";}else if(a instanceof RegExp){return"RegExp";}return"Object";},values=U2=>{const V2=[];for(key in U2){V2.push(U2[key]);}return V2;},uniq=W2=>{const X2=[];return W2.filter(Y2=>{if(X2.includes(Y2)){return!1;}X2.push(Y2);return!0;});},update=(Z2,a3,b3)=>{if(a3===void 0){return(c3,d3)=>update(Z2,c3,d3);}else if(b3===void 0){return e3=>update(Z2,a3,e3);}return b3.fill(Z2,a3,a3+1);};module.exports.add=add;module.exports.adjust=adjust;module.exports.any=any;module.exports.append=append;module.exports.compose=compose;module.exports.contains=contains;module.exports.drop=drop;module.exports.dropLast=dropLast;module.exports.equals=equals;module.exports.filter=filter;module.exports.find=find;module.exports.findIndex=findIndex;module.exports.flatten=flatten;module.exports.head=head;module.exports.indexOf=indexOf;module.exports.init=init;module.exports.join=join;module.exports.last=last;module.exports.length=length;module.exports.map=map;module.exports.match=match;module.exports.merge=merge;module.exports.omit=omit;module.exports.path=path;module.exports.pick=pick;module.exports.prepend=prepend;module.exports.prop=prop;module.exports.propEq=propEq;module.exports.range=range;module.exports.repeat=repeat;module.exports.replace=replace;module.exports.sort=sort;module.exports.sortBy=sortBy;module.exports.split=split;module.exports.splitEvery=splitEvery;module.exports.subtract=subtract;module.exports.tail=tail;module.exports.take=take;module.exports.takeLast=takeLast;module.exports.test=test;module.exports.toLower=toLower;module.exports.toUpper=toUpper;module.exports.trim=trim;module.exports.type=type;module.exports.uniq=uniq;module.exports.update=update;module.exports.values=values; | ||
const add=(a,b)=>{if(b===void 0){return c=>add(a,c);}return a+b;},adjust=(d,e,f)=>{if(e===void 0){return(g,h)=>adjust(d,g,h);}else if(f===void 0){return j=>adjust(d,e,j);}return f.map((k,l)=>{if(l===e){return d(f[e]);}return k;});},any=(m,n)=>{if(n===void 0){return o=>any(m,o);}let p=0;while(p<n.length){if(m(n[p])){return!0;}p++;}return!1;},append=(q,r)=>{if(r===void 0){return s=>append(q,s);}const t=r;t.unshift(q);return t;},isFunction=u=>typeof u==="function";function compose(){const v=arguments;let w=v.length;while(w--){if(!isFunction(v[w])){throw new TypeError();}}return function(){let x=arguments,y=v.length;while(y--){x=[v[y].apply(this,x)];}return x[0];};}const contains=(z,A)=>{if(A===void 0){return B=>contains(z,B);}return any(C=>z===C,A);},filter=(D,E)=>{if(E===void 0){return F=>filter(D,F);}let G=-1,H=0;const I=E===null?0:E.length,J=[];while(++G<I){const K=E[G];if(D(K)){J[H++]=K;}}return J;},find=(L,M)=>{if(M===void 0){return N=>find(L,N);}return M.find(L);},findIndex=(O,P)=>{if(P===void 0){return Q=>findIndex(O,Q);}const R=P.length;let S=0;while(++S<R){if(O(P[S])){return S;}}return-1;},flatten=(T,U)=>{U=U===void 0?[]:U;for(let i=0;i<T.length;i++){if(Array.isArray(T[i])){flatten(T[i],U);}else{U.push(T[i]);}}return U;},drop=(V,W)=>{if(W===void 0){return X=>drop(V,X);}const Y=W;return Y.slice(V);},dropLast=(Z,a1)=>{if(a1===void 0){return b1=>dropLast(Z,b1);}const c1=a1;return c1.slice(0,-Z);},equals=(a,b)=>{if(b===void 0){return d1=>equals(a,d1);}else if(a===b){return a!==0||1/a===1/b;}const e1=type(a);if(e1!==type(b)){return!1;}if(e1==="Array"){const f1=a,g1=b;return f1.sort().toString()===g1.sort().toString();}if(e1==="Object"){const h1=Object.keys(a);if(h1.length===Object.keys(b).length){if(h1.length===0){return!0;}let i1=!0;h1.map(j1=>{if(i1){const k1=type(a[j1]),l1=type(b[j1]);if(k1===l1){if(k1==="Object"){if(Object.keys(a[j1]).length===Object.keys(b[j1]).length){if(Object.keys(a[j1]).length!==0){if(!equals(a[j1],b[j1])){i1=!1;}}}else{i1=!1;}}else if(!equals(a[j1],b[j1])){i1=!1;}}else{i1=!1;}}});return i1;}}return!1;},head=a=>{if(typeof a==="string"){return a[0]||"";}return a[0];},indexOf=(m1,n1)=>{if(n1===void 0){return o1=>indexOf(m1,o1);}let p1=-1;const q1=n1.length;while(++p1<q1){if(n1[p1]===m1){return p1;}}return-1;},baseSlice=(r1,s1,t1)=>{let u1=-1,v1=r1.length;if(s1<0){s1=-s1>v1?0:v1+s1;}t1=t1>v1?v1:t1;if(t1<0){t1+=v1;}v1=s1>t1?0:t1-s1>>>0;s1>>>=0;const w1=Array(v1);while(++u1<v1){w1[u1]=r1[u1+s1];}return w1;},init=a=>{if(typeof a==="string"){return a.slice(0,-1);}return a.length?baseSlice(a,0,-1):[];},join=(x1,y1)=>{if(y1===void 0){return z1=>join(x1,z1);}return y1.join(x1);},map=(fn,B1)=>{if(B1===void 0){return C1=>map(fn,C1);}return B1.map(fn);},last=D1=>D1[D1.length-1],length=E1=>E1.length,match=(F1,G1)=>{if(G1===void 0){return H1=>match(F1,H1);}const I1=G1.match(F1);return I1===null?[]:I1;},merge=(J1,K1)=>{if(K1===void 0){return L1=>merge(J1,L1);}return Object.assign({},J1,K1);},omit=(M1,N1)=>{if(N1===void 0){return O1=>omit(M1,O1);}const P1={};for(key in N1){if(!M1.includes(key)){P1[key]=N1[key];}}return P1;},path=(Q1,R1)=>{if(R1===void 0){return S1=>path(Q1,S1);}let T1=R1,U1=0;while(U1<Q1.length){if(T1===null){return void 0;}T1=T1[Q1[U1]];U1++;}return T1;},prepend=(V1,W1)=>{if(W1===void 0){return X1=>prepend(V1,X1);}const Y1=W1;Y1.push(V1);return Y1;},pick=(Z1,a2)=>{if(a2===void 0){return b2=>pick(Z1,b2);}const c2={};for(key in a2){if(Z1.includes(key)){c2[key]=a2[key];}}return c2;},prop=(d2,e2)=>{if(e2===void 0){return f2=>prop(d2,f2);}return e2[d2];},propEq=(g2,h2,i2)=>{if(h2===void 0){return(j2,k2)=>propEq(g2,j2,k2);}else if(i2===void 0){return l2=>propEq(g2,h2,l2);}return i2[g2]===h2;},range=(m2,n2)=>{const o2=[];for(let i=m2;i<n2;i++){o2.push(i);}return o2;},repeat=(a,p2)=>{if(p2===void 0){return q2=>repeat(a,q2);}const r2=range(0,p2);return r2.fill(a);},replace=(s2,t2,u2)=>{if(t2===void 0){return(v2,w2)=>replace(s2,v2,w2);}else if(u2===void 0){return x2=>replace(s2,t2,x2);}return u2.replace(s2,t2);},subtract=(a,b)=>{if(b===void 0){return c=>subtract(a,c);}return a-b;},sort=(fn,z2)=>{if(z2===void 0){return A2=>sort(fn,A2);}const B2=z2;return B2.sort(fn);},sortBy=(fn,D2)=>{if(D2===void 0){return E2=>sortBy(fn,E2);}const F2=D2;return F2.sort((a,b)=>{const G2=fn(a),H2=fn(b);return G2<H2?-1:G2>H2?1:0;});},split=(I2,J2)=>{if(J2===void 0){return K2=>split(I2,K2);}return J2.split(I2);},splitEvery=(L2,a)=>{if(a===void 0){return M2=>splitEvery(L2,M2);}L2=L2>1?L2:1;const N2=[];let O2=0;while(O2<a.length){N2.push(a.slice(O2,O2+=L2));}return N2;},tail=P2=>drop(1,P2),take=(Q2,R2)=>{if(R2===void 0){return S2=>take(Q2,S2);}const T2=R2;return T2.slice(0,Q2);},takeLast=(U2,V2)=>{if(V2===void 0){return W2=>dropLast(U2,W2);}const X2=V2;U2=U2>X2.length?X2.length:U2;return X2.slice(X2.length-U2);},toLower=a=>a.toLowerCase(),toUpper=a=>a.toUpperCase(),test=(Y2,Z2)=>{if(Z2===void 0){return a3=>test(Y2,a3);}return Z2.search(Y2)===-1?!1:!0;},trim=b3=>b3.trim(),type=a=>{if(a===null){return"Null";}else if(Array.isArray(a)){return"Array";}else if(typeof a==="boolean"){return"Boolean";}else if(typeof a==="number"){return"Number";}else if(typeof a==="string"){return"String";}else if(a===void 0){return"Undefined";}else if(a instanceof RegExp){return"RegExp";}return"Object";},values=c3=>{const d3=[];for(key in c3){d3.push(c3[key]);}return d3;},uniq=e3=>{const f3=[];return e3.filter(g3=>{if(f3.includes(g3)){return!1;}f3.push(g3);return!0;});},update=(h3,i3,j3)=>{if(i3===void 0){return(k3,l3)=>update(h3,k3,l3);}else if(j3===void 0){return m3=>update(h3,i3,m3);}return j3.fill(h3,i3,i3+1);};module.exports.add=add;module.exports.adjust=adjust;module.exports.any=any;module.exports.append=append;module.exports.compose=compose;module.exports.contains=contains;module.exports.drop=drop;module.exports.dropLast=dropLast;module.exports.equals=equals;module.exports.filter=filter;module.exports.find=find;module.exports.findIndex=findIndex;module.exports.flatten=flatten;module.exports.head=head;module.exports.indexOf=indexOf;module.exports.init=init;module.exports.join=join;module.exports.last=last;module.exports.length=length;module.exports.map=map;module.exports.match=match;module.exports.merge=merge;module.exports.omit=omit;module.exports.path=path;module.exports.pick=pick;module.exports.prepend=prepend;module.exports.prop=prop;module.exports.propEq=propEq;module.exports.range=range;module.exports.repeat=repeat;module.exports.replace=replace;module.exports.sort=sort;module.exports.sortBy=sortBy;module.exports.split=split;module.exports.splitEvery=splitEvery;module.exports.subtract=subtract;module.exports.tail=tail;module.exports.take=take;module.exports.takeLast=takeLast;module.exports.test=test;module.exports.toLower=toLower;module.exports.toUpper=toUpper;module.exports.trim=trim;module.exports.type=type;module.exports.uniq=uniq;module.exports.update=update;module.exports.values=values; |
{ | ||
"name": "rambda", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Lightweight alternative to Ramda", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -119,3 +119,12 @@ const add = (a, b) => { | ||
return arr.findIndex(fn) | ||
const length = arr.length | ||
let index = 0 | ||
while (++index < length) { | ||
if (fn(arr[ index ])) { | ||
return index | ||
} | ||
} | ||
return -1 | ||
} | ||
@@ -212,4 +221,10 @@ | ||
const head = arr => dropLast(arr.length - 1, arr) | ||
const head = a => { | ||
if (typeof a === "string") { | ||
return a[ 0 ] || "" | ||
} | ||
return a[ 0 ] | ||
} | ||
const indexOf = (question, arr) => { | ||
@@ -220,7 +235,44 @@ if (arr === undefined) { | ||
return arr.indexOf(question) | ||
let index = -1 | ||
const length = arr.length | ||
while (++index < length) { | ||
if (arr[ index ] === question) { | ||
return index | ||
} | ||
} | ||
return -1 | ||
} | ||
const init = arr => dropLast(1, arr) | ||
const baseSlice = (array, start, end) => { | ||
let index = -1, | ||
length = array.length | ||
if (start < 0) { | ||
start = -start > length ? 0 : length + start | ||
} | ||
end = end > length ? length : end | ||
if (end < 0) { | ||
end += length | ||
} | ||
length = start > end ? 0 : end - start >>> 0 | ||
start >>>= 0 | ||
const result = Array(length) | ||
while (++index < length) { | ||
result[ index ] = array[ index + start ] | ||
} | ||
return result | ||
} | ||
const init = a => { | ||
if(typeof a === "string"){ | ||
return a.slice(0, -1) | ||
} | ||
return a.length ? baseSlice(a, 0, -1) : [] | ||
} | ||
const join = (glue, arr) => { | ||
@@ -227,0 +279,0 @@ if (arr === undefined) { |
31
test.js
@@ -191,7 +191,14 @@ const Ramda = require("ramda") | ||
R.head, | ||
R.flatten, | ||
R.filter(val => val > 1), | ||
R.flatten, | ||
)([ [ 1 ], [ 2 ], [ 3 ], 4 ]) | ||
).toEqual([ 2 ]) | ||
).toEqual(2) | ||
expect( | ||
R.head([ 1 , 2 , 3 , 4 ]) | ||
).toEqual( 1 ) | ||
expect(R.head("")).toEqual("") | ||
expect(R.head("foo")).toEqual("f") | ||
}) | ||
@@ -217,2 +224,22 @@ | ||
).toEqual([ 2, 3 ]) | ||
expect( | ||
R.init([]) | ||
).toEqual([]) | ||
expect( | ||
R.init([1]) | ||
).toEqual([]) | ||
expect( | ||
R.init("foo") | ||
).toEqual("fo") | ||
expect( | ||
R.init("f") | ||
).toEqual("") | ||
expect( | ||
R.init("") | ||
).toEqual("") | ||
}) | ||
@@ -219,0 +246,0 @@ |
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
277344
11
1444