@e-mc/request 0.13.10 → 0.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.13.10",
3
+ "version": "0.14.0",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/module": "0.13.10",
23
- "@e-mc/types": "0.13.10",
22
+ "@e-mc/module": "0.14.0",
23
+ "@e-mc/types": "0.14.0",
24
24
  "combined-stream": "^1.0.8",
25
25
  "js-yaml": "^4.1.1",
26
26
  "picomatch": "^4.0.4",
package/util.js CHANGED
@@ -1,30 +1,11 @@
1
1
  "use strict";
2
- exports.parseHeader = parseHeader;
3
- exports.parseOutgoingHeaders = parseOutgoingHeaders;
4
- exports.normalizeHeaders = normalizeHeaders;
5
- exports.getBasicAuth = getBasicAuth;
6
- exports.hasBasicAuth = hasBasicAuth;
7
- exports.checkRetryable = checkRetryable;
8
- exports.isRetryable = isRetryable;
9
- exports.parseHttpProxy = parseHttpProxy;
10
- exports.trimPath = trimPath;
11
- exports.asInt = asInt;
12
- exports.asFloat = asFloat;
13
- exports.fromSeconds = fromSeconds;
14
- exports.fromURL = fromURL;
15
- exports.fromStatusCode = fromStatusCode;
16
- exports.getTransferRate = getTransferRate;
17
- exports.hasSize = hasSize;
18
- exports.getSize = getSize;
19
- exports.hasSameStat = hasSameStat;
20
- exports.byteLength = byteLength;
21
- exports.cleanupStream = cleanupStream;
22
- const path = require("node:path");
23
- const fs = require("node:fs");
24
- const node_util_1 = require("node:util");
25
- const types_1 = require("@e-mc/types");
26
- const module_1 = require("@e-mc/module");
27
- const host_1 = require("@e-mc/request/http/host");
2
+
3
+ const path = require('node:path');
4
+ const fs = require('node:fs');
5
+ const { toUSVString } = require('node:util');
6
+ const { getEncoding, isArray, isError, isErrorCode, isObject, isString } = require('@e-mc/types');
7
+ const Module = require('@e-mc/module');
8
+ const HttpHost = require('@e-mc/request/http/host');
28
9
  function setHeader(result, key, value) {
29
10
  if (key === 'set-cookie') {
30
11
  (result[key] ||= []).push(value);
@@ -38,7 +19,7 @@ function parseHeader(headers, name) {
38
19
  const value = headers[name];
39
20
  switch (name.toLowerCase()) {
40
21
  case 'content-disposition':
41
- if ((0, types_1.isString)(value)) {
22
+ if (isString(value)) {
42
23
  let result;
43
24
  for (const match of value.matchAll(/\bfilename(?:\*\s*=\s*UTF-8''([^\s;]+)|\s*=\s*(?:"([^"]+)"|([^\s;]+)))/gi)) {
44
25
  if (match[1]) {
@@ -92,10 +73,10 @@ function normalizeHeaders(headers) {
92
73
  value = value.trim();
93
74
  break;
94
75
  default:
95
- if (!(0, types_1.isArray)(value)) {
76
+ if (!isArray(value)) {
96
77
  continue;
97
78
  }
98
- value = value.map(out => module_1.asString(out).trim());
79
+ value = value.map(out => Module.asString(out).trim());
99
80
  break;
100
81
  }
101
82
  if (value) {
@@ -105,10 +86,10 @@ function normalizeHeaders(headers) {
105
86
  return result;
106
87
  }
107
88
  function getBasicAuth(username, password) {
108
- if ((0, types_1.isObject)(username)) {
89
+ if (isObject(username)) {
109
90
  ({ username, password } = username);
110
91
  }
111
- return (0, types_1.isString)(username) ? encodeURIComponent((0, node_util_1.toUSVString)(username)) + ((0, types_1.isString)(password) ? ':' + encodeURIComponent((0, node_util_1.toUSVString)(password)) : '') + '@' : '';
92
+ return isString(username) ? encodeURIComponent(toUSVString(username)) + (isString(password) ? ':' + encodeURIComponent(toUSVString(password)) : '') + '@' : '';
112
93
  }
113
94
  function hasBasicAuth(value) {
114
95
  try {
@@ -119,7 +100,7 @@ function hasBasicAuth(value) {
119
100
  return false;
120
101
  }
121
102
  function checkRetryable(err) {
122
- if (err instanceof Error) {
103
+ if (isError(err)) {
123
104
  const { code, errno } = err;
124
105
  switch (code) {
125
106
  case 'ETIMEDOUT':
@@ -174,11 +155,11 @@ function parseHttpProxy(value, ignoreEnv) {
174
155
  exclude = ['**'];
175
156
  break;
176
157
  }
177
- if (module_1.isURL(item)) {
158
+ if (Module.isURL(item)) {
178
159
  exclude.push(item);
179
160
  }
180
161
  else {
181
- const negate = item.startsWith('!') ? (item = item.substring(1), '!') : '';
162
+ const negate = item.startsWith('!') ? (item = item.slice(1), '!') : '';
182
163
  if (!/^(?:[^.]+|(?:\d+\.){3}\d+)$/.test(item) && !item.includes('*')) {
183
164
  item = '*' + item;
184
165
  }
@@ -237,10 +218,10 @@ function fromSeconds(value) {
237
218
  }
238
219
  }
239
220
  function fromURL(url, value) {
240
- if (module_1.isURL(value)) {
221
+ if (Module.isURL(value)) {
241
222
  return value;
242
223
  }
243
- const auth = host_1.formatBasicAuth(url);
224
+ const auth = HttpHost.formatBasicAuth(url);
244
225
  return url.protocol + '//' + (auth && (auth + '@')) + url.hostname + (url.port ? ':' + url.port : '') + (value.startsWith('/') ? '' : '/') + value;
245
226
  }
246
227
  function fromStatusCode(value) {
@@ -435,7 +416,7 @@ function hasSameStat(src, dest, keepEmpty) {
435
416
  return false;
436
417
  }
437
418
  function byteLength(value, encoding) {
438
- return typeof value === 'string' && (path.isAbsolute(value) || module_1.isPath(value)) ? getSize(value) : Buffer.byteLength(value, encoding && (0, types_1.getEncoding)(encoding));
419
+ return typeof value === 'string' && (path.isAbsolute(value) || Module.isPath(value)) ? getSize(value) : Buffer.byteLength(value, encoding && getEncoding(encoding));
439
420
  }
440
421
  function cleanupStream(stream, uri) {
441
422
  try {
@@ -446,8 +427,29 @@ function cleanupStream(stream, uri) {
446
427
  }
447
428
  }
448
429
  catch (err) {
449
- if (!(0, types_1.isErrorCode)(err, 'ENOENT')) {
450
- module_1.writeFail(["Unable to delete file", path.basename(uri)], err, 32);
430
+ if (!isErrorCode(err, 'ENOENT')) {
431
+ Module.writeFail(["Unable to delete file", path.basename(uri)], err, 32);
451
432
  }
452
433
  }
453
434
  }
435
+
436
+ exports.asFloat = asFloat;
437
+ exports.asInt = asInt;
438
+ exports.byteLength = byteLength;
439
+ exports.checkRetryable = checkRetryable;
440
+ exports.cleanupStream = cleanupStream;
441
+ exports.fromSeconds = fromSeconds;
442
+ exports.fromStatusCode = fromStatusCode;
443
+ exports.fromURL = fromURL;
444
+ exports.getBasicAuth = getBasicAuth;
445
+ exports.getSize = getSize;
446
+ exports.getTransferRate = getTransferRate;
447
+ exports.hasBasicAuth = hasBasicAuth;
448
+ exports.hasSameStat = hasSameStat;
449
+ exports.hasSize = hasSize;
450
+ exports.isRetryable = isRetryable;
451
+ exports.normalizeHeaders = normalizeHeaders;
452
+ exports.parseHeader = parseHeader;
453
+ exports.parseHttpProxy = parseHttpProxy;
454
+ exports.parseOutgoingHeaders = parseOutgoingHeaders;
455
+ exports.trimPath = trimPath;