@nsnanocat/util 1.8.2 → 1.8.4

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/index.js CHANGED
@@ -6,7 +6,7 @@ export * from "./lib/wait.mjs";
6
6
  export * from "./polyfill/Console.mjs";
7
7
  export * from "./polyfill/fetch.mjs";
8
8
  export * from "./polyfill/Lodash.mjs";
9
- export * from "./polyfill/StatusCodes.mjs";
9
+ export * from "./polyfill/StatusTexts.mjs";
10
10
  export * from "./polyfill/Storage.mjs";
11
11
  export * from "./gRPC.mjs";
12
12
  export * from "./getStorage.mjs";
package/lib/done.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { $app } from "./app.mjs";
2
2
  import { Console } from "../polyfill/Console.mjs";
3
3
  import { Lodash as _ } from "../polyfill/Lodash.mjs";
4
- import { StatusCodes } from "../polyfill/StatusCodes.mjs";
4
+ import { StatusTexts } from "../polyfill/StatusTexts.mjs";
5
5
 
6
6
  /**
7
7
  * Complete the script execution
@@ -40,14 +40,13 @@ export function done(object = {}) {
40
40
  object = _.pick(object, ["status", "url", "headers", "body", "bodyBytes"]);
41
41
  switch (typeof object.status) {
42
42
  case "number":
43
- object.status = StatusCodes[object.status];
43
+ object.status = `HTTP/1.1 ${object.status} ${StatusTexts[object.status]}`;
44
44
  break;
45
45
  case "string":
46
46
  case "undefined":
47
47
  break;
48
48
  default:
49
- object.status = undefined;
50
- break;
49
+ throw new TypeError(`${Function.name}: 参数类型错误, status 必须为数字或字符串`);
51
50
  }
52
51
  if (object.body instanceof ArrayBuffer) {
53
52
  object.bodyBytes = object.body;
package/package.json CHANGED
@@ -36,5 +36,5 @@
36
36
  "devDependencies": {
37
37
  "typescript": "^5.6.3"
38
38
  },
39
- "version": "1.8.2"
39
+ "version": "1.8.4"
40
40
  }
@@ -0,0 +1,62 @@
1
+ export const StatusTexts = {
2
+ 100: "Continue",
3
+ 101: "Switching Protocols",
4
+ 102: "Processing",
5
+ 103: "Early Hints",
6
+ 200: "OK",
7
+ 201: "Created",
8
+ 202: "Accepted",
9
+ 203: "Non-Authoritative Information",
10
+ 204: "No Content",
11
+ 205: "Reset Content",
12
+ 206: "Partial Content",
13
+ 207: "Multi-Status",
14
+ 208: "Already Reported",
15
+ 226: "IM Used",
16
+ 300: "Multiple Choices",
17
+ 301: "Moved Permanently",
18
+ 302: "Found",
19
+ 304: "Not Modified",
20
+ 307: "Temporary Redirect",
21
+ 308: "Permanent Redirect",
22
+ 400: "Bad Request",
23
+ 401: "Unauthorized",
24
+ 402: "Payment Required",
25
+ 403: "Forbidden",
26
+ 404: "Not Found",
27
+ 405: "Method Not Allowed",
28
+ 406: "Not Acceptable",
29
+ 407: "Proxy Authentication Required",
30
+ 408: "Request Timeout",
31
+ 409: "Conflict",
32
+ 410: "Gone",
33
+ 411: "Length Required",
34
+ 412: "Precondition Failed",
35
+ 413: "Content Too Large",
36
+ 414: "URI Too Long",
37
+ 415: "Unsupported Media Type",
38
+ 416: "Range Not Satisfiable",
39
+ 417: "Expectation Failed",
40
+ 418: "I'm a teapot",
41
+ 421: "Misdirected Request",
42
+ 422: "Unprocessable Entity",
43
+ 423: "Locked",
44
+ 424: "Failed Dependency",
45
+ 425: "Too Early",
46
+ 426: "Upgrade Required",
47
+ 428: "Precondition Required",
48
+ 429: "Too Many Requests",
49
+ 431: "Request Header Fields Too Large",
50
+ 451: "Unavailable For Legal Reasons",
51
+ 500: "Internal Server Error",
52
+ 501: "Not Implemented",
53
+ 502: "Bad Gateway",
54
+ 503: "Service Unavailable",
55
+ 504: "Gateway Timeout",
56
+ 505: "HTTP Version Not Supported",
57
+ 506: "Variant Also Negotiates",
58
+ 507: "Insufficient Storage",
59
+ 508: "Loop Detected",
60
+ 510: "Not Extended",
61
+ 511: "Network Authentication Required",
62
+ };
@@ -1,6 +1,7 @@
1
1
  import { $app } from "../lib/app.mjs";
2
2
  import { Console } from "./Console.mjs";
3
3
  import { Lodash as _ } from "./Lodash.mjs";
4
+ import { StatusTexts } from "./StatusTexts.mjs";
4
5
 
5
6
  /**
6
7
  * fetch
@@ -104,6 +105,7 @@ export async function fetch(resource, options = {}) {
104
105
  else {
105
106
  response.ok = /^2\d\d$/.test(response.status);
106
107
  response.statusCode = response.status;
108
+ response.statusText = StatusTexts[response.status];
107
109
  if (body) {
108
110
  response.body = body;
109
111
  if (resource["binary-mode"] == true) response.bodyBytes = body;
@@ -130,6 +132,7 @@ export async function fetch(resource, options = {}) {
130
132
  response => {
131
133
  response.ok = /^2\d\d$/.test(response.statusCode);
132
134
  response.status = response.statusCode;
135
+ response.statusText = StatusTexts[response.status];
133
136
  switch ((response.headers?.["Content-Type"] ?? response.headers?.["content-type"])?.split(";")?.[0]) {
134
137
  case "application/protobuf":
135
138
  case "application/x-protobuf":
package/polyfill/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./Console.mjs";
2
2
  export * from "./fetch.mjs";
3
3
  export * from "./Lodash.mjs";
4
- export * from "./StatusCodes.mjs";
4
+ export * from "./StatusTexts.mjs";
5
5
  export * from "./Storage.mjs";
@@ -1,62 +0,0 @@
1
- export const StatusCodes = {
2
- 100: "HTTP/1.1 100 Continue",
3
- 101: "HTTP/1.1 101 Switching Protocols",
4
- 102: "HTTP/1.1 102 Processing",
5
- 103: "HTTP/1.1 103 Early Hints",
6
- 200: "HTTP/1.1 200 OK",
7
- 201: "HTTP/1.1 201 Created",
8
- 202: "HTTP/1.1 202 Accepted",
9
- 203: "HTTP/1.1 203 Non-Authoritative Information",
10
- 204: "HTTP/1.1 204 No Content",
11
- 205: "HTTP/1.1 205 Reset Content",
12
- 206: "HTTP/1.1 206 Partial Content",
13
- 207: "HTTP/1.1 207 Multi-Status",
14
- 208: "HTTP/1.1 208 Already Reported",
15
- 226: "HTTP/1.1 226 IM Used",
16
- 300: "HTTP/1.1 300 Multiple Choices",
17
- 301: "HTTP/1.1 301 Moved Permanently",
18
- 302: "HTTP/1.1 302 Found",
19
- 304: "HTTP/1.1 304 Not Modified",
20
- 307: "HTTP/1.1 307 Temporary Redirect",
21
- 308: "HTTP/1.1 308 Permanent Redirect",
22
- 400: "HTTP/1.1 400 Bad Request",
23
- 401: "HTTP/1.1 401 Unauthorized",
24
- 402: "HTTP/1.1 402 Payment Required",
25
- 403: "HTTP/1.1 403 Forbidden",
26
- 404: "HTTP/1.1 404 Not Found",
27
- 405: "HTTP/1.1 405 Method Not Allowed",
28
- 406: "HTTP/1.1 406 Not Acceptable",
29
- 407: "HTTP/1.1 407 Proxy Authentication Required",
30
- 408: "HTTP/1.1 408 Request Timeout",
31
- 409: "HTTP/1.1 409 Conflict",
32
- 410: "HTTP/1.1 410 Gone",
33
- 411: "HTTP/1.1 411 Length Required",
34
- 412: "HTTP/1.1 412 Precondition Failed",
35
- 413: "HTTP/1.1 413 Content Too Large",
36
- 414: "HTTP/1.1 414 URI Too Long",
37
- 415: "HTTP/1.1 415 Unsupported Media Type",
38
- 416: "HTTP/1.1 416 Range Not Satisfiable",
39
- 417: "HTTP/1.1 417 Expectation Failed",
40
- 418: "HTTP/1.1 418 I'm a teapot",
41
- 421: "HTTP/1.1 421 Misdirected Request",
42
- 422: "HTTP/1.1 422 Unprocessable Entity",
43
- 423: "HTTP/1.1 423 Locked",
44
- 424: "HTTP/1.1 424 Failed Dependency",
45
- 425: "HTTP/1.1 425 Too Early",
46
- 426: "HTTP/1.1 426 Upgrade Required",
47
- 428: "HTTP/1.1 428 Precondition Required",
48
- 429: "HTTP/1.1 429 Too Many Requests",
49
- 431: "HTTP/1.1 431 Request Header Fields Too Large",
50
- 451: "HTTP/1.1 451 Unavailable For Legal Reasons",
51
- 500: "HTTP/1.1 500 Internal Server Error",
52
- 501: "HTTP/1.1 501 Not Implemented",
53
- 502: "HTTP/1.1 502 Bad Gateway",
54
- 503: "HTTP/1.1 503 Service Unavailable",
55
- 504: "HTTP/1.1 504 Gateway Timeout",
56
- 505: "HTTP/1.1 505 HTTP Version Not Supported",
57
- 506: "HTTP/1.1 506 Variant Also Negotiates",
58
- 507: "HTTP/1.1 507 Insufficient Storage",
59
- 508: "HTTP/1.1 508 Loop Detected",
60
- 510: "HTTP/1.1 510 Not Extended",
61
- 511: "HTTP/1.1 511 Network Authentication Required",
62
- };