Skip to content

Commit ee1ae58

Browse files
authored
docs: improve readme (#28)
1 parent 4361233 commit ee1ae58

1 file changed

Lines changed: 53 additions & 3 deletions

File tree

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,48 @@
1-
# AssertionError [![Build Status](https://github.com/chaijs/assertion-error/actions/workflows/nodejs.yml/badge.svg)](https://github.com/chaijs/assertion-error/actions/workflows/nodejs.yml)
1+
<p align=center>
2+
AssertionError and AssertionResult classes.
3+
</p>
24

3-
> Error constructor for test and validation frameworks that implements standardized AssertionError specification.
5+
<p align=center>
6+
<a href="https://github.com/chaijs/assertion-error/actions">
7+
<img
8+
alt="build:?"
9+
src="https://github.com/chaijs/assertion-error/actions/workflows/nodejs.yml/badge.svg"
10+
/>
11+
</a><a href="https://www.npmjs.com/package/assertion-error">
12+
<img
13+
alt="downloads:?"
14+
src="https://img.shields.io/npm/dm/assertion-error.svg"
15+
/>
16+
</a><a href="">
17+
<img
18+
alt="devDependencies:none"
19+
src="https://img.shields.io/badge/dependencies-none-brightgreen"
20+
/>
21+
</a>
22+
</p>
23+
24+
## What is AssertionError?
25+
26+
Assertion Error is a module that contains two classes: `AssertionError`, which
27+
is an instance of an `Error`, and `AssertionResult` which is not an instance of
28+
Error.
29+
30+
These can be useful for returning from a function - if the function "succeeds"
31+
return an `AssertionResult` and if the function fails return (or throw) an
32+
`AssertionError`.
33+
34+
Both `AssertionError` and `AssertionResult` implement the `Result` interface:
35+
36+
```typescript
37+
interface Result {
38+
name: 'AssertionError' | 'AssertionResult'
39+
ok: boolean
40+
toJSON(...args: unknown[]): Record<string, unknown>
41+
}
42+
```
43+
44+
So if a function returns `AssertionResult | AssertionError` it is easy to check
45+
_which_ one is returned by checking either `.name` or `.ok`, or check `instanceof Error`.
446

547
## Installation
648

@@ -10,4 +52,12 @@
1052

1153
```
1254
$ npm install --save assertion-error
13-
```
55+
```
56+
57+
### Deno
58+
59+
`assertion_error` is available on [Deno.land](https://deno.land/x/assertion_error)
60+
61+
```
62+
import {AssertionError, AssertionResult} from 'https://deno.land/x/assertion_error@2.0.0/mod.ts'
63+
```

0 commit comments

Comments
 (0)