JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q26826F
  • License MIT

Some tools for ramda

Package Exports

  • bobda

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bobda) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Bobda

XO code style npm version

logo

It's an add-on module for Ramda, so all functions are curry.

Table of Contents


Installation

$ yarn add bobda

or $ npm install bobda

Documentation

Async Functions

We used the Bluebird functions and adapted them for use with Ramda

bromiseMap

bromiseMap(asyncFn : Function, array : Array): Promise

This function allows to apply a map but with an asynchronous function

Arguments

asyncFn: The asynchronous function who whant to apply

array: The array who want to apply a map

Exemple

const {bromiseMap} = require('bobda');

const squareAsync = async value =>
  new Promise(resolve => setTimeout(() => resolve(value * value), 30));

const array = [2, 3, 4, 5];
bromiseMap(squareAsync)(array); //=> Promise

bromiseAll

bromiseAll(array : Array<Promise>): Promise

This function allows you to wait until all the promises contained in an array are resolved

Arguments

array: The array of promise

Exemple

const R = require('ramda');
const {bromiseAll} = require('bobda');

const incrementAsync = async value =>
  new Promise(resolve => setTimeout(() => resolve(++value), 30));

const squareAsync = async value =>
  new Promise(resolve => setTimeout(() => resolve(value * value), 30));

const value = 2;
bromiseAll(R.juxt([incrementAsync, squareAsync]))(value); //=> Promise

bromiseProps

bromiseProps(object : Object): Promise

This function allows you to wait until all the promises contained in an object as key are resolved

Arguments

object: The array of promise

Exemple

const R = require('ramda');
const {bromiseProps} = require('bobda');

const incrementAsync = async value =>
  new Promise(resolve => setTimeout(() => resolve(++value), 30));

const squareAsync = async value =>
  new Promise(resolve => setTimeout(() => resolve(value * value), 30));

const value = 2;

bromiseProps(R.applySpec({incrementResult: incrementAsync, squareResult: squareAsync}))(value) //=> Promise

Object properties functions

renameProp

renameProp(from : String ,to : String): object

This function allows you to rename a prop into the given object.

Argments

  • from : Name of the prop you want to rename
  • to : New name you want to give to this prop
  • object : This function is curried by default, last argument (not explicitly given) is the object

Exemple

const myAwesomeObj = {
  prop1 : 'chapi',
  prop2 : 'chapo'
}
const myAwesomePipe = R.pipe(
  renameProp('prop1', 'readTheDoc')
)

myAwesomePipe(myAwesomeObj) 
/* =>
{
  readTheDoc : 'chapi',
  prop2 : 'chapo'
}
 */

Note Read test for other examples.

renamePath

renamePath(from : [String] ,to : [String]): object

This function allows you to rename a path into the given object.

Argments

  • from : Name of the path you want to rename
  • to : New name you want to give to this path
  • object : This function is curried by default, last argument (not explicitly given) is the object

Exemple

const myAwesomeObj = {
  prop1 : 'chapi',
  prop2 : { 
    chapo : { 
      patapo : true
    }
  }
}
const myAwesomePipe = R.pipe(
  renamePath(['prop2','chapo','patapo'], ['chapi','chapo','patapo'])
)

myAwesomePipe(myAwesomeObj) 
/* =>
{
  prop1 : 'chapi',
  chapi : { 
    chapo : { 
      patapo : true
    }
  }
}
 */

Note Read test for other examples.

multiPath

multiPath(mappingRename : [[[String],[String]]] ,object : Object): object

Argments

  • mappingRename : Name of the path you want to rename
  • object : New name you want to give to this path

This function take list of tuples and recursively replace the path [0] with the path [1] into the given object.

Exemple

const listOfPaths = [
  [['une', 'souris', 'verte'], ['qui', 'courait', 'dans']],
  [['l', 'herbe'], ['je', 'la', 'montre']],
  [['a', 'ces'], ['messieurs']]
];

const inObj = {
  une: {souris: {verte: true}},
  l: {herbe: false},
  a: {ces: 0}
};

multiPath(listOfPaths, inObj) 
/* =>
{
  qui: {courait: {dans: true}},
  je: {la: {montre: false}},
  messieurs: 0,
  a: {},
  l: {},
  une: {souris: {}}
};
 */

Note

Read test for other examples.