JSPM

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

This library includes functional helpers for object, string, and array processing.

Package Exports

  • cbk-functional-library

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 (cbk-functional-library) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cbk-functional-library

This library offers a lot of functional helpers I use a lot in my applications. Mainly I want to allow most of Javascripts functionality to be used in a function pipeline. A function pipeline replaces the use of functions this way

function doSomething(input) {
    const preparation = prepareTheData(input)
    const data = getDataFromAPI(preparation)
    const result = validateTheData(data)
    return result
}

by this way

const doSomething = flow(
    prepareTheData,
    getDataFromAPI,
    validateTheData
)

which I think is way easier to read. However, it also brings some challenges in terms of error handling and async calls. In the coming weeks I will add some descriptions how to handle those using the library.

Getting Started

Install the library using npm:

npm install cbk-functional-library --save

Use the library by importing it:

import { flow, ifThenElse, log, isDevEnvironment, addMinutes } from "cbk-functional-library"

const addHoursToDate = (date, hours) => flow(
    ifThenElse(isDevEnvironment, log("Called addHoursToDate")),
    (date) => addMinutes(date, hours*60),
    ifThenElse(isDevEnvironment, log("Result of addHoursToDate")),
)(date)

const inOneHour = addHoursToDate(new Date(), 1)

I think it is useful to just import the functions you want to use in your code as shown in the example above.

Documentation

Find the documentation for the library here.

Contribute and raise issues

Feel free to contribute to the library and send me a pull request in the Github repo. Also, feel free to raise an issue in the repo.