Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 7, 2021
1 parent f6640b3 commit 1f7c988
Showing 1 changed file with 69 additions and 12 deletions.
81 changes: 69 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,56 @@
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]

:warning: Throw a given error.
Throw if given an error.

## Install
## Contents

* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`bail(err?)`](#bailerr)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)

## What is this?

This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.
This package throws a given error.

[npm][]:
## When should I use this?

Use this package if you’re building some scripts that might theoretically get
errors but frequently don’t and you keep writing `if (error) throw error` over
and over again and you’re just really done with that.

## Install

This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:

```sh
npm install bail
```

In Deno with [Skypack][]:

```js
import {bail} from 'https://cdn.skypack.dev/bail@2?dts'
```

In browsers with [Skypack][]:

```html
<script type="module">
import {bail} from 'https://cdn.skypack.dev/bail@2?min'
</script>
```

## Use

```js
Expand All @@ -34,27 +71,39 @@ bail(new Error('failure'))

## API

This package exports the following identifiers: `bail`.
This package exports the following identifier: `bail`.
There is no default export.

### `bail([err])`
### `bail(err?)`

Throw a given error.
Throw a given error (`Error?`).

###### Parameters
## Types

* `err` (`Error?`) — Optional error.
This package is fully typed with [TypeScript][].
There are no extra exported types.

###### Throws
## Compatibility

* `Error` — Given error, if any.
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
It also works in Deno and modern browsers.

## Security

This package is safe.

## Related

* [`noop`][noop]
* [`noop2`][noop2]
* [`noop3`][noop3]

## Contribute

Yes please!
See [How to Contribute to Open Source][contribute].

## License

[MIT][license] © [Titus Wormer][author]
Expand All @@ -79,10 +128,18 @@ Throw a given error.

[npm]: https://docs.npmjs.com/cli/install

[skypack]: https://www.skypack.dev

[license]: license

[author]: https://wooorm.com

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[typescript]: https://www.typescriptlang.org

[contribute]: https://opensource.guide/how-to-contribute/

[noop]: https://www.npmjs.com/package/noop

[noop2]: https://www.npmjs.com/package/noop2
Expand Down

0 comments on commit 1f7c988

Please sign in to comment.