Skip to content

dovca/toolbox

Repository files navigation

JSR JSR Score

Toolbox

A set of general-purpose typescript functions for common tasks.

Installation

The toolbox is available via JSR. To install it, run:

npx jsr add @dovca/toolbox

Motivation

The main goal of this package is to remedy the pain of writing readable linear functional code in TypeScript. This package was conceived as a workaround for these issues:

  • Lodash's chain() breaks in production builds. (see issue)
  • TypeScript doesn't support the pipeline operator (yet). (see issue)

One example for all

import {
    add, flow, fromCharCode, grow, increment,
    join, log, map, multiply, toArray,
} from '@dovca/toolbox';

const result = flow(
  1,                 // 1
  add(12),           // 13
  multiply(5),       // 65
  toArray,           // [65]
  grow(increment),   // [65, 66]
  map(fromCharCode), // ['A', 'B']
  join(', '),        // 'A, B'
  log,               // -> console.log('A, B')
);

result; // 'A, B'

Used nomenclature

  • flowing value - the value that is being passed through the flow and pipe functions
  • to produce a value - a function produces a value that then becomes the flowing value
  • predicate - a unary function that "passes" when it returns true for a given value

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published