1.5.0 • Published 4 years ago

mini_ramda v1.5.0

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

mini_ramda

N|Solid

mini_ramda is a small collection of functions which will be useful for projects and other builds

Installation

mini_ramda requires Node.js v4+ to run.

Install using the command given below:

$ npm i mini_ramda

In index.js

let miniRamda = require('miniRamda')

Functions

assocPath(array, number, Object) Makes a shallow clone of an object, setting or overriding the nodes required to create the given path, and placing the specific value at the tail end of that path. Note that this copies and flattens prototype properties onto the new object as well. All non-primitive properties are copied by reference.

miniRamda.assocPath(['x', 'y', 'z'], 42, {x: {y: {z: 0}}});
>> {x: {y: {z: 42}}}

// Any missing or non-object keys in path will be overridden
miniRamda.assocPath(['a', 'b', 'c'], 42, {a: 5});
>> {a: {b: {c: 42}}}

merge(Object, Object) 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.

miniRamda.merge({ 'name': 'Rohith', 'age': 20 }, { 'age': 21 });
>> { 'name': 'Rohith', 'age': 21 }

append (value, value) Returns a new list containing the contents of the given list, followed by the given element.

miniRamda.append('tests', ['write', 'more']);
>> ['write', 'more', 'tests']
miniRamda.append('tests', []);
>> ['tests']
miniRamda.append(['tests'], ['write', 'more']);
>> ['write', 'more', ['tests']]

applyTo (value) Takes a value and applies a function to it. This function is also known as the thrush combinator.

const foo = miniRamda.applyTo(42);
foo(miniRamda.identity);
>> 42
foo(miniRamda.add(1));
>> 43

identity (value) A function that does nothing but return the parameter supplied to it. Good as a default or placeholder function.

const foo = miniRamda.applyTo("Gayathri");
foo(miniRamda.identity);
>> Gayathri

add (number)(number) Adds two numbers

miniRamda.add(1)(2);
>> 3

dupe (Array) returns true if there is a duplicate in an array

miniRamda.dupe([1,2,1])
>> true
miniRamda.dupe([1,2,3])
>> false

avgPair (Array,number) returns true if given average is equal to any of the averages of the pair inside the array

miniRamda.avgPair([1,2,1],1.5)
>> true
miniRamda.avgPair([1,2,3],3.8)
>> false

maxSubArray (Array,number) returns a maximum value among all the totals in a given window length

miniRamda.maxSubArray([1,4,2,10,23,3,1,0,20],2)
>> 33
miniRamda.maxSubArray([1,2,3],2)
>> 5

isSubseq (string 1, string 2) returns true if string 1 is a substring of string 2

miniRamda.isSubseq("sing","sting")
>> true

cond Returns a function, fn, which encapsulates if/else, if/else, ... logic. It takes a list of predicate, transformer pairs. All of the arguments to fn are applied to each of the predicates in turn until one returns a "truthy" value, at which point fn returns the result of applying its arguments to the corresponding transformer. If none of the predicates matches,fn returns undefined.

const fn = miniRamda.cond([
  [(x)=>x===0,()=>'The value 0 is minimum'],
  [(x)=>x===100,()=>'The value 100 is maximum'],
  [(x)=>x,temp=>'neither minimum nor maximum']
]);

fn(0) >> The value 0 is minimum
fn(100) >> The value 100 is maximum
fn(50) >> Neither minimum nor maximum

pipe Takes in an array of functions and values to be applied to the functions and returns the result of all the computations

let fn = miniRamda.pipe([(value)=>{
  let sum=0;
    for(let i=0;i<value.length;i++){
      sum=sum+value[i];
    }
    return sum;
},(value)=>10*value])([3,4])

>> 70
1.5.0

4 years ago

1.4.0

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.0

4 years ago