Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

composable-statements

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

composable-statements

Composable Statements for JavaScript

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Composable Statements for JavaScript

Usually statements like IfStatement is not composable within expression like function call. This package provides alternative way to express statements as composable function call expression. This may be useful when you are using stuff like JSX, which uses tons of nested expressions.

Currently IfStatement is only implementation so far, but more is to come! Feel free to suggest improvements, features, or report bugs. There is no NPM dependency.

I do not think so, for the most of case. But I don't like putting && or ternery operator everywhere, this is way better than doing such for the readability's sake, IMHO.

Installation

npm install composable-statements

Usage

start with IfStatement() (if_) and end with fi(). You can chain elif() and else() after if_.

JavaScript

import {
    IfStatement as if_
} from 'composable-statements';

if_(foo, () => 'foo')
    .elif_(bar, () => 'bar')
    .else_(() => 'baz')
.fi();

JSX:

// Conditional event handler
<div onClick={
    if_(foo, () => (e) => { $('#foo').append('<div className="this-is-if" />'); })
        .elif(bar, () => (e) => { $('#bar').append('<div className="this-is-elif" />'); })
        .else(() => (e) => { $('#baz').append('<div className="this-is-else" />'); })
    .fi()
    }
/>

// conditional element
<div>
    {
        if_(foo, <div className="foo" />)
            .elif(foo, <div className="bar-is-complicated"><ul></ul></div>)
        .fi()
    }
</div>

Keywords

FAQs

Package last updated on 19 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc