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
Package was removed
Sorry, it seems this package was removed from the registry

by-jituanlin-match

A convenient function as an alternative to the switch statement

1.0.1
unpublished
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
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

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