Socket
Socket
Sign inDemoInstall

rambda

Package Overview
Dependencies
Maintainers
1
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rambda - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

_inc/compose.js

186

benchmark.js

@@ -7,44 +7,152 @@ const R = require("./rambda")

const add = new Benchmark.Suite
const adjust = new Benchmark.Suite
const equals = new Benchmark.Suite
const type = new Benchmark.Suite
const update = new Benchmark.Suite
const type = new Benchmark.Suite
const firstExample = new Benchmark.Suite
const secondExample = new Benchmark.Suite
// add.add('Rambda#add', ()=>{
// R.add(1)(1)
// })
// .add('R.add', () => {
// Ramda.add(1)(1)
// })
// .on('cycle', event => {
// benchmarks.add(event.target)
// })
// .on('complete', ()=>{
// benchmarks.log()
// })
// .run()
const options = {
add: true,
adjust: true,
equals: true,
type: true,
update: true,
first: true,
second: true
}
update.add('Rambda#update', ()=>{
R.update(3,1,[1,2,3])
})
.add('R.update', () => {
Ramda.update(3,1,[1,2,3])
})
.on('cycle', event => {
benchmarks.add(event.target)
})
.on('complete', ()=>{
benchmarks.log()
})
if(options.add){
add.add('Rambda#add', ()=>{
R.add(1)(1)
})
.add('Ramda', () => {
Ramda.add(1)(1)
})
.on('cycle', event => {
benchmarks.add(event.target)
})
.on('complete', ()=>{
benchmarks.log()
})
.run()
}
type.add('Rambda#type', ()=>{
R.type([1,2,3])
})
.add('R.update', () => {
Ramda.type([1,2,3])
})
.on('cycle', event => {
benchmarks.add(event.target)
})
.on('complete', ()=>{
benchmarks.log()
})
.run()
if(options.adjust){
adjust.add('Rambda#adjust', ()=>{
R.adjust(val=>val+1, 0)
})
.add('Ramda', () => {
Ramda.adjust(val=>val+1, 0)
})
.on('cycle', event => {
benchmarks.add(event.target)
})
.on('complete', ()=>{
benchmarks.log()
})
.run()
}
if(options.equals){
equals.add('Rambda#equals', ()=>{
R.equals({ a:{ b:{ c:1 } } }, { a:{ b:{ c:1 } } })
})
.add('Ramda', () => {
Ramda.equals({ a:{ b:{ c:1 } } }, { a:{ b:{ c:1 } } })
})
.on('cycle', event => {
benchmarks.add(event.target)
})
.on('complete', ()=>{
benchmarks.log()
})
.run()
}
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(
R.join("|"),
R.dropLast(2),
R.flatten,
R.filter(val => val > 1),
R.flatten
)([ [ 1 ], [ 2 ], [ 3 ], 4 ])
})
.add('Ramda#firstExample', () => {
Ramda.compose(
Ramda.join("|"),
Ramda.dropLast(2),
Ramda.flatten,
Ramda.filter(val => val > 1),
Ramda.flatten
)([ [ 1 ], [ 2 ], [ 3 ], 4 ])
})
.on('cycle', event => {
benchmarks.add(event.target)
})
.on('complete', ()=>{
benchmarks.log()
})
.run()
}
if(options.second){
secondExample.add('Rambda#secondExample', ()=>{
R.compose(
R.last,
R.map(R.subtract(10)),
R.adjust(R.add(1), 0)
)([ 0, 2, 3, 4, 5, 6, 7, 8, 9 ])
})
.add('Ramda#secondExample', () => {
Ramda.compose(
Ramda.last,
Ramda.map(Ramda.subtract(10)),
Ramda.adjust(Ramda.add(1), 0)
)([ 0, 2, 3, 4, 5, 6, 7, 8, 9 ])
})
.on('cycle', event => {
benchmarks.add(event.target)
})
.on('complete', ()=>{
benchmarks.log()
})
.run()
}
{
"name": "rambda",
"version": "0.1.4",
"version": "0.1.5",
"description": "Lightweight alternative to Ramda",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,88 +0,93 @@

const R = require("./compose")
const R = require("./_inc/compose")
const add = (a,b)=>{
if(b === undefined){
return c => add(a,c)
}else{
return a + b
const add = (a, b) => {
if (b === undefined) {
return c => add(a, c)
}
return a + b
}
const adjust = (fn,index,arr)=>{
if(index === undefined){
return (indexHolder, arrHolder) => adjust(fn,indexHolder, arrHolder)
}else if(arr === undefined){
return holder => adjust(fn,index, holder)
}else{
return arr.map((val,key)=>{
if(key===index){
return fn(arr[index])
}else{
return val
}
})
const adjust = (fn, index, arr) => {
if (index === undefined) {
return (indexHolder, arrHolder) => adjust(fn, indexHolder, arrHolder)
} else if (arr === undefined) {
return holder => adjust(fn, index, holder)
}
return arr.map((val, key) => {
if (key === index) {
return fn(arr[ index ])
}
return val
})
}
const any = (fn,arr) =>{
if(arr===undefined){
return holder => any(fn,holder)
}else{
let flag = false
arr.map(val=>{
if(fn(val)===true){
flag = true
const any = (fn, arr) => {
if (arr === undefined) {
return holder => any(fn, holder)
}
let flag = false
arr.map(val => {
if (fn(val) === true) {
flag = true
}
})
return flag
}
const append = (val, arr) => {
if (arr === undefined) {
return holder => append(val, holder)
}
const clone = arr
clone.unshift(val)
return clone
}
const append = (val,arr)=>{
if(arr === undefined){
return holder => append(val,holder)
}else{
const clone = arr
clone.unshift(val)
return clone
const contains = (val, arr) => {
if (arr === undefined) {
return holder => contains(val, holder)
}
return any(value => val === value, arr)
}
const contains = (val,arr) =>{
if(arr===undefined){
return holder => contains(val,holder)
}else{
return any(value=>val===value,arr)
const filter = (fn, arr) => {
if (arr === undefined) {
return holder => filter(fn, holder)
}
return arr.filter(fn)
}
const filter = (fn,arr) =>{
if(arr===undefined){
return holder => filter(fn,holder)
}else{
return arr.filter(fn)
const find = (fn, arr) => {
if (arr === undefined) {
return holder => find(fn, holder)
}
return arr.find(fn)
}
const findIndex = (fn, arr) => {
if (arr === undefined) {
return holder => findIndex(fn, holder)
}
return arr.findIndex(fn)
}
const flatten = arr => {
const willReturn = []
arr.map(val => {
if (val instanceof Array) {
val.map(value => {
if (value instanceof Array) {
value.map(lastValue => {
if (lastValue instanceof Array) {
willReturn.push(...lastValue)
} else {
willReturn.push(lastValue)
}
})
} else {
willReturn.push(value)
}
})
let willReturn = []
for (let i = 0; i < arr.length; i++) {
if (Array.isArray(arr[ i ])) {
willReturn = willReturn.concat(flatten(arr[ i ]))
} else {
willReturn.push(val)
willReturn.push(arr[ i ])
}
})
}

@@ -93,20 +98,73 @@ return willReturn

const drop = (dropNumber, arr) => {
if(arr === undefined){
if (arr === undefined) {
return holder => drop(dropNumber, holder)
}else{
const arrClone = arr
}
const arrClone = arr
return arrClone.slice(dropNumber)
}
return arrClone.slice(dropNumber)
}
const dropLast = (dropNumber, arr) => {
if(arr === undefined){
if (arr === undefined) {
return holder => dropLast(dropNumber, holder)
}else{
const arrClone = arr
}
const arrClone = arr
return arrClone.slice(0, -dropNumber)
return arrClone.slice(0, -dropNumber)
}
const equals = (a, b) => {
if (b === undefined) {
return holder => equals(a, holder)
} else if (a === b) {
return a !== 0 || 1 / a === 1 / b
}
const aType = type(a)
if (aType !== type(b)) {
return false
}
if (aType === "Array") {
const aClone = a
const bClone = b
return aClone.sort().toString() === bClone.sort().toString()
}
if (aType === "Object") {
const aKeys = Object.keys(a)
if (aKeys.length === Object.keys(b).length) {
if (aKeys.length === 0) {
return true
}
let flag = true
aKeys.map(val => {
if (flag) {
const aValType = type(a[ val ])
const bValType = type(b[ val ])
if (aValType === bValType) {
if (aValType === "Object") {
if (Object.keys(a[ val ]).length === Object.keys(b[ val ]).length) {
if (Object.keys(a[ val ]).length !== 0) {
if (!equals(a[ val ], b[ val ])) {
flag = false
}
}
} else {
flag = false
}
} else if (!equals(a[ val ], b[ val ])) {
flag = false
}
} else {
flag = false
}
}
})
return flag
}
}
return false
}

@@ -116,18 +174,26 @@

const indexOf = (question, arr) => {
if (arr === undefined) {
return holder => indexOf(question, holder)
}
return arr.indexOf(question)
}
const init = arr => dropLast(1, arr)
const join = (glue,arr) =>{
if(arr===undefined){
return holder => join(glue,holder)
}else{
return arr.join(glue)
const join = (glue, arr) => {
if (arr === undefined) {
return holder => join(glue, holder)
}
return arr.join(glue)
}
const map = (fn,arr) =>{
if(arr===undefined){
return holder => map(fn,holder)
}else{
return arr.map(fn)
const map = (fn, arr) => {
if (arr === undefined) {
return holder => map(fn, holder)
}
return arr.map(fn)
}

@@ -137,26 +203,102 @@

const prepend = (val,arr)=>{
if(arr === undefined){
return holder => prepend(val,holder)
}else{
const clone = arr
clone.push(val)
return clone
const length = arr => arr.length
const match = (regex, str) => {
if (str === undefined) {
return holder => match(regex, holder)
}
const willReturn = str.match(regex)
return willReturn === null ?
[] :
willReturn
}
const propEq = (key,val, obj)=>{
if(val===undefined){
return (valHolder,objHolder)=>propEq(key, valHolder, objHolder)
}else if(obj === undefined){
return holder => propEq(key,val, holder)
}else{
return obj[key] === val
const merge = (obj, newProps) => {
if (newProps === undefined) {
return holder => merge(obj, holder)
}
return Object.assign({}, obj, newProps)
}
const omit = (keys, obj) => {
if (obj === undefined) {
return holder => omit(keys, holder)
}
const willReturn = {}
for (key in obj) {
if (!keys.includes(key)) {
willReturn[ key ] = obj[ key ]
}
}
return willReturn
}
const path = (pathArr, obj) => {
if (obj === undefined) {
return holder => path(pathArr, holder)
}
let holder = obj
let counter = 0
while (counter < pathArr.length) {
if (holder === null) {
return undefined
}
holder = holder[ pathArr[ counter ] ]
counter++
}
return holder
}
const prepend = (val, arr) => {
if (arr === undefined) {
return holder => prepend(val, holder)
}
const clone = arr
clone.push(val)
return clone
}
const pick = (keys, obj) => {
if (obj === undefined) {
return holder => pick(keys, holder)
}
const willReturn = {}
for (key in obj) {
if (keys.includes(key)) {
willReturn[ key ] = obj[ key ]
}
}
return willReturn
}
const prop = (key, obj) => {
if (obj === undefined) {
return holder => prop(key, holder)
}
return obj[ key ]
}
const propEq = (key, val, obj) => {
if (val === undefined) {
return (valHolder, objHolder) => propEq(key, valHolder, objHolder)
} else if (obj === undefined) {
return holder => propEq(key, val, holder)
}
return obj[ key ] === val
}
const range = (start, end) => {
const willReturn = []
for (let i = start; i < end; i++) {
willReturn.push(i);
willReturn.push(i)
}

@@ -167,75 +309,78 @@

const repeat = (a, num) =>{
if(num === undefined){
const repeat = (a, num) => {
if (num === undefined) {
return holder => repeat(a, holder)
}else{
const willReturn = range(0,num)
return willReturn.fill(a)
}
const willReturn = range(0, num)
return willReturn.fill(a)
}
const replace = (regex, replacer,str) => {
if(replacer === undefined){
const replace = (regex, replacer, str) => {
if (replacer === undefined) {
return (replacerHolder, strHolder) => replace(regex, replacerHolder, strHolder)
}else if(str === undefined){
} else if (str === undefined) {
return holder => replace(regex, replacer, holder)
}else{
return str.replace(regex, replacer)
}
return str.replace(regex, replacer)
}
const subtract = (a,b)=>{
if(b === undefined){
return c => subtract(a,c)
}else{
return a - b
const subtract = (a, b) => {
if (b === undefined) {
return c => subtract(a, c)
}
return a - b
}
const sort = (fn,arr) =>{
if(arr===undefined){
return holder => sort(fn,holder)
}else{
const arrClone = arr
const sort = (fn, arr) => {
if (arr === undefined) {
return holder => sort(fn, holder)
}
const arrClone = arr
return arrClone.sort(fn)
}
return arrClone.sort(fn)
}
const sortBy = (fn,arr) =>{
if(arr===undefined){
return holder => sortBy(fn,holder)
}else{
const arrClone = arr
const sortBy = (fn, arr) => {
if (arr === undefined) {
return holder => sortBy(fn, holder)
}
const arrClone = arr
return arrClone.sort((a,b)=>{
const fnA = fn(a)
const fnB = fn(b)
return fnA < fnB ? -1 : fnA > fnB ? 1 : 0
})
}
return arrClone.sort((a, b) => {
const fnA = fn(a)
const fnB = fn(b)
return fnA < fnB ?
-1 :
fnA > fnB ?
1 :
0
})
}
const split = (glue,str) =>{
if(str===undefined){
return holder => split(glue,holder)
}else{
return str.split(glue)
const split = (glue, str) => {
if (str === undefined) {
return holder => split(glue, holder)
}
return str.split(glue)
}
const splitEvery = (num,a) =>{
if(a===undefined){
return holder => splitEvery(num,holder)
}else{
num = num > 1 ?
num :
1
const willReturn = []
let counter = 0
while(counter<a.length){
willReturn.push(a.slice(counter, counter += num))
}
return willReturn
const splitEvery = (num, a) => {
if (a === undefined) {
return holder => splitEvery(num, holder)
}
num = num > 1 ?
num :
1
const willReturn = []
let counter = 0
while (counter < a.length) {
willReturn.push(a.slice(counter, counter += num))
}
return willReturn
}

@@ -246,23 +391,20 @@

const take = (takeNumber, arr) => {
if(arr === undefined){
if (arr === undefined) {
return holder => take(takeNumber, holder)
}else{
const arrClone = arr
}
const arrClone = arr
return arrClone.slice(0,takeNumber)
}
return arrClone.slice(0, takeNumber)
}
const takeLast = (takeNumber, arr) => {
if(arr === undefined){
if (arr === undefined) {
return holder => dropLast(takeNumber, holder)
}else{
const arrClone = arr
takeNumber = takeNumber > arrClone.length ?
arrClone.length :
takeNumber
}
const arrClone = arr
takeNumber = takeNumber > arrClone.length ?
arrClone.length :
takeNumber
return arrClone.slice(arrClone.length - takeNumber)
}
return arrClone.slice(arrClone.length - takeNumber)
}

@@ -274,30 +416,31 @@

const test = (regex, str) =>{
if(str === undefined){
const test = (regex, str) => {
if (str === undefined) {
return holder => test(regex, holder)
}else{
return str.search(regex) === -1 ?
false :
true
}
return str.search(regex) === -1 ?
false :
true
}
const trim = str => str.trim()
const type = a => {
if(a === null){
if (a === null) {
return "Null"
}else if(a.splice!== undefined){
} else if (Array.isArray(a)) {
return "Array"
}else if(a.freeze !== undefined){
return "Object"
}else if(typeof(a)==="boolean"){
} else if (typeof a === "boolean") {
return "Boolean"
} else if(typeof(a) === "number"){
} else if (typeof a === "number") {
return "Number"
}else if(typeof(a) === "string"){
} else if (typeof a === "string") {
return "String"
} else if(a === undefined){
} else if (a === undefined) {
return "Undefined"
}else if(a instanceof RegExp){
} else if (a instanceof RegExp) {
return "RegExp"
}
return "Object"

@@ -308,5 +451,6 @@ }

const willReturn = []
for(key in obj){
willReturn.push(obj[key]);
for (key in obj) {
willReturn.push(obj[ key ])
}
return willReturn

@@ -317,20 +461,21 @@ }

const holder = []
return arr.filter(val=>{
if(holder.includes(val)){
return arr.filter(val => {
if (holder.includes(val)) {
return false
}else{
holder.push(val)
return true
}
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 update = (newValue, index, arr) => {
if (index === undefined) {
return (indexHolder, arrHolder) => update(newValue, indexHolder, arrHolder)
} else if (arr === undefined) {
return holder => update(newValue, index, holder)
}
return arr.fill(newValue, index, index + 1)
}

@@ -342,14 +487,25 @@

module.exports.append = append
module.exports.compose = R.compose
module.exports.contains = contains
module.exports.compose = R.compose
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

@@ -370,5 +526,6 @@ module.exports.range = range

module.exports.toUpper = toUpper
module.exports.trim = trim
module.exports.type = type
module.exports.values = values
module.exports.uniq = uniq
module.exports.update = update
module.exports.values = values

@@ -9,5 +9,6 @@ [![Build Status](https://travis-ci.org/selfrefactor/ils.svg?branch=master)](https://travis-ci.org/selfrefactor/rambda)

## Argumentation
I admire *Ramda* but most of the time I use only small part of what it offers.
But even when I create custom **Ramda** build, I still am not completely happy with the size.
But even when I create custom **Ramda** build, I still am not completely happy with its size.

@@ -18,3 +19,2 @@ ## Example use

const result = R.compose(
R.flatten,
R.filter(val => val>2),

@@ -27,52 +27,182 @@ R.flatten,

## Differences between Rambda and Ramda
Rambda shadows only small part of the Ramda's API. A few things to note:
Rambda's method are not compatible with **Ramda.__**.
- Rambda's methods are not compatible with the placeholder **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.
- Rambda's **equals** doesn't protect against circular structures as **Ramda.equals** does
## Methods
## Benchmark
#### compose
Just passing Ramda's compose method
Performance was not the main reason for this library, it is side effect.
The benchmark coverage is small.
Its current status:
![Screen](/_inc/screen.png)
## API
#### add
[link to Ramda's docs for add method](http://ramdajs.com/docs/#add)
#### adjust
[link to Ramda's docs for adjust method](http://ramdajs.com/docs/#adjust)
#### any
[link to Ramda's docs for any method](http://ramdajs.com/docs/#any)
#### append
[link to Ramda's docs for append method](http://ramdajs.com/docs/#append)
#### compose
Just passing the original compose method of Ramda
[link to Ramda's docs for compose method](http://ramdajs.com/docs/#compose)
#### contains
[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)
#### dropLast
[link to Ramda's docs for dropLast method](http://ramdajs.com/docs/#dropLast)
#### filter
[link to Ramda's docs for filter method](http://ramdajs.com/docs/#filter)
#### flatten
[link to Ramda's docs for flatten method](http://ramdajs.com/docs/#flatten)
#### head
[link to Ramda's docs for head method](http://ramdajs.com/docs/#head)
#### init
[link to Ramda's docs for init method](http://ramdajs.com/docs/#init)
#### join
[link to Ramda's docs for join method](http://ramdajs.com/docs/#join)
#### last
[link to Ramda's docs for last method](http://ramdajs.com/docs/#last)
#### length
[link to Ramda's docs for length method](http://ramdajs.com/docs/#length)
#### map
[link to Ramda's docs for map method](http://ramdajs.com/docs/#map)
#### omit
[link to Ramda's docs for omit method](http://ramdajs.com/docs/#omit)
#### path
[link to Ramda's docs for path method](http://ramdajs.com/docs/#path)
#### prepend
[link to Ramda's docs for prepend method](http://ramdajs.com/docs/#prepend)
#### pick
[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)
#### propEq
[link to Ramda's docs for propEq method](http://ramdajs.com/docs/#propEq)
#### range
[link to Ramda's docs for range method](http://ramdajs.com/docs/#range)
#### repeat
[link to Ramda's docs for repeat method](http://ramdajs.com/docs/#repeat)
#### replace
[link to Ramda's docs for replace method](http://ramdajs.com/docs/#replace)
#### sort
[link to Ramda's docs for sort method](http://ramdajs.com/docs/#sort)
#### sortBy
[link to Ramda's docs for sortBy method](http://ramdajs.com/docs/#sortBy)
#### split
[link to Ramda's docs for split method](http://ramdajs.com/docs/#split)
#### splitEvery
[link to Ramda's docs for splitEvery method](http://ramdajs.com/docs/#splitEvery)
#### subtract
[link to Ramda's docs for subtract method](http://ramdajs.com/docs/#subtract)
#### tail
[link to Ramda's docs for tail method](http://ramdajs.com/docs/#tail)
#### take
[link to Ramda's docs for take method](http://ramdajs.com/docs/#take)
#### takeLast
[link to Ramda's docs for takeLast method](http://ramdajs.com/docs/#takeLast)
#### test
[link to Ramda's docs for test method](http://ramdajs.com/docs/#test)
#### toLower
[link to Ramda's docs for toLower method](http://ramdajs.com/docs/#toLower)
#### toUpper
[link to Ramda's docs for toUpper method](http://ramdajs.com/docs/#toUpper)
#### type
[link to Ramda's docs for type method](http://ramdajs.com/docs/#type)
#### values
[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)
#### update
[link to Ramda's docs for update method](http://ramdajs.com/docs/#update)

@@ -5,20 +5,28 @@ const Ramda = require("ramda")

describe("common cases", () => {
it("works with Ramda's flip", () => {
expect(
R.compose(
R.map(Ramda.flip(R.subtract)(10)),
R.adjust(R.add(1), 0)
)([ 0, 2, 3, 4, 5, 6, 7, 8, 9 ])
).toEqual([ -9, -8, -7, -6, -5, -4, -3, -2, -1 ])
})
it("add/adjust",()=>{
it("add/adjust", () => {
expect(
R.adjust(R.add(1))(1)([1,2,3])
).toEqual([1,3,3])
R.adjust(R.add(1))(1)([ 1, 2, 3 ])
).toEqual([ 1, 3, 3 ])
})
it("any/subtract",()=>{
it("any/subtract", () => {
expect(
R.compose(
R.any(val=>val<5),
R.any(val => val < 5),
R.map(R.subtract(10)),
R.adjust(R.add(1),0)
)([0,2,3,4,5,6,7,8,9])
R.adjust(R.add(1), 0)
)([ 0, 2, 3, 4, 5, 6, 7, 8, 9 ])
).toBeTruthy()
})
it("append",()=>{
it("append", () => {
expect(

@@ -28,7 +36,7 @@ R.compose(

R.map(R.append(0))
)([[1],[2],[3]])
).toEqual( [0, 1, 0, 2, 0, 3])
)([ [ 1 ], [ 2 ], [ 3 ] ])
).toEqual([ 0, 1, 0, 2, 0, 3 ])
})
it("contains",()=>{
it("contains", () => {
expect(

@@ -39,70 +47,165 @@ R.compose(

R.map(R.append(0))
)([[1],[2],[3]])
)([ [ 1 ], [ 2 ], [ 3 ] ])
).toBeTruthy()
})
it("filter",()=>{
it("drop", () => {
expect(
R.compose(
R.drop(2),
R.flatten,
R.filter(val=>val>2),
R.filter(val => val > 1),
R.flatten,
)([[1],[2],[3],4])
).toEqual([3,4])
)([ [ 1 ], [ 2 ], [ 3 ], 4 ])
).toEqual([ 4 ])
})
it("flatten", () => {
it("dropLast", () => {
expect(
R.flatten([ 1, 2, 3, [ 4 ] ])
).toEqual([ 1, 2, 3, 4 ])
R.compose(
R.dropLast(2),
R.flatten,
R.filter(val => val > 1),
R.flatten,
)([ [ 1 ], [ 2 ], [ 3 ], 4 ])
).toEqual([ 2 ])
})
it("equals", () => {
expect(
R.flatten([ 1, [ 2, [ [ 3 ] ] ], [ 4 ] ])
).toEqual([ 1, 2, 3, 4 ])
R.equals([ 1, 2, 3 ], [ 1, 2, 3 ])
).toBeTruthy()
expect(
R.flatten([ 1, [ 2, [ [ [ 3 ] ] ] ], [ 4 ] ])
).toEqual([ 1, 2, [ 3 ], 4 ])
})
R.equals([ 1, 2, 3 ], [ 1, 2 ])
).toBeFalsy()
it("works with Ramda's flip",()=>{
expect(
R.compose(
R.map(Ramda.flip(R.subtract)(10)),
R.adjust(R.add(1),0)
)([0,2,3,4,5,6,7,8,9])
).toEqual([-9, -8, -7, -6, -5, -4, -3, -2, -1])
R.equals(1, 1)
).toBeTruthy()
expect(
R.equals("1", 1)
).toBeFalsy()
expect(
R.equals({}, {})
).toBeTruthy()
expect(
R.equals({ a:1, b:2 }, { b:2, a:1 })
).toBeTruthy()
expect(
R.equals({ a:1, b:2 }, { b:2, a:1, c:3 })
).toBeFalsy()
expect(
R.equals({ x:{a:1, b:2} }, { x:{b:2, a:1, c:3} })
).toBeFalsy()
expect(
R.equals({ a:1, b:2 }, { b:3, a:1 })
).toBeFalsy()
expect(
R.equals({ a:{ b:{ c:1 } } }, { a:{ b:{ c:1 } } })
).toBeTruthy()
expect(
R.equals({ a:{} }, { a:{} })
).toBeTruthy()
expect(
R.equals("", "")
).toBeTruthy()
expect(
R.equals("foo", "foo")
).toBeTruthy()
expect(
R.equals("foo", "bar")
).toBeFalsy()
expect(
R.equals(0, false)
).toBeFalsy()
expect(
R.equals(/\s/g, null)
).toBeFalsy()
expect(
R.equals(null, null)
).toBeTruthy()
expect(
R.equals(false)(null)
).toBeFalsy()
})
it("drop",()=>{
it("filter", () => {
expect(
R.compose(
R.drop(2),
R.flatten,
R.filter(val=>val>1),
R.filter(val => val > 2),
R.flatten,
)([[1],[2],[3],4])
).toEqual([4])
)([ [ 1 ], [ 2 ], [ 3 ], 4 ])
).toEqual([ 3, 4 ])
})
it("dropLast",()=>{
it("find", () => {
expect(
R.compose(
R.dropLast(2),
R.flatten,
R.filter(val=>val>1),
R.flatten,
)([[1],[2],[3],4])
).toEqual([2])
R.find(R.propEq("a", 2))([ { a: 1 }, { a: 2 }, { a: 3 } ])
).toEqual({ a: 2 })
expect(
R.find(R.propEq("a", 4))([ { a: 1 }, { a: 2 }, { a: 3 } ])
).toEqual(undefined)
})
it("head",()=>{
it("findIndex", () => {
expect(
R.findIndex(R.propEq("a", 2))([ { a: 1 }, { a: 2 }, { a: 3 } ])
).toEqual(1)
expect(
R.findIndex(R.propEq("a", 4))([ { a: 1 }, { a: 2 }, { a: 3 } ])
).toEqual(-1)
})
it("flatten", () => {
expect(
R.flatten([ 1, 2, 3, [ 4 ] ])
).toEqual([ 1, 2, 3, 4 ])
expect(
R.flatten([ 1, [ 2, [ [ 3 ] ] ], [ 4 ] ])
).toEqual([ 1, 2, 3, 4 ])
expect(
R.flatten([ 1, [ 2, [ [ [ 3 ] ] ] ], [ 4 ] ])
).toEqual([ 1, 2, 3 , 4 ])
})
it("head", () => {
expect(
R.compose(
R.head,
R.flatten,
R.filter(val=>val>1),
R.filter(val => val > 1),
R.flatten,
)([[1],[2],[3],4])
).toEqual([2])
)([ [ 1 ], [ 2 ], [ 3 ], 4 ])
).toEqual([ 2 ])
})
it("indexOf", () => {
expect(
R.indexOf(3, [ 1, 2, 3, 4 ])
).toEqual(2)
expect(
R.indexOf(1)([ 1, 2, 3, 4 ])
).toEqual(0)
})
it("init/tail", () => {

@@ -118,44 +221,126 @@ expect(

it("join",()=>{
it("join", () => {
expect(
R.join(
"|"
)(["foo","bar","baz"])
)([ "foo", "bar", "baz" ])
).toEqual("foo|bar|baz")
})
it("map",()=>{
it("last", () => {
expect(
R.compose(
R.last,
R.map(R.last)
)([ "foo", "bar", "baz" ])
).toEqual("z")
})
it("length", () => {
expect(
R.length("foo")
).toEqual(3)
})
it("map", () => {
expect(
R.compose(
val => val.reverse(),
R.map(R.subtract(10)),
R.adjust(R.add(1),0)
)([0,2,3,4,5,6,7,8,9])
).toEqual([1,2,3,4,5,6,7,8,9])
R.adjust(R.add(1), 0)
)([ 0, 2, 3, 4, 5, 6, 7, 8, 9 ])
).toEqual([ 1, 2, 3, 4, 5, 6, 7, 8, 9 ])
})
it("last",()=>{
it("match", () => {
expect(
R.compose(
R.last,
R.map(R.last)
)(["foo","bar","baz"])
).toEqual("z")
R.match(
/a./g
)("foo bar baz")
).toEqual([ "ar", "az" ])
expect(
R.match(
/a./g
)("foo")
).toEqual([])
expect(
() => { R.match(/a./g, null) }
).toThrow()
})
it("prepend",()=>{
it("merge", () => {
expect(
R.merge(
{ foo:"bar", bar:"bar" }
)({ bar:"baz" })
).toEqual({ foo:"bar", bar:"baz" })
})
it("omit", () => {
expect(
R.omit(
[ "a", "c" ]
)({ a:"foo", b:"bar", c:"baz" })
).toEqual({ b:"bar" })
})
it("prepend", () => {
expect(
R.compose(
R.flatten,
R.map(R.prepend(0))
)([[1],[2],[3]])
).toEqual( [1, 0, 2, 0, 3,0])
)([ [ 1 ], [ 2 ], [ 3 ] ])
).toEqual([ 1, 0, 2, 0, 3, 0 ])
})
it("propEq",()=>{
it("path", () => {
expect(
R.path(
[ "foo", "bar", "baz" ]
)({ foo:{ bar:{ baz:"yes" } } })
).toEqual("yes")
expect(
R.path(
[ "foo", "bar", "baz" ]
)(null)
).toEqual(undefined)
expect(
R.path(
[ "foo", "bar", "baz" ]
)({ foo:{ bar:"baz" } })
).toEqual(undefined)
})
it("pick", () => {
expect(
R.pick(
[ "a", "c" ]
)({ a:"foo", b:"bar", c:"baz" })
).toEqual({ a:"foo", c:"baz" })
})
it("prop", () => {
expect(
R.prop(
"foo"
)({ foo:"baz" })
).toEqual("baz")
expect(
R.prop(
"bar"
)({ foo:"baz" })
).toEqual(undefined)
})
it("propEq", () => {
expect(
R.propEq(
"foo",
"bar"
)({foo:"bar"})
)({ foo:"bar" })
).toBeTruthy()

@@ -167,7 +352,11 @@

"bar"
)({foo:"baz"})
)({ foo:"baz" })
).toBeFalsy()
expect(
R.propEq("foo")("bar")({ foo:"baz" })
).toBeFalsy()
})
it("range",()=>{
it("range", () => {
expect(

@@ -178,6 +367,6 @@ R.range(

)
).toEqual([0,1,2,3,4,5,6,7,8,9])
).toEqual([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ])
})
it("repeat",()=>{
it("repeat", () => {
expect(

@@ -188,52 +377,52 @@ R.replace(/\s/g)("|")("foo bar baz")

it("replace",()=>{
it("replace", () => {
expect(
R.repeat('foo', 3)
).toEqual(["foo","foo","foo"])
R.repeat("foo", 3)
).toEqual([ "foo", "foo", "foo" ])
expect(
R.repeat({}, 3)
).toEqual([{},{},{}])
).toEqual([ {}, {}, {} ])
})
it("sort",()=>{
it("sort", () => {
expect(
R.sort(
(a,b)=> a>b
)(["foo","bar","baz"])
).toEqual(["bar", "baz", "foo"])
(a, b) => a > b
)([ "foo", "bar", "baz" ])
).toEqual([ "bar", "baz", "foo" ])
expect(
R.sort(
(a,b)=> a-b
)([2,3,1])
).toEqual([1,2,3])
(a, b) => a - b
)([ 2, 3, 1 ])
).toEqual([ 1, 2, 3 ])
})
it("sortBy",()=>{
it("sortBy", () => {
const sortByNameCaseInsensitive = R.sortBy(
R.compose(
R.toLower,
Ramda.prop('name')
Ramda.prop("name")
)
)
const alice = {
name: 'ALICE',
age: 101
};
name: "ALICE",
age: 101,
}
const bob = {
name: 'Bob',
age: -10
};
name: "Bob",
age: -10,
}
const clara = {
name: 'clara',
age: 314.159
};
const people = [clara, bob, alice];
name: "clara",
age: 314.159,
}
const people = [ clara, bob, alice ]
expect(
sortByNameCaseInsensitive(people)
).toEqual( [alice, bob, clara])
).toEqual([ alice, bob, clara ])
})
it("split",()=>{
it("split", () => {
expect(

@@ -243,50 +432,50 @@ R.split(

)("foo|bar|baz")
).toEqual(["foo","bar","baz"])
).toEqual([ "foo", "bar", "baz" ])
})
it("splitEvery",()=>{
it("splitEvery", () => {
expect(
R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7])
).toEqual([[1, 2, 3], [4, 5, 6], [7]])
R.splitEvery(3, [ 1, 2, 3, 4, 5, 6, 7 ])
).toEqual([ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7 ] ])
expect(
R.splitEvery(3, 'foobarbaz')
).toEqual(["foo","bar","baz"])
R.splitEvery(3)("foobarbaz")
).toEqual([ "foo", "bar", "baz" ])
})
it("take",()=>{
it("take", () => {
expect(
R.take(1, ['foo', 'bar', 'baz'])
).toEqual(['foo'])
R.take(1, [ "foo", "bar", "baz" ])
).toEqual([ "foo" ])
expect(
R.take(3, 'rambda')
R.take(3)("rambda")
).toEqual("ram")
})
it("takeLast",()=>{
it("takeLast", () => {
expect(
R.takeLast(1, ['foo', 'bar', 'baz'])
).toEqual(['baz'])
R.takeLast(1, [ "foo", "bar", "baz" ])
).toEqual([ "baz" ])
expect(
R.takeLast(10, ['foo', 'bar', 'baz'])
).toEqual(['foo', 'bar', 'baz'])
R.takeLast(10, [ "foo", "bar", "baz" ])
).toEqual([ "foo", "bar", "baz" ])
expect(
R.takeLast(3, 'rambda')
R.takeLast(3, "rambda")
).toEqual("bda")
})
it("test",()=>{
it("test", () => {
expect(
R.test(/^x/, 'xyz')
R.test(/^x/, "xyz")
).toBeTruthy()
expect(
R.test(/^y/, 'xyz')
R.test(/^y/)("xyz")
).toBeFalsy()
})
it("toLower",()=>{
it("toLower", () => {
expect(

@@ -297,3 +486,3 @@ R.toLower("FOO|BAR|BAZ")

it("toUpper",()=>{
it("toUpper", () => {
expect(

@@ -308,4 +497,10 @@ R.compose(

it("type",()=>{
it("trim", () => {
expect(
R.trim(" foo ")
).toEqual("foo")
})
it("type", () => {
expect(
R.type({})

@@ -337,22 +532,25 @@ ).toEqual("Object")

).toEqual("RegExp")
expect(
R.type(undefined)
).toEqual("Undefined")
})
it("values",()=>{
it("values", () => {
expect(
R.values({a:1,b:2,c:3})
).toEqual([1,2,3])
R.values({ a:1, b:2, c:3 })
).toEqual([ 1, 2, 3 ])
})
it("uniq",()=>{
it("uniq", () => {
expect(
R.uniq([1,2,3,3,3,1,2,0])
).toEqual([1,2,3,0])
R.uniq([ 1, 2, 3, 3, 3, 1, 2, 0 ])
).toEqual([ 1, 2, 3, 0 ])
})
it("update",()=>{
it("update", () => {
expect(
R.update(3)(1)([1,2,3])
).toEqual([1,3,3])
R.update(3)(1)([ 1, 2, 3 ])
).toEqual([ 1, 3, 3 ])
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc