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

@housinganywhere/match

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@housinganywhere/match

Poor man's pattern matching

  • 1.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-12.5%
Maintainers
4
Weekly downloads
 
Created
Source

poor man's pattern matching :traffic_light:

npm version CircleCI

Install

yarn add @housinganywhere/match

npm i @housinganywhere/match

Use

Edit @housinganywhere/match

import * as React from 'react';
import match from '@housinganywhere/match';

type Status = 'loading' | 'error' | 'success';

enum Status {
  loading = 'loading',
  error = 'error',
  success = 'success',
}

const StatusMsg: React.SFC<{ status: Status }> = ({ status }) =>
  match<Status, React.ReactNode>({
    loading: () => <Spinner />,
    error: () => <Alert type="danger">There was an error</Alert>,
    success: () => <Alert type="success">Yay! It worked</Alert>,
  })(status);

For matching several cases together use wildMatch. All the missing cases will be handled by case _.

import { wildMatch } from '@housinganywhere/match';

type Vowels = 'a' | 'e' | 'i' | 'o' | 'u';

const isA = wildMatch<Vowels, string>({
  a: () => 'Yay!',
  _: (v) => `Nope, "${v}" is not "a"`,
});

isA('a'); // 'Yay!'
isA('e'); // 'Nope, "e" is not "a"'
isA('i'); // 'Nope, "i" is not "a"'
isA('o'); // 'Nope, "o" is not "a"'
isA('u'); // 'Nope, "u" is not "a"'

License

MIT © 2019 HousingAnywhere

Keywords

FAQs

Package last updated on 04 Sep 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