Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "rambda", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Lightweight alternative to Ramda", | ||
"main": "rambda.min.js", | ||
"main": "index.js", | ||
"scripts": { | ||
@@ -28,4 +28,7 @@ "test": "jest", | ||
"devDependencies": { | ||
"jest": "^18.1.0" | ||
"beautify-benchmark": "^0.2.4", | ||
"benchmark": "^2.1.3", | ||
"jest": "^18.1.0", | ||
"ramda": "*" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
const R = require("./ramda") | ||
const R = require("./compose") | ||
@@ -172,2 +172,56 @@ const add = (a,b)=>{ | ||
const type = a => { | ||
let b = R.compose( | ||
filter(val=>a instanceof val) | ||
)([Array, Number]) | ||
console.log(b) | ||
return "" | ||
} | ||
const values = obj => { | ||
const willReturn = [] | ||
for(key in obj){ | ||
willReturn.push(obj[key]); | ||
} | ||
return willReturn | ||
} | ||
const uniq = arr => { | ||
const holder = [] | ||
return arr.filter(val=>{ | ||
if(holder.includes(val)){ | ||
return false | ||
}else{ | ||
holder.push(val) | ||
return true | ||
} | ||
}) | ||
} | ||
const update = (newValue,index,arr)=>{ | ||
if(index === undefined){ | ||
return (indexHolder, arrHolder) => update(newValue,indexHolder, arrHolder) | ||
}else if(arr === undefined){ | ||
return holder => update(newValue,index, holder) | ||
}else{ | ||
return arr.fill(newValue,index, index+1) | ||
} | ||
} | ||
const updateB = (newValue,index,arr)=>{ | ||
if(index === undefined){ | ||
return (indexHolder, arrHolder) => update(newValue,indexHolder, arrHolder) | ||
}else if(arr === undefined){ | ||
return holder => update(newValue,index, holder) | ||
}else{ | ||
return arr.map((val,key)=>{ | ||
if(key===index){ | ||
return newValue | ||
}else{ | ||
return val | ||
} | ||
}) | ||
} | ||
} | ||
module.exports.add = add | ||
@@ -177,4 +231,4 @@ module.exports.adjust = adjust | ||
module.exports.append = append | ||
module.exports.contains = contains | ||
module.exports.compose = R.compose | ||
module.exports.contains = contains | ||
module.exports.drop = drop | ||
@@ -184,3 +238,2 @@ module.exports.dropLast = dropLast | ||
module.exports.flatten = flatten | ||
module.exports.flip = R.flip | ||
module.exports.head = head | ||
@@ -196,1 +249,5 @@ module.exports.init = init | ||
module.exports.tail = tail | ||
module.exports.type = type | ||
module.exports.values = values | ||
module.exports.uniq = uniq | ||
module.exports.update = update |
@@ -6,29 +6,71 @@ [![Build Status](https://travis-ci.org/selfrefactor/ils.svg?branch=master)](https://travis-ci.org/selfrefactor/rambda) | ||
Partial copy of *Ramda* using only *R.compose* and plain Javascript functions. | ||
Partial copy of *Ramda* using *Ramda.compose* and plain Javascript functions. | ||
## Argumentation | ||
The main issue with *Ramda* is its size. Custom build and minification solve the issue only partially. | ||
I admire *Ramda* but most of the time I use only small part of what it offers. | ||
## What is included? | ||
But even when I create custom **Ramda** build, I still am not completely happy with the size. | ||
## Example use | ||
``` | ||
const R = require("rambda") | ||
const result = R.compose( | ||
R.flatten, | ||
R.filter(val => val>2), | ||
R.flatten, | ||
)([ [1], [2], [3], 4]) | ||
console.log(result) // => [3,4] | ||
``` | ||
## Differences between Rambda and Ramda | ||
Rambda's method are not compatible with **Ramda.__**. | ||
In some cases **Ramda.__** can be replaced by **Ramda.flip**. **Rambda** is tested for compatability with **Ramda.flip**. | ||
Also Rambda's **flatten** works only for the first 3 levels of nesting. | ||
## Methods | ||
#### compose | ||
Just passing minified version of Ramda's compose method | ||
Just passing Ramda's compose method | ||
#### add | ||
#### adjust | ||
#### any | ||
#### append | ||
#### contains | ||
#### drop | ||
#### dropLast | ||
#### filter | ||
#### flatten | ||
Flattens nested arrays. Work only for the first 3 levels of nesting | ||
#### head | ||
Same implenentation as *Ramda's* ***head*** method, except it is not auto-curried. | ||
This description applies also for the following **Rambda** methods: | ||
#### init | ||
#### tail | ||
#### join | ||
#### last | ||
#### drop | ||
#### map | ||
#### dropLast | ||
#### prepend | ||
#### range | ||
#### split | ||
#### subtract | ||
#### tail | ||
#### uniq | ||
#### update |
21
test.js
@@ -63,6 +63,6 @@ const Ramda = require("ramda") | ||
it("flip",()=>{ | ||
it("works with Ramda's flip",()=>{ | ||
expect( | ||
R.compose( | ||
R.map(R.flip(R.subtract)(10)), | ||
R.map(Ramda.flip(R.subtract)(10)), | ||
R.adjust(R.add(1),0) | ||
@@ -169,3 +169,20 @@ )([0,2,3,4,5,6,7,8,9]) | ||
it("values",()=>{ | ||
expect( | ||
R.values({a:1,b:2,c:3}) | ||
).toEqual([1,2,3]) | ||
}) | ||
it("uniq",()=>{ | ||
expect( | ||
R.uniq([1,2,3,3,3,1,2,0]) | ||
).toEqual([1,2,3,0]) | ||
}) | ||
it("update",()=>{ | ||
expect( | ||
R.update(3)(1)([1,2,3]) | ||
).toEqual([1,3,3]) | ||
}) | ||
}) |
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
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
415
76
0
19626
4