# panic-fn

> Functional way of throwing errors in JS/TS

Latest version **1.2.1** (published 2022-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install panic-fn
pnpm add panic-fn
yarn add panic-fn
bun add panic-fn
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2022-06-08 |
| First published | 2021-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | glebbash |
| Maintainers | glebbash |

## Links

- npm: https://www.npmjs.com/package/panic-fn
- Repository: https://github.com/glebbash/panic-fn
- Homepage: https://github.com/glebbash/panic-fn#readme
- Issues: https://github.com/glebbash/panic-fn/issues
- npm.io page: https://npm.io/package/panic-fn

## Recent versions

- 1.2.1 (latest) — 2022-06-08
- 1.2.0 — 2022-06-07
- 1.1.3 — 2022-06-07
- 1.1.2 — 2022-06-07
- 1.1.1 — 2022-06-07
- 1.1.0 — 2022-06-07
- 1.0.3 — 2021-02-06
- 1.0.2 — 2021-02-05
- 1.0.1 — 2021-02-05
- 1.0.0 — 2021-02-05

## README

# panic-fn

[![Source](https://img.shields.io/badge/source-github-informational)](https://github.com/glebbash/panic-fn)
[![Deploy](https://github.com/glebbash/panic-fn/actions/workflows/release.yml/badge.svg)](https://github.com/glebbash/panic-fn/actions)
[![Coverage Status](https://coveralls.io/repos/github/glebbash/panic-fn/badge.svg?branch=main)](https://coveralls.io/github/glebbash/panic-fn?branch=main)

Functional way of throwing errors in JS/TS

## Why?

Have you ever tried to do this?

```ts
callback(() => throw new Error("Not implemented"));
// or this
doStuff(value ?? throw new Error("No value provided"));
```

But got `Uncaught SyntaxError: Unexpected token 'throw'`.

With `panic-fn` it works as expected.

```ts
callback(() => panic("Not implemented"));
// or this
doStuff(value ?? panic("No value provided"));
```

You can also throw custom errors:

```ts
panic(new SyntaxError(`Unexpected token 'throw'`));
```

## Installation

### Node

```bash
npm i panic-fn
```

```ts
import { panic } from "panic-fn";
```

### Deno

```ts
import { panic } from "https://deno.land/x/panic_fn/mod.ts";
```

## Module info

This module was created using [denoland/dnt](https://github.com/denoland/dnt).

Source is written in Deno and compiles to both Node.js CJS and ESM.

---
_Source: https://npm.io/package/panic-fn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
