@e-mc/request 0.9.6 → 0.10.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.9.6",
3
+ "version": "0.10.0",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.9.6",
24
- "@e-mc/types": "0.9.6",
23
+ "@e-mc/module": "0.10.0",
24
+ "@e-mc/types": "0.10.0",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "picomatch": "^4.0.2",
package/util.js CHANGED
@@ -1,5 +1,20 @@
1
1
  "use strict";
2
- exports.cleanupStream = exports.byteLength = exports.hasSameStat = exports.getSize = exports.hasSize = exports.getTransferRate = exports.fromSeconds = exports.asFloat = exports.asInt = exports.trimPath = exports.isRetryable = exports.checkRetryable = exports.hasBasicAuth = exports.getBasicAuth = exports.normalizeHeaders = exports.parseHeader = void 0;
2
+ exports.parseHeader = parseHeader;
3
+ exports.normalizeHeaders = normalizeHeaders;
4
+ exports.getBasicAuth = getBasicAuth;
5
+ exports.hasBasicAuth = hasBasicAuth;
6
+ exports.checkRetryable = checkRetryable;
7
+ exports.isRetryable = isRetryable;
8
+ exports.trimPath = trimPath;
9
+ exports.asInt = asInt;
10
+ exports.asFloat = asFloat;
11
+ exports.fromSeconds = fromSeconds;
12
+ exports.getTransferRate = getTransferRate;
13
+ exports.hasSize = hasSize;
14
+ exports.getSize = getSize;
15
+ exports.hasSameStat = hasSameStat;
16
+ exports.byteLength = byteLength;
17
+ exports.cleanupStream = cleanupStream;
3
18
  const path = require("path");
4
19
  const fs = require("fs");
5
20
  const module_1 = require("@e-mc/module");
@@ -22,7 +37,6 @@ function parseHeader(headers, name) {
22
37
  }
23
38
  }
24
39
  }
25
- exports.parseHeader = parseHeader;
26
40
  function normalizeHeaders(headers) {
27
41
  const result = Object.create(null);
28
42
  for (const name in headers) {
@@ -47,14 +61,12 @@ function normalizeHeaders(headers) {
47
61
  }
48
62
  return result;
49
63
  }
50
- exports.normalizeHeaders = normalizeHeaders;
51
64
  function getBasicAuth(username, password) {
52
65
  if ((0, types_1.isObject)(username)) {
53
66
  ({ username, password } = username);
54
67
  }
55
68
  return (0, types_1.isString)(username) ? encodeURIComponent(username) + ((0, types_1.isString)(password) ? ':' + encodeURIComponent(password) : '') + '@' : '';
56
69
  }
57
- exports.getBasicAuth = getBasicAuth;
58
70
  function hasBasicAuth(value) {
59
71
  try {
60
72
  return new URL(value).username.length > 0;
@@ -63,7 +75,6 @@ function hasBasicAuth(value) {
63
75
  }
64
76
  return false;
65
77
  }
66
- exports.hasBasicAuth = hasBasicAuth;
67
78
  function checkRetryable(err) {
68
79
  if (err instanceof Error) {
69
80
  const { code, errno } = err;
@@ -84,7 +95,6 @@ function checkRetryable(err) {
84
95
  }
85
96
  return false;
86
97
  }
87
- exports.checkRetryable = checkRetryable;
88
98
  function isRetryable(value, timeout) {
89
99
  switch (value) {
90
100
  case 408:
@@ -107,12 +117,10 @@ function isRetryable(value, timeout) {
107
117
  return false;
108
118
  }
109
119
  }
110
- exports.isRetryable = isRetryable;
111
120
  function trimPath(value) {
112
121
  const length = value.length - 1;
113
122
  return value[length] === '/' ? value.substring(0, length) : value;
114
123
  }
115
- exports.trimPath = trimPath;
116
124
  function asInt(value) {
117
125
  switch (typeof value) {
118
126
  case 'string':
@@ -123,7 +131,6 @@ function asInt(value) {
123
131
  return NaN;
124
132
  }
125
133
  }
126
- exports.asInt = asInt;
127
134
  function asFloat(value) {
128
135
  switch (typeof value) {
129
136
  case 'string':
@@ -134,7 +141,6 @@ function asFloat(value) {
134
141
  return NaN;
135
142
  }
136
143
  }
137
- exports.asFloat = asFloat;
138
144
  function fromSeconds(value) {
139
145
  switch (typeof value) {
140
146
  case 'string':
@@ -145,7 +151,6 @@ function fromSeconds(value) {
145
151
  return NaN;
146
152
  }
147
153
  }
148
- exports.fromSeconds = fromSeconds;
149
154
  function getTransferRate(length, timeMs, unitSeparator = '') {
150
155
  const unit = (length * 8) / timeMs;
151
156
  if (unit < 1) {
@@ -156,7 +161,6 @@ function getTransferRate(length, timeMs, unitSeparator = '') {
156
161
  }
157
162
  return (unit / 1000).toPrecision(3) + unitSeparator + 'GiB/s';
158
163
  }
159
- exports.getTransferRate = getTransferRate;
160
164
  function hasSize(value, keepEmpty) {
161
165
  try {
162
166
  const statSrc = fs.statSync(value);
@@ -171,7 +175,6 @@ function hasSize(value, keepEmpty) {
171
175
  }
172
176
  return false;
173
177
  }
174
- exports.hasSize = hasSize;
175
178
  function getSize(value, diskUsed) {
176
179
  try {
177
180
  return (diskUsed ? fs.lstatSync(value) : fs.statSync(value)).size;
@@ -180,7 +183,6 @@ function getSize(value, diskUsed) {
180
183
  return 0;
181
184
  }
182
185
  }
183
- exports.getSize = getSize;
184
186
  function hasSameStat(src, dest, keepEmpty) {
185
187
  try {
186
188
  if (fs.existsSync(dest)) {
@@ -198,11 +200,9 @@ function hasSameStat(src, dest, keepEmpty) {
198
200
  }
199
201
  return false;
200
202
  }
201
- exports.hasSameStat = hasSameStat;
202
203
  function byteLength(value, encoding) {
203
204
  return typeof value === 'string' && (path.isAbsolute(value) || module_1.isPath(value)) ? getSize(value) : Buffer.byteLength(value, encoding && (0, types_1.getEncoding)(encoding));
204
205
  }
205
- exports.byteLength = byteLength;
206
206
  function cleanupStream(stream, uri) {
207
207
  try {
208
208
  stream.removeAllListeners();
@@ -217,4 +217,3 @@ function cleanupStream(stream, uri) {
217
217
  }
218
218
  }
219
219
  }
220
- exports.cleanupStream = cleanupStream;