New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

by-jituanlin-match

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

by-jituanlin-match

A convenient function as an alternative to the switch statement

  • 1.0.1
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

by-jituanlin-match

What is

A convenient function as an alternative to the switch statement.

Why and How

Before After
let answer;
switch (value) {
  case 1:
    answer = 'one';
    break;
  default:
    answer = 'forty-two';
}
...
<div>
  {answer}
<div/>
see detail1
<div>
  {match(value)(
       [1, 'one'],
       [stubTrue, 'forty-two']
     )}
<div/>
switch (value) {
  case _.isArray(value):
    doSomething(value);
    break;
  case _.isNumber(value):
    doAnotherThing(value);
    break
}
see detail2
match(value)(
  [_.isArray,doSomething],
  [_.isNumber,doAnotherThing]
)
switch (value) {
  case 1:
    switch (anotherValue) {
      case 2:
        return 'one then two';
      default:
        return 'default';
    }
  default:
    return 'default';
}
see detail3
match(value)(
  [1,match(anotherValue)(
      [2, 'one then two'])
  ],
  [stubTrue, 'default']
);

Detail

  1. The match function call is a expression,you can use it directly in jsx

  2. Match function support for parameters of function types. Its return value will be used as the return value of the match function.

  3. If the branch does not match (or returns null),subsequent branches will continue to be performed

Install and Import

install: npm install by-jituanlin-match or yarn add by-jituanlin-match

then import {stubTrue,match} from 'by-jituanlin-match' or

const {stubTrue,match} = require('by-jituanlin-match')

FAQs

Package last updated on 29 Mar 2019

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