@one-format/http-plugin 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @one-format/http-plugin
|
|
2
|
+
|
|
3
|
+
An official one-format plugin for formatting standard HTTP status codes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @one-format/http-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
The package exports a plugin object containing two tools:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import httpPlugin from "@one-format/http-plugin";
|
|
17
|
+
|
|
18
|
+
httpPlugin.tools.codeToMessage(404);
|
|
19
|
+
// "Not Found"
|
|
20
|
+
|
|
21
|
+
httpPlugin.tools.codeToFormal(404);
|
|
22
|
+
// "HTTP/404 Not Found"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Use the plugin with `@one-format/core` to expose its tools directly:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import adapter from "@one-format/core";
|
|
29
|
+
import httpPlugin from "@one-format/http-plugin";
|
|
30
|
+
|
|
31
|
+
const http = adapter(httpPlugin);
|
|
32
|
+
|
|
33
|
+
http.codeToMessage(500); // "Internal Server Error"
|
|
34
|
+
http.codeToFormal(201); // "HTTP/201 Created"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Supported status codes
|
|
38
|
+
|
|
39
|
+
The `HttpStatusCode` type covers the standard HTTP status codes in the
|
|
40
|
+
informational (1xx), success (2xx), redirection (3xx), client error (4xx),
|
|
41
|
+
and server error (5xx) ranges, including WebDAV and other registered codes.
|
|
42
|
+
TypeScript will restrict tool inputs to the supported codes.
|
|
43
|
+
|
|
44
|
+
### API
|
|
45
|
+
|
|
46
|
+
- `tools.codeToMessage(code)` - returns the reason phrase for a status code.
|
|
47
|
+
- `tools.codeToFormal(code)` - returns a formatted `HTTP/<code> <message>`
|
|
48
|
+
status line.
|
|
49
|
+
- `metadata` - identifies the plugin and its version.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
EUPL-1.2
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ const httpPlugin = {
|
|
|
3
3
|
"metadata": {
|
|
4
4
|
"author": "Vedansh Shetti <vedansh.shetti@gmail.com> - one-format Official Plugin",
|
|
5
5
|
"name": "One-Format Datetime",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.1.0"
|
|
7
7
|
},
|
|
8
8
|
tools: {
|
|
9
9
|
codeToFormal: (code) => `HTTP/${code} ${HTTP_STATUS_MESSAGES[code]}`,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -28,7 +28,7 @@ const httpPlugin: PluginType<{
|
|
|
28
28
|
"metadata": {
|
|
29
29
|
"author": "Vedansh Shetti <vedansh.shetti@gmail.com> - one-format Official Plugin",
|
|
30
30
|
"name": "One-Format Datetime",
|
|
31
|
-
"version": "1.
|
|
31
|
+
"version": "1.1.0"
|
|
32
32
|
},
|
|
33
33
|
tools: {
|
|
34
34
|
codeToFormal: (code: HttpStatusCode) => `HTTP/${code} ${HTTP_STATUS_MESSAGES[code]}`,
|