Comparing version 0.2.1 to 0.3.0
207
benchmark.js
@@ -1,11 +0,19 @@ | ||
const R = require("./rambda") | ||
const R = require("./") | ||
const Ramda = require("ramda") | ||
const Benchmark = require('benchmark') | ||
const benchmarks = require('beautify-benchmark') | ||
const _ = require("lodash") | ||
const Benchmark = require("benchmark") | ||
const benchmarks = require("beautify-benchmark") | ||
const add = new Benchmark.Suite | ||
const adjust = new Benchmark.Suite | ||
const any = new Benchmark.Suite | ||
const flatten = new Benchmark.Suite | ||
const filter = new Benchmark.Suite | ||
const compose = new Benchmark.Suite | ||
const contains = new Benchmark.Suite | ||
const equals = new Benchmark.Suite | ||
const find = new Benchmark.Suite | ||
const type = new Benchmark.Suite | ||
const update = new Benchmark.Suite | ||
const firstExample = new Benchmark.Suite | ||
@@ -17,20 +25,28 @@ const secondExample = new Benchmark.Suite | ||
adjust: true, | ||
any: true, | ||
compose: true, | ||
equals: true, | ||
filter: true, | ||
find: true, | ||
first: false, | ||
flatten: true, | ||
second: false, | ||
type: true, | ||
update: true, | ||
first: true, | ||
second: true | ||
} | ||
if(options.add){ | ||
add.add('Rambda#add', ()=>{ | ||
R.add(1)(1) | ||
if (options.add) { | ||
add.add("Rambda#add", () => { | ||
R.add(1, 1) | ||
}) | ||
.add('Ramda', () => { | ||
Ramda.add(1)(1) | ||
.add("Ramda", () => { | ||
Ramda.add(1, 1) | ||
}) | ||
.on('cycle', event => { | ||
.add("Lodash", () => { | ||
_.add(1, 1) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on('complete', ()=>{ | ||
.on("complete", () => { | ||
benchmarks.log() | ||
@@ -41,13 +57,13 @@ }) | ||
if(options.adjust){ | ||
adjust.add('Rambda#adjust', ()=>{ | ||
R.adjust(val=>val+1, 0) | ||
if (options.adjust) { | ||
adjust.add("Rambda#adjust", () => { | ||
R.adjust(val => val + 1, 0) | ||
}) | ||
.add('Ramda', () => { | ||
Ramda.adjust(val=>val+1, 0) | ||
.add("Ramda", () => { | ||
Ramda.adjust(val => val + 1, 0) | ||
}) | ||
.on('cycle', event => { | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on('complete', ()=>{ | ||
.on("complete", () => { | ||
benchmarks.log() | ||
@@ -58,14 +74,35 @@ }) | ||
if(options.equals){ | ||
if (options.any) { | ||
any.add("Rambda#any", () => { | ||
R.any(val => val > 2, [ 1, 2, 3, 4 ]) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.any(val => val > 2, [ 1, 2, 3, 4 ]) | ||
}) | ||
.add("Lodash.some", () => { | ||
_.some([ 1, 2, 3, 4 ], val => val > 2) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
equals.add('Rambda#equals', ()=>{ | ||
if (options.equals) { | ||
equals.add("Rambda#equals", () => { | ||
R.equals({ a:{ b:{ c:1 } } }, { a:{ b:{ c:1 } } }) | ||
}) | ||
.add('Ramda', () => { | ||
.add("Ramda", () => { | ||
Ramda.equals({ a:{ b:{ c:1 } } }, { a:{ b:{ c:1 } } }) | ||
}) | ||
.on('cycle', event => { | ||
.add("Lodash.isEqual", () => { | ||
_.isEqual({ a:{ b:{ c:1 } } }, { a:{ b:{ c:1 } } }) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on('complete', ()=>{ | ||
.on("complete", () => { | ||
benchmarks.log() | ||
@@ -76,14 +113,35 @@ }) | ||
if(options.update){ | ||
if (options.filter) { | ||
filter.add("Rambda#filter", () => { | ||
R.filter(val => val > 2, [ 1, 2, 3, 4 ]) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.filter(val => val > 2, [ 1, 2, 3, 4 ]) | ||
}) | ||
.add("Lodash", () => { | ||
_.filter([ 1, 2, 3, 4 ], val => val > 2) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
update.add('Rambda#update', ()=>{ | ||
R.update(3,1,[1,2,3]) | ||
if (options.find) { | ||
find.add("Rambda#find", () => { | ||
R.find(val => val > 2, [ 1, 2, 3, 4 ]) | ||
}) | ||
.add('Ramda', () => { | ||
Ramda.update(3,1,[1,2,3]) | ||
.add("Ramda", () => { | ||
Ramda.find(val => val > 2, [ 1, 2, 3, 4 ]) | ||
}) | ||
.on('cycle', event => { | ||
.add("Lodash", () => { | ||
_.find([ 1, 2, 3, 4 ], val => val > 2) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on('complete', ()=>{ | ||
.on("complete", () => { | ||
benchmarks.log() | ||
@@ -94,14 +152,35 @@ }) | ||
if(options.type){ | ||
if (options.flatten) { | ||
flatten.add("Rambda#flatten", () => { | ||
R.flatten([ 1, [ 2, [ 3, 4, 6 ] ] ]) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.flatten([ 1, [ 2, [ 3, 4, 6 ] ] ]) | ||
}) | ||
.add("Lodash", () => { | ||
_.flatten([ 1, [ 2, [ 3, 4, 6 ] ] ]) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
type.add('Rambda#type', ()=>{ | ||
R.type([1,2,3]) | ||
if (options.compose) { | ||
compose.add("Rambda#compose", () => { | ||
R.compose(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
}) | ||
.add('Ramda', () => { | ||
Ramda.type([1,2,3]) | ||
.add("Ramda", () => { | ||
Ramda.compose(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
}) | ||
.on('cycle', event => { | ||
.add("Lodash.flowRight", () => { | ||
_.flowRight(val => val + 1, val => val.length)([ 1, 2, 3, 4 ]) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on('complete', ()=>{ | ||
.on("complete", () => { | ||
benchmarks.log() | ||
@@ -112,4 +191,36 @@ }) | ||
if(options.first){ | ||
firstExample.add('Rambda#firstExample', ()=>{ | ||
if (options.update) { | ||
update.add("Rambda#update", () => { | ||
R.update(3, 1, [ 1, 2, 3 ]) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.update(3, 1, [ 1, 2, 3 ]) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
if (options.type) { | ||
type.add("Rambda#type", () => { | ||
R.type([ 1, 2, 3 ]) | ||
}) | ||
.add("Ramda", () => { | ||
Ramda.type([ 1, 2, 3 ]) | ||
}) | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on("complete", () => { | ||
benchmarks.log() | ||
}) | ||
.run() | ||
} | ||
if (options.first) { | ||
firstExample.add("Rambda#firstExample", () => { | ||
R.compose( | ||
@@ -123,3 +234,3 @@ R.join("|"), | ||
}) | ||
.add('Ramda#firstExample', () => { | ||
.add("Ramda#firstExample", () => { | ||
Ramda.compose( | ||
@@ -133,6 +244,6 @@ Ramda.join("|"), | ||
}) | ||
.on('cycle', event => { | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on('complete', ()=>{ | ||
.on("complete", () => { | ||
benchmarks.log() | ||
@@ -143,4 +254,4 @@ }) | ||
if(options.second){ | ||
secondExample.add('Rambda#secondExample', ()=>{ | ||
if (options.second) { | ||
secondExample.add("Rambda#secondExample", () => { | ||
R.compose( | ||
@@ -152,3 +263,3 @@ R.last, | ||
}) | ||
.add('Ramda#secondExample', () => { | ||
.add("Ramda#secondExample", () => { | ||
Ramda.compose( | ||
@@ -160,6 +271,6 @@ Ramda.last, | ||
}) | ||
.on('cycle', event => { | ||
.on("cycle", event => { | ||
benchmarks.add(event.target) | ||
}) | ||
.on('complete', ()=>{ | ||
.on("complete", () => { | ||
benchmarks.log() | ||
@@ -166,0 +277,0 @@ }) |
@@ -1,1 +0,1 @@ | ||
const R=require("./_inc/compose"),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=!1;n.map(q=>{if(m(q)===!0){p=!0;}});return p;},append=(r,s)=>{if(s===void 0){return t=>append(r,t);}const u=s;u.unshift(r);return u;},contains=(v,w)=>{if(w===void 0){return x=>contains(v,x);}return any(y=>v===y,w);},filter=(z,A)=>{if(A===void 0){return B=>filter(z,B);}return A.filter(z);},find=(C,D)=>{if(D===void 0){return E=>find(C,E);}return D.find(C);},findIndex=(F,G)=>{if(G===void 0){return H=>findIndex(F,H);}return G.findIndex(F);},flatten=I=>{let J=[];for(let i=0;i<I.length;i++){if(Array.isArray(I[i])){J=J.concat(flatten(I[i]));}else{J.push(I[i]);}}return J;},drop=(K,L)=>{if(L===void 0){return M=>drop(K,M);}const N=L;return N.slice(K);},dropLast=(O,P)=>{if(P===void 0){return Q=>dropLast(O,Q);}const S=P;return S.slice(0,-O);},equals=(a,b)=>{if(b===void 0){return T=>equals(a,T);}else if(a===b){return a!==0||1/a===1/b;}const U=type(a);if(U!==type(b)){return!1;}if(U==="Array"){const V=a,W=b;return V.sort().toString()===W.sort().toString();}if(U==="Object"){const X=Object.keys(a);if(X.length===Object.keys(b).length){if(X.length===0){return!0;}let Y=!0;X.map(Z=>{if(Y){const a1=type(a[Z]),b1=type(b[Z]);if(a1===b1){if(a1==="Object"){if(Object.keys(a[Z]).length===Object.keys(b[Z]).length){if(Object.keys(a[Z]).length!==0){if(!equals(a[Z],b[Z])){Y=!1;}}}else{Y=!1;}}else if(!equals(a[Z],b[Z])){Y=!1;}}else{Y=!1;}}});return Y;}}return!1;},head=c1=>dropLast(c1.length-1,c1),indexOf=(d1,e1)=>{if(e1===void 0){return f1=>indexOf(d1,f1);}return e1.indexOf(d1);},init=g1=>dropLast(1,g1),join=(h1,i1)=>{if(i1===void 0){return j1=>join(h1,j1);}return i1.join(h1);},map=(fn,l1)=>{if(l1===void 0){return m1=>map(fn,m1);}return l1.map(fn);},last=n1=>n1[n1.length-1],length=o1=>o1.length,match=(p1,q1)=>{if(q1===void 0){return r1=>match(p1,r1);}const s1=q1.match(p1);return s1===null?[]:s1;},merge=(t1,u1)=>{if(u1===void 0){return v1=>merge(t1,v1);}return Object.assign({},t1,u1);},omit=(w1,x1)=>{if(x1===void 0){return y1=>omit(w1,y1);}const z1={};for(key in x1){if(!w1.includes(key)){z1[key]=x1[key];}}return z1;},path=(A1,B1)=>{if(B1===void 0){return C1=>path(A1,C1);}let D1=B1,E1=0;while(E1<A1.length){if(D1===null){return void 0;}D1=D1[A1[E1]];E1++;}return D1;},prepend=(F1,G1)=>{if(G1===void 0){return H1=>prepend(F1,H1);}const I1=G1;I1.push(F1);return I1;},pick=(J1,K1)=>{if(K1===void 0){return L1=>pick(J1,L1);}const M1={};for(key in K1){if(J1.includes(key)){M1[key]=K1[key];}}return M1;},prop=(N1,O1)=>{if(O1===void 0){return P1=>prop(N1,P1);}return O1[N1];},propEq=(Q1,R1,S1)=>{if(R1===void 0){return(T1,U1)=>propEq(Q1,T1,U1);}else if(S1===void 0){return V1=>propEq(Q1,R1,V1);}return S1[Q1]===R1;},range=(W1,X1)=>{const Y1=[];for(let i=W1;i<X1;i++){Y1.push(i);}return Y1;},repeat=(a,Z1)=>{if(Z1===void 0){return a2=>repeat(a,a2);}const b2=range(0,Z1);return b2.fill(a);},replace=(c2,d2,e2)=>{if(d2===void 0){return(f2,g2)=>replace(c2,f2,g2);}else if(e2===void 0){return h2=>replace(c2,d2,h2);}return e2.replace(c2,d2);},subtract=(a,b)=>{if(b===void 0){return c=>subtract(a,c);}return a-b;},sort=(fn,j2)=>{if(j2===void 0){return k2=>sort(fn,k2);}const l2=j2;return l2.sort(fn);},sortBy=(fn,n2)=>{if(n2===void 0){return o2=>sortBy(fn,o2);}const p2=n2;return p2.sort((a,b)=>{const q2=fn(a),r2=fn(b);return q2<r2?-1:q2>r2?1:0;});},split=(s2,t2)=>{if(t2===void 0){return u2=>split(s2,u2);}return t2.split(s2);},splitEvery=(v2,a)=>{if(a===void 0){return w2=>splitEvery(v2,w2);}v2=v2>1?v2:1;const x2=[];let y2=0;while(y2<a.length){x2.push(a.slice(y2,y2+=v2));}return x2;},tail=z2=>drop(1,z2),take=(A2,B2)=>{if(B2===void 0){return C2=>take(A2,C2);}const D2=B2;return D2.slice(0,A2);},takeLast=(E2,F2)=>{if(F2===void 0){return G2=>dropLast(E2,G2);}const H2=F2;E2=E2>H2.length?H2.length:E2;return H2.slice(H2.length-E2);},toLower=a=>a.toLowerCase(),toUpper=a=>a.toUpperCase(),test=(I2,J2)=>{if(J2===void 0){return K2=>test(I2,K2);}return J2.search(I2)===-1?!1:!0;},trim=L2=>L2.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=M2=>{const N2=[];for(key in M2){N2.push(M2[key]);}return N2;},uniq=O2=>{const P2=[];return O2.filter(Q2=>{if(P2.includes(Q2)){return!1;}P2.push(Q2);return!0;});},update=(R2,S2,T2)=>{if(S2===void 0){return(U2,V2)=>update(R2,U2,V2);}else if(T2===void 0){return W2=>update(R2,S2,W2);}return T2.fill(R2,S2,S2+1);};module.exports.add=add;module.exports.adjust=adjust;module.exports.any=any;module.exports.append=append;module.exports.compose=R.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);}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; |
{ | ||
"name": "rambda", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Lightweight alternative to Ramda", | ||
@@ -30,5 +30,6 @@ "main": "index.js", | ||
"benchmark": "^2.1.3", | ||
"ramda": "*", | ||
"jest": "^18.1.0" | ||
"jest": "^18.1.0", | ||
"lodash": "^4.17.4", | ||
"ramda": "*" | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
const R = require("./_inc/compose") | ||
const add = (a, b) => { | ||
@@ -32,10 +30,11 @@ if (b === undefined) { | ||
let flag = false | ||
arr.map(val => { | ||
if (fn(val) === true) { | ||
flag = true | ||
let counter = 0 | ||
while (counter < arr.length) { | ||
if (fn(arr[ counter ])) { | ||
return true | ||
} | ||
}) | ||
counter++ | ||
} | ||
return flag | ||
return false | ||
} | ||
@@ -53,2 +52,26 @@ | ||
const isFunction = value => typeof value === "function" | ||
function compose () { | ||
const funcs = arguments | ||
let length = funcs.length | ||
while (length--) { | ||
if (!isFunction(funcs[ length ])) { | ||
throw new TypeError | ||
} | ||
} | ||
return function () { | ||
let args = arguments | ||
let len = funcs.length | ||
while (len--) { | ||
args = [ funcs[ len ].apply(this, args) ] | ||
} | ||
return args[ 0 ] | ||
} | ||
} | ||
const contains = (val, arr) => { | ||
@@ -67,3 +90,18 @@ if (arr === undefined) { | ||
return arr.filter(fn) | ||
let index = -1 | ||
let resIndex = 0 | ||
const length = arr === null ? | ||
0 : | ||
arr.length | ||
const willReturn = [] | ||
while (++index < length) { | ||
const value = arr[ index ] | ||
if (fn(value)) { | ||
willReturn[ resIndex++ ] = value | ||
} | ||
} | ||
return willReturn | ||
} | ||
@@ -87,13 +125,15 @@ | ||
const flatten = arr => { | ||
let willReturn = [] | ||
for (let i = 0; i < arr.length; i++) { | ||
if (Array.isArray(arr[ i ])) { | ||
willReturn = willReturn.concat(flatten(arr[ i ])) | ||
const flatten = (ary, ret) => { | ||
ret = ret === undefined ? | ||
[] : | ||
ret | ||
for (let i = 0; i < ary.length; i++) { | ||
if (Array.isArray(ary[ i ])) { | ||
flatten(ary[ i ], ret) | ||
} else { | ||
willReturn.push(arr[ i ]) | ||
ret.push(ary[ i ]) | ||
} | ||
} | ||
return willReturn | ||
return ret | ||
} | ||
@@ -483,3 +523,3 @@ | ||
module.exports.append = append | ||
module.exports.compose = R.compose | ||
module.exports.compose = compose | ||
module.exports.contains = contains | ||
@@ -486,0 +526,0 @@ module.exports.drop = drop |
530
README.md
@@ -6,10 +6,12 @@ [![Build Status](https://travis-ci.org/selfrefactor/ils.svg?branch=master)](https://travis-ci.org/selfrefactor/rambda) | ||
Partial copy of *Ramda* using *Ramda.compose* and plain Javascript functions. | ||
Faster alternative to **Ramda** in just 6kB | ||
## Argumentation | ||
I admire *Ramda* but most of the time I use only small part of what it offers. | ||
I admire ***Ramda*** as it is great library in what it does, but I used only small part of what it offers. | ||
But even when I create custom **Ramda** build, I still am not completely happy with its size. | ||
I wanted to optimize the size of my bundle, but already developed Ramda habits. | ||
This lead me to the idea to recreate the funtionality of some Ramda methods and export that as library. | ||
## Example use | ||
@@ -37,10 +39,8 @@ ``` | ||
Performance was not the main reason for this library, it is side effect. | ||
![Screen](/screen.png) | ||
The benchmark coverage is small. | ||
## Disclaimer | ||
Its current status: | ||
- Documentation of the methods below is scraped from Ramda's website and could be removed in the future, if requested from Ramda's side. | ||
![Screen](/_inc/screen.png) | ||
## API | ||
@@ -50,160 +50,578 @@ | ||
[link to Ramda's docs for add method](http://ramdajs.com/docs/#add) | ||
- Adds two values. | ||
```javascript | ||
R.add(2, 3); //=> 5 | ||
R.add(7)(10); //=> 17 | ||
``` | ||
#### adjust | ||
[link to Ramda's docs for adjust method](http://ramdajs.com/docs/#adjust) | ||
- Applies a function to the value at the given index of an array, returning a | ||
new copy of the array with the element at the given index replaced with the | ||
result of the function application. | ||
```javascript | ||
R.adjust(R.add(10), 1, [0, 1, 2]); //=> [0, 11, 2] | ||
R.adjust(R.add(10))(1)([0, 1, 2]); //=> [0, 11, 2] | ||
``` | ||
#### any | ||
[link to Ramda's docs for any method](http://ramdajs.com/docs/#any) | ||
- Returns true if at least one of elements of the list match the predicate, | ||
false otherwise. | ||
Dispatches to the any method of the second argument, if present. | ||
Acts as a transducer if a transformer is given in list position. | ||
```javascript | ||
var lessThan0 = R.flip(R.lt)(0); | ||
var lessThan2 = R.flip(R.lt)(2); | ||
R.any(lessThan0)([1, 2]); //=> false | ||
R.any(lessThan2)([1, 2]); //=> true | ||
``` | ||
#### append | ||
[link to Ramda's docs for append method](http://ramdajs.com/docs/#append) | ||
- Returns a new list containing the contents of the given list, followed by | ||
the given element. | ||
#### compose | ||
```javascript | ||
R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests'] | ||
R.append('tests', []); //=> ['tests'] | ||
R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']] | ||
``` | ||
Just passing the original compose method of Ramda | ||
#### contains | ||
[link to Ramda's docs for compose method](http://ramdajs.com/docs/#compose) | ||
- Returns true if the specified value is equal, in R.equals terms, to at | ||
least one element of the given list; false otherwise. | ||
#### contains | ||
```javascript | ||
R.contains(3, [1, 2, 3]); //=> true | ||
R.contains(4, [1, 2, 3]); //=> false | ||
R.contains([42], [[42]]); //=> true | ||
``` | ||
[link to Ramda's docs for contains method](http://ramdajs.com/docs/#contains) | ||
#### drop | ||
[link to Ramda's docs for drop method](http://ramdajs.com/docs/#drop) | ||
- Returns all but the first n elements of the given list, string, or | ||
transducer/transformer (or object with a drop method). | ||
Dispatches to the drop method of the second argument, if present. | ||
```javascript | ||
R.drop(1, ['foo', 'bar', 'baz']); //=> ['bar', 'baz'] | ||
R.drop(2, ['foo', 'bar', 'baz']); //=> ['baz'] | ||
R.drop(3, ['foo', 'bar', 'baz']); //=> [] | ||
R.drop(4, ['foo', 'bar', 'baz']); //=> [] | ||
R.drop(3, 'ramda'); //=> 'da' | ||
``` | ||
#### dropLast | ||
[link to Ramda's docs for dropLast method](http://ramdajs.com/docs/#dropLast) | ||
- Returns a list containing all but the last n elements of the given list. | ||
```javascript | ||
R.dropLast(1, ['foo', 'bar', 'baz']); //=> ['foo', 'bar'] | ||
R.dropLast(2, ['foo', 'bar', 'baz']); //=> ['foo'] | ||
R.dropLast(3, ['foo', 'bar', 'baz']); //=> [] | ||
R.dropLast(4, ['foo', 'bar', 'baz']); //=> [] | ||
R.dropLast(3, 'ramda'); //=> 'ra' | ||
``` | ||
#### equals | ||
- Returns true if its arguments are equivalent, false otherwise. Handles | ||
cyclical data structures. | ||
Dispatches symmetrically to the equals methods of both arguments, if | ||
present. | ||
```javascript | ||
R.equals(1, 1); //=> true | ||
R.equals(1, '1'); //=> false | ||
R.equals([1, 2, 3], [1, 2, 3]); //=> true | ||
var a = {}; a.v = a; | ||
var b = {}; b.v = b; | ||
R.equals(a, b); //=> true | ||
``` | ||
#### filter | ||
[link to Ramda's docs for filter method](http://ramdajs.com/docs/#filter) | ||
- Takes a predicate and a "filterable", and returns a new filterable of the | ||
same type containing the members of the given filterable which satisfy the | ||
given predicate. | ||
Dispatches to the filter method of the second argument, if present. | ||
Acts as a transducer if a transformer is given in list position. | ||
```javascript | ||
var isEven = n => n % 2 === 0; | ||
R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4] | ||
R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4} | ||
``` | ||
#### find | ||
- Returns the first element of the list which matches the predicate, or | ||
undefined if no element matches. | ||
Dispatches to the find method of the second argument, if present. | ||
Acts as a transducer if a transformer is given in list position. | ||
```javascript | ||
var xs = [{a: 1}, {a: 2}, {a: 3}]; | ||
R.find(R.propEq('a', 2))(xs); //=> {a: 2} | ||
R.find(R.propEq('a', 4))(xs); //=> undefined | ||
``` | ||
#### findIndex | ||
- Returns the index of the first element of the list which matches the | ||
predicate, or -1 if no element matches. | ||
Dispatches to the findIndex method of the second argument, if present. | ||
Acts as a transducer if a transformer is given in list position. | ||
```javascript | ||
var xs = [{a: 1}, {a: 2}, {a: 3}]; | ||
R.findIndex(R.propEq('a', 2))(xs); //=> 1 | ||
R.findIndex(R.propEq('a', 4))(xs); //=> -1 | ||
``` | ||
#### flatten | ||
[link to Ramda's docs for flatten method](http://ramdajs.com/docs/#flatten) | ||
- Returns a new list by pulling every item out of it (and all its sub-arrays) | ||
and putting them in a new array, depth-first. | ||
```javascript | ||
R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]); | ||
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | ||
``` | ||
#### head | ||
[link to Ramda's docs for head method](http://ramdajs.com/docs/#head) | ||
- Returns the first element of the given list or string. In some libraries | ||
this function is named first. | ||
```javascript | ||
R.head(['fi', 'fo', 'fum']); //=> 'fi' | ||
R.head([]); //=> undefined | ||
R.head('abc'); //=> 'a' | ||
R.head(''); //=> '' | ||
``` | ||
#### indexOf | ||
- Returns the position of the first occurrence of an item in an array, or -1 | ||
if the item is not included in the array. R.equals is used to determine | ||
equality. | ||
```javascript | ||
R.indexOf(3, [1,2,3,4]); //=> 2 | ||
R.indexOf(10, [1,2,3,4]); //=> -1 | ||
``` | ||
#### init | ||
[link to Ramda's docs for init method](http://ramdajs.com/docs/#init) | ||
- Returns all but the last element of the given list or string. | ||
```javascript | ||
R.init([1, 2, 3]); //=> [1, 2] | ||
R.init([1, 2]); //=> [1] | ||
R.init([1]); //=> [] | ||
R.init([]); //=> [] | ||
R.init('abc'); //=> 'ab' | ||
R.init('ab'); //=> 'a' | ||
R.init('a'); //=> '' | ||
R.init(''); //=> '' | ||
``` | ||
#### join | ||
[link to Ramda's docs for join method](http://ramdajs.com/docs/#join) | ||
- Returns a string made by inserting the separator between each element and | ||
concatenating all the elements into a single string. | ||
```javascript | ||
var spacer = R.join(' '); | ||
spacer(['a', 2, 3.4]); //=> 'a 2 3.4' | ||
R.join('|', [1, 2, 3]); //=> '1|2|3' | ||
``` | ||
#### last | ||
[link to Ramda's docs for last method](http://ramdajs.com/docs/#last) | ||
- Returns the last element of the given list or string. | ||
```javascript | ||
R.last(['fi', 'fo', 'fum']); //=> 'fum' | ||
R.last([]); //=> undefined | ||
R.last('abc'); //=> 'c' | ||
R.last(''); //=> '' | ||
``` | ||
#### length | ||
[link to Ramda's docs for length method](http://ramdajs.com/docs/#length) | ||
- Returns the number of elements in the array by returning list.length. | ||
```javascript | ||
R.length([]); //=> 0 | ||
R.length([1, 2, 3]); //=> 3 | ||
``` | ||
#### map | ||
[link to Ramda's docs for map method](http://ramdajs.com/docs/#map) | ||
- Takes a function and | ||
a functor, | ||
applies the function to each of the functor's values, and returns | ||
a functor of the same shape. | ||
Ramda provides suitable map implementations for Array and Object, | ||
so this function may be applied to [1, 2, 3] or {x: 1, y: 2, z: 3}. | ||
Dispatches to the map method of the second argument, if present. | ||
Acts as a transducer if a transformer is given in list position. | ||
Also treats functions as functors and will compose them together. | ||
```javascript | ||
var double = x => x * 2; | ||
R.map(double, [1, 2, 3]); //=> [2, 4, 6] | ||
R.map(double, {x: 1, y: 2, z: 3}); //=> {x: 2, y: 4, z: 6} | ||
``` | ||
#### match | ||
- Tests a regular expression against a String. Note that this function will | ||
return an empty array when there are no matches. This differs from | ||
String.prototype.match | ||
which returns null when there are no matches. | ||
```javascript | ||
R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na'] | ||
R.match(/a/, 'b'); //=> [] | ||
R.match(/a/, null); //=> TypeError: null does not have a method named "match" | ||
``` | ||
#### merge | ||
- Create a new object with the own properties of the first object merged with | ||
the own properties of the second object. If a key exists in both objects, | ||
the value from the second object will be used. | ||
```javascript | ||
R.merge({ 'name': 'fred', 'age': 10 }, { 'age': 40 }); | ||
//=> { 'name': 'fred', 'age': 40 } | ||
var resetToDefault = R.merge(R.__, {x: 0}); | ||
resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2} | ||
``` | ||
#### omit | ||
[link to Ramda's docs for omit method](http://ramdajs.com/docs/#omit) | ||
- Returns a partial copy of an object omitting the keys specified. | ||
```javascript | ||
R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3} | ||
``` | ||
#### path | ||
[link to Ramda's docs for path method](http://ramdajs.com/docs/#path) | ||
- Retrieve the value at a given path. | ||
```javascript | ||
R.path(['a', 'b'], {a: {b: 2}}); //=> 2 | ||
R.path(['a', 'b'], {c: {b: 2}}); //=> undefined | ||
``` | ||
#### pick | ||
- Returns a partial copy of an object containing only the keys specified. If | ||
the key does not exist, the property is ignored. | ||
```javascript | ||
R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4} | ||
R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1} | ||
``` | ||
#### prepend | ||
[link to Ramda's docs for prepend method](http://ramdajs.com/docs/#prepend) | ||
- Returns a new list with the given element at the front, followed by the | ||
contents of the list. | ||
#### pick | ||
```javascript | ||
R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum'] | ||
``` | ||
[link to Ramda's docs for pick method](http://ramdajs.com/docs/#pick) | ||
#### prop | ||
[link to Ramda's docs for prop method](http://ramdajs.com/docs/#prop) | ||
- Returns a function that when supplied an object returns the indicated | ||
property of that object, if it exists. | ||
```javascript | ||
R.prop('x', {x: 100}); //=> 100 | ||
R.prop('x', {}); //=> undefined | ||
``` | ||
#### propEq | ||
[link to Ramda's docs for propEq method](http://ramdajs.com/docs/#propEq) | ||
- Returns true if the specified object property is equal, in R.equals | ||
terms, to the given value; false otherwise. | ||
```javascript | ||
var abby = {name: 'Abby', age: 7, hair: 'blond'}; | ||
var fred = {name: 'Fred', age: 12, hair: 'brown'}; | ||
var rusty = {name: 'Rusty', age: 10, hair: 'brown'}; | ||
var alois = {name: 'Alois', age: 15, disposition: 'surly'}; | ||
var kids = [abby, fred, rusty, alois]; | ||
var hasBrownHair = R.propEq('hair', 'brown'); | ||
R.filter(hasBrownHair, kids); //=> [fred, rusty] | ||
``` | ||
#### range | ||
[link to Ramda's docs for range method](http://ramdajs.com/docs/#range) | ||
- Returns a list of numbers from from (inclusive) to to (exclusive). | ||
```javascript | ||
R.range(1, 5); //=> [1, 2, 3, 4] | ||
R.range(50, 53); //=> [50, 51, 52] | ||
``` | ||
#### repeat | ||
[link to Ramda's docs for repeat method](http://ramdajs.com/docs/#repeat) | ||
- Returns a fixed list of size n containing a specified identical value. | ||
```javascript | ||
R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi'] | ||
var obj = {}; | ||
var repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}] | ||
repeatedObjs[0] === repeatedObjs[1]; //=> true | ||
``` | ||
#### replace | ||
[link to Ramda's docs for replace method](http://ramdajs.com/docs/#replace) | ||
- Replace a substring or regex match in a string with a replacement. | ||
```javascript | ||
R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo' | ||
R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo' | ||
// Use the "g" (global) flag to replace all occurrences: | ||
R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar' | ||
``` | ||
#### sort | ||
[link to Ramda's docs for sort method](http://ramdajs.com/docs/#sort) | ||
- Returns a copy of the list, sorted according to the comparator function, | ||
which should accept two values at a time and return a negative number if the | ||
first value is smaller, a positive number if it's larger, and zero if they | ||
are equal. Please note that this is a copy of the list. It does not | ||
modify the original. | ||
```javascript | ||
var diff = function(a, b) { return a - b; }; | ||
R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7] | ||
``` | ||
#### sortBy | ||
[link to Ramda's docs for sortBy method](http://ramdajs.com/docs/#sortBy) | ||
- Sorts the list according to the supplied function. | ||
```javascript | ||
var sortByFirstItem = R.sortBy(R.prop(0)); | ||
var sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop('name'))); | ||
var pairs = [[-1, 1], [-2, 2], [-3, 3]]; | ||
sortByFirstItem(pairs); //=> [[-3, 3], [-2, 2], [-1, 1]] | ||
var alice = { | ||
name: 'ALICE', | ||
age: 101 | ||
}; | ||
var bob = { | ||
name: 'Bob', | ||
age: -10 | ||
}; | ||
var clara = { | ||
name: 'clara', | ||
age: 314.159 | ||
}; | ||
var people = [clara, bob, alice]; | ||
sortByNameCaseInsensitive(people); //=> [alice, bob, clara] | ||
``` | ||
#### split | ||
[link to Ramda's docs for split method](http://ramdajs.com/docs/#split) | ||
- Splits a string into an array of strings based on the given | ||
separator. | ||
```javascript | ||
var pathComponents = R.split('/'); | ||
R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node'] | ||
R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd'] | ||
``` | ||
#### splitEvery | ||
[link to Ramda's docs for splitEvery method](http://ramdajs.com/docs/#splitEvery) | ||
- Splits a collection into slices of the specified length. | ||
```javascript | ||
R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]] | ||
R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz'] | ||
``` | ||
#### subtract | ||
[link to Ramda's docs for subtract method](http://ramdajs.com/docs/#subtract) | ||
- Subtracts its second argument from its first argument. | ||
```javascript | ||
R.subtract(10, 8); //=> 2 | ||
var minus5 = R.subtract(R.__, 5); | ||
minus5(17); //=> 12 | ||
var complementaryAngle = R.subtract(90); | ||
complementaryAngle(30); //=> 60 | ||
complementaryAngle(72); //=> 18 | ||
``` | ||
#### tail | ||
[link to Ramda's docs for tail method](http://ramdajs.com/docs/#tail) | ||
- Returns all but the first element of the given list or string (or object | ||
with a tail method). | ||
Dispatches to the slice method of the first argument, if present. | ||
```javascript | ||
R.tail([1, 2, 3]); //=> [2, 3] | ||
R.tail([1, 2]); //=> [2] | ||
R.tail([1]); //=> [] | ||
R.tail([]); //=> [] | ||
R.tail('abc'); //=> 'bc' | ||
R.tail('ab'); //=> 'b' | ||
R.tail('a'); //=> '' | ||
R.tail(''); //=> '' | ||
``` | ||
#### take | ||
[link to Ramda's docs for take method](http://ramdajs.com/docs/#take) | ||
- Returns the first n elements of the given list, string, or | ||
transducer/transformer (or object with a take method). | ||
Dispatches to the take method of the second argument, if present. | ||
```javascript | ||
R.take(1, ['foo', 'bar', 'baz']); //=> ['foo'] | ||
R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar'] | ||
R.take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] | ||
R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] | ||
R.take(3, 'ramda'); //=> 'ram' | ||
var personnel = [ | ||
'Dave Brubeck', | ||
'Paul Desmond', | ||
'Eugene Wright', | ||
'Joe Morello', | ||
'Gerry Mulligan', | ||
'Bob Bates', | ||
'Joe Dodge', | ||
'Ron Crotty' | ||
]; | ||
var takeFive = R.take(5); | ||
takeFive(personnel); | ||
//=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan'] | ||
``` | ||
#### takeLast | ||
[link to Ramda's docs for takeLast method](http://ramdajs.com/docs/#takeLast) | ||
- Returns a new list containing the last n elements of the given list. | ||
If n > list.length, returns a list of list.length elements. | ||
```javascript | ||
R.takeLast(1, ['foo', 'bar', 'baz']); //=> ['baz'] | ||
R.takeLast(2, ['foo', 'bar', 'baz']); //=> ['bar', 'baz'] | ||
R.takeLast(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] | ||
R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] | ||
R.takeLast(3, 'ramda'); //=> 'mda' | ||
``` | ||
#### test | ||
[link to Ramda's docs for test method](http://ramdajs.com/docs/#test) | ||
- Determines whether a given string matches a given regular expression. | ||
```javascript | ||
R.test(/^x/, 'xyz'); //=> true | ||
R.test(/^y/, 'xyz'); //=> false | ||
``` | ||
#### toLower | ||
[link to Ramda's docs for toLower method](http://ramdajs.com/docs/#toLower) | ||
- The lower case version of a string. | ||
```javascript | ||
R.toLower('XYZ'); //=> 'xyz' | ||
``` | ||
#### toUpper | ||
[link to Ramda's docs for toUpper method](http://ramdajs.com/docs/#toUpper) | ||
- The upper case version of a string. | ||
```javascript | ||
R.toUpper('abc'); //=> 'ABC' | ||
``` | ||
#### trim | ||
- Removes (strips) whitespace from both ends of the string. | ||
```javascript | ||
R.trim(' xyz '); //=> 'xyz' | ||
R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z'] | ||
``` | ||
#### type | ||
[link to Ramda's docs for type method](http://ramdajs.com/docs/#type) | ||
- Gives a single-word string description of the (native) type of a value, | ||
returning such answers as 'Object', 'Number', 'Array', or 'Null'. Does not | ||
attempt to distinguish user Object types any further, reporting them all as | ||
'Object'. | ||
#### values | ||
```javascript | ||
R.type({}); //=> "Object" | ||
R.type(1); //=> "Number" | ||
R.type(false); //=> "Boolean" | ||
R.type('s'); //=> "String" | ||
R.type(null); //=> "Null" | ||
R.type([]); //=> "Array" | ||
R.type(/[A-z]/); //=> "RegExp" | ||
``` | ||
[link to Ramda's docs for values method](http://ramdajs.com/docs/#values) | ||
#### uniq | ||
[link to Ramda's docs for uniq method](http://ramdajs.com/docs/#uniq) | ||
- Returns a new list containing only one copy of each element in the original | ||
list. R.equals is used to determine equality. | ||
```javascript | ||
R.uniq([1, 1, 2, 1]); //=> [1, 2] | ||
R.uniq([1, '1']); //=> [1, '1'] | ||
R.uniq([[42], [42]]); //=> [[42]] | ||
``` | ||
#### update | ||
[link to Ramda's docs for update method](http://ramdajs.com/docs/#update) | ||
- Returns a new copy of the array with the element at the provided index | ||
replaced with the given value. | ||
```javascript | ||
R.update(1, 11, [0, 1, 2]); //=> [0, 11, 2] | ||
R.update(1)(11)([0, 1, 2]); //=> [0, 11, 2] | ||
``` | ||
#### values | ||
- Returns a list of all the enumerable own properties of the supplied object. | ||
Note that the order of the output array is not guaranteed across different | ||
JS platforms. | ||
```javascript | ||
R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3] | ||
``` |
@@ -177,3 +177,3 @@ const Ramda = require("ramda") | ||
expect( | ||
R.flatten([ 1, 2, 3, [ 4 ] ]) | ||
R.flatten([ 1, 2, 3, [ [ [ [ [ 4 ] ] ] ] ] ]) | ||
).toEqual([ 1, 2, 3, 4 ]) | ||
@@ -180,0 +180,0 @@ expect( |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
264051
1171
1
625
0
5
10