# @hudson-newey/conditional-match

> Adds support for a match() opperator with conditional matching

Latest version **1.0.4** (published 2023-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hudson-newey/conditional-match
pnpm add @hudson-newey/conditional-match
yarn add @hudson-newey/conditional-match
bun add @hudson-newey/conditional-match
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2023-05-17 |
| First published | 2023-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | hudson-newey |
| Maintainers | hudson-newey |
| Keywords | match |

## Links

- npm: https://www.npmjs.com/package/@hudson-newey/conditional-match
- Repository: https://github.com/hudson-newey/conditional-match
- Homepage: https://github.com/hudson-newey/conditional-match#readme
- Issues: https://github.com/hudson-newey/conditional-match/issues
- npm.io page: https://npm.io/package/@hudson-newey/conditional-match

## Recent versions

- 1.0.4 (latest) — 2023-05-17
- 1.0.3 — 2023-05-10
- 1.0.2 — 2023-05-10
- 1.0.1 — 2023-05-10
- 1.0.0 — 2023-05-10

## README

# Conditional Match

"Lazily evaluated switch statements"  
  
This is me just testing NPM and is probably not good for use in production.

## Examples

```ts
const conditions: Conditional[] = [
    {
        condition: (arg) => arg === 1,
        then: () => console.log("1"),
        else: () => console.log("not 1")
    },
    {
        condition: (arg) => arg === 2,
        then: () => console.log("2"),
        else: () => console.log("not 2")
    },
    {
        condition: (arg) => arg < 3,
        then: () => console.log("less than 3"),
    }
];

const matchCondition: MatchObject = {
    variable: 5,
    conditions
};

match(matchCondition);

// Output:
// not 1
// not 2
```

## Default Statements

```ts
const conditions: Conditional[] = [
    {
        condition: (x: number) => x > 1,
        then: () => console.log("hello world"),
    },
    {
        condition: (x: any) => typeof x === "string",
        then: () => console.log("incorrect input"),
    },
    {
        default: () => console.log("bar")
    }
];

match({ variable: "foo", conditions });

// Output:
// incorrect input
// bar
```

## Singular Match Statement

```ts
const conditions: Conditional = {
    condition: (x: number) => x > 10 && x < 999,
    then: () => "yay!"
};

match({
    variable: 100,
    conditions
});

// Output:
// yay!
```

## Only a Default Match Statement

```ts
const conditions: Conditional = {
    default: () => console.log("foo")
};

match({
    variable: 100,
    conditions
});

// output:
// Foo
```

---
_Source: https://npm.io/package/@hudson-newey/conditional-match · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
