New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lit-match

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lit-match

An awesome new package

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
5
-64.29%
Maintainers
0
Weekly downloads
 
Created
Source

lit-match

A minimal alternative to ts-pattern that focuses on literal values and supports enums!


Usage

import { match } from "lit-match"

enum Progress {
  None,
  Loading,
  Loaded,
}

const currentProgress = Progress.Loaded as Progress

the above is used for all proceeding examples:

const result = match(currentProgress)
  .with(Progress.None, () => null)
  .with(Progress.Loading, () => "loading")
  .with(Progress.Loaded, () => "loaded")
  .exhaustive()

console.log(result)
//          ^? string | null

The exhaustive method will throw a compile-time error if not all variants have been exhausted.

const result = match(currentProgress)
  .with(Progress.None, () => null)
  .with(Progress.Loading, () => "loading")
  .exhaustive()
// ^ throws compile-time error, not all variants have been exhausted

The else allows you to handle cases where no pattern matches, or can be used like a 'fallthrough' case.

const result = match(currentProgress)
  .with(Progress.None, (value) => null)
  //                    ^? Progress.None
  .else((value) => "active")
//       ^? Progress.Loading | Progress.Loaded

console.log(result)
//          ^? null | "active"

FAQs

Package last updated on 15 Mar 2025

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