statementjs
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

npm version

statementjs

A simple library for run javascript statements inline and returning the values. Offers full typescript support.

Installation

npm i --save statementjs

Usage

import {
  iif,
  itry,
  iswitch
} from 'statementjs';

// If
const ifValue = iif(() => false, () => "first if")
  .elseIf(() => false, () => "second if")
  .else(() => "else");

// Try
const tryValue = itry(() => {
  new Error("throw an error");
})
  .catchAll(error => {
    console.log(error) // Error<throw an error>

    return "actual value";
  })
  .finally(); // returns "actual value"

// Switch

const switchValue = iswitch(1)
  .case(() => 2, () => "nope")
  .case(() => 3, () => "not me")
  .case(() => 1, () => "yep")
  .default(() => "default value") // returns "yep"

For more details usage, see the jsdocs

/statementjs/

    Package Sidebar

    Install

    npm i statementjs

    Weekly Downloads

    0

    Version

    0.2.0

    License

    GPL-3.0

    Unpacked Size

    65.6 kB

    Total Files

    21

    Last publish

    Collaborators

    • sam.boylett