@dovca/toolbox
TypeScript icon, indicating that this package has built-in type declarations

0.0.33 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @dovca/toolbox

Weekly Downloads

195

Version

0.0.33

License

LGPL-3.0-or-later

Unpacked Size

708 kB

Total Files

8

Last publish

Collaborators

  • dovca