Skip to content

Commit

Permalink
chore: fix typo and fmt (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
lino-levan authored Jan 5, 2023
1 parent 856f0d6 commit 65e5084
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[![Deno Version](https://img.shields.io/badge/deno-1.0.0-informational)](https://deno.land)
[![Deno Doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/status/mod.ts)

HTTP codes and status utility for Deno. Based on [Java Apache HttpStatus](http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpStatus.html)
HTTP codes and status utility for Deno. Based on
[Java Apache HttpStatus](http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpStatus.html)

## API

Expand All @@ -14,23 +15,24 @@ HTTP codes and status utility for Deno. Based on [Java Apache HttpStatus](http:/
```typescript
import { status } from "https://deno.land/x/status/mod.ts";

status(403) // => "FORBIDDEN"
status("403") // => "FORBIDDEN"
status.pretty(403) // => "Forbidden"
status(306) // throws
status(403); // => "FORBIDDEN"
status("403"); // => "FORBIDDEN"
status.pretty(403); // => "Forbidden"
status(306); // throws
```

### status(message)

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

status("forbidden") // => 403
status("FoRbIdDeN") // => 403
status("foo") // throws
status("forbidden"); // => 403
status("FoRbIdDeN"); // => 403
status("foo"); // throws
```

### status.codes

Array of all the possible status codes.

```typescript
Expand All @@ -40,6 +42,7 @@ status.codes; // => [202, 502, 400, ...]
```

### status.code[code]

Map of all the available codes. `message (string) -> code (number)`

```typescript
Expand All @@ -50,6 +53,7 @@ status.code["FORBIDDEN"] = 403;
```

### status.message[msg]

Map of all the available codes. `code (number) -> message (string)`

```typescript
Expand All @@ -60,40 +64,46 @@ status.message[403] = "FORBIDDEN";
```

### status.empty[code]
Returns `true` if a status code exprects an empty body.

Returns `true` if a status code expects an empty body.

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

status.empty[200] // => undefined
status.empty[204] // => true
status.empty[200]; // => undefined
status.empty[204]; // => true
```

### status.redirect[code]

Returns `true` if a status code is a valid redirect status.

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

status.redirect[200] // => undefined
status.redirect[301] // => true
status.redirect[200]; // => undefined
status.redirect[301]; // => true
```

### status.retry[code]

Returns `true` if a status code hints that the request might be retried.

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

status.retry[501] // => undefined
status.retry[503] // => true
status.retry[501]; // => undefined
status.retry[503]; // => true
```


## other

### contribution
Pull request and issues are very welcome. Code style is formatted with `deno fmt`.

Pull request and issues are very welcome. Code style is formatted with
`deno fmt`.

### inspiration
The project is inspired by the [statuses](https://github.com/jshttp/statuses) project.

The project is inspired by the [statuses](https://github.com/jshttp/statuses)
project.
4 changes: 2 additions & 2 deletions status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ status.retry = {

/**
* Get the status code. But pretty printed.
*
*
* Given a number, this will throw if it is not a known status
* code, otherwise the code will be returned. Given a string,
* the string will be parsed for a number and return the code
* if valid, otherwise will lookup the code assuming this is
* the status message.
*
*
* Status codes remain the same as status(arg)
* Status messages are pretty printed:
* 'INTERNAL_SERVER_ERROR' -> 'Internal Server Error'
Expand Down
5 changes: 1 addition & 4 deletions status_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {
assertThrows,
} from "https://deno.land/std/testing/asserts.ts";

import {
status,
MOVED_PERMANENTLY,
} from "./mod.ts";
import { MOVED_PERMANENTLY, status } from "./mod.ts";

Deno.test({
name: "status:arguments:number",
Expand Down

0 comments on commit 65e5084

Please sign in to comment.