@jeniex/utils 1.0.18 → 1.0.20
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/browser/index.cjs +4 -3
- package/browser/index.d.ts +4 -1
- package/browser/index.js +4 -3
- package/node/index.d.ts +4 -1
- package/package.json +1 -1
package/browser/index.cjs
CHANGED
|
@@ -111,7 +111,7 @@ function prompt(message, _default) {
|
|
|
111
111
|
|
|
112
112
|
async function fishResponse(url, options) {
|
|
113
113
|
const response = await fetch(url, options);
|
|
114
|
-
if (!response.ok) {
|
|
114
|
+
if (!response.ok && !response.url.startsWith('file:///')) {
|
|
115
115
|
throw new Error(`Request to ${response.url} ended with ${response.status} status.`);
|
|
116
116
|
}
|
|
117
117
|
return response;
|
|
@@ -131,14 +131,15 @@ async function fishXResponse(url, fishOptions) {
|
|
|
131
131
|
timeout: timeOut,
|
|
132
132
|
onprogress: onProgress,
|
|
133
133
|
onload({ response, statusText, status, finalUrl }) {
|
|
134
|
+
const isFileURL = finalUrl.startsWith('file:///');
|
|
134
135
|
const ok = status >= 200 && status < 300;
|
|
135
|
-
if (!ok) {
|
|
136
|
+
if (!ok && !isFileURL) {
|
|
136
137
|
reject(new Error(`Request to ${url} ended with ${status} status.`));
|
|
137
138
|
return;
|
|
138
139
|
}
|
|
139
140
|
const properResponse = new Response(response, {
|
|
140
141
|
statusText,
|
|
141
|
-
status,
|
|
142
|
+
status: isFileURL ? 200 : status,
|
|
142
143
|
});
|
|
143
144
|
Object.defineProperty(properResponse, 'url', { value: finalUrl });
|
|
144
145
|
resolve(properResponse);
|
package/browser/index.d.ts
CHANGED
|
@@ -37,6 +37,9 @@ declare function sleep(milliSeconds: number): Promise<void>;
|
|
|
37
37
|
|
|
38
38
|
type Nullable<T> = T | null | undefined;
|
|
39
39
|
type Fn<T = void, U = any> = (param?: U) => T;
|
|
40
|
+
type Prettify<T> = {
|
|
41
|
+
[KeyType in keyof T]: T[KeyType];
|
|
42
|
+
} & {};
|
|
40
43
|
|
|
41
44
|
declare function alert(message?: string): void;
|
|
42
45
|
declare function confirm(message: string): boolean;
|
|
@@ -129,4 +132,4 @@ type Options = Record<string, FlagValue>;
|
|
|
129
132
|
|
|
130
133
|
declare function getOptions(flags: Flag[]): Promise<Options>;
|
|
131
134
|
|
|
132
|
-
export { $, $$, Flag, Fn, Nullable, addStyle, alert, asserted, confirm, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, logId, noop, pageLoad, prompt, remove, scriptName, setSearchParam, sleep, tabURL, toString };
|
|
135
|
+
export { $, $$, Flag, Fn, Nullable, Prettify, addStyle, alert, asserted, confirm, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, logId, noop, pageLoad, prompt, remove, scriptName, setSearchParam, sleep, tabURL, toString };
|
package/browser/index.js
CHANGED
|
@@ -109,7 +109,7 @@ function prompt(message, _default) {
|
|
|
109
109
|
|
|
110
110
|
async function fishResponse(url, options) {
|
|
111
111
|
const response = await fetch(url, options);
|
|
112
|
-
if (!response.ok) {
|
|
112
|
+
if (!response.ok && !response.url.startsWith('file:///')) {
|
|
113
113
|
throw new Error(`Request to ${response.url} ended with ${response.status} status.`);
|
|
114
114
|
}
|
|
115
115
|
return response;
|
|
@@ -129,14 +129,15 @@ async function fishXResponse(url, fishOptions) {
|
|
|
129
129
|
timeout: timeOut,
|
|
130
130
|
onprogress: onProgress,
|
|
131
131
|
onload({ response, statusText, status, finalUrl }) {
|
|
132
|
+
const isFileURL = finalUrl.startsWith('file:///');
|
|
132
133
|
const ok = status >= 200 && status < 300;
|
|
133
|
-
if (!ok) {
|
|
134
|
+
if (!ok && !isFileURL) {
|
|
134
135
|
reject(new Error(`Request to ${url} ended with ${status} status.`));
|
|
135
136
|
return;
|
|
136
137
|
}
|
|
137
138
|
const properResponse = new Response(response, {
|
|
138
139
|
statusText,
|
|
139
|
-
status,
|
|
140
|
+
status: isFileURL ? 200 : status,
|
|
140
141
|
});
|
|
141
142
|
Object.defineProperty(properResponse, 'url', { value: finalUrl });
|
|
142
143
|
resolve(properResponse);
|
package/node/index.d.ts
CHANGED
|
@@ -37,6 +37,9 @@ declare function sleep(milliSeconds: number): Promise<void>;
|
|
|
37
37
|
|
|
38
38
|
type Nullable<T> = T | null | undefined;
|
|
39
39
|
type Fn<T = void, U = any> = (param?: U) => T;
|
|
40
|
+
type Prettify<T> = {
|
|
41
|
+
[KeyType in keyof T]: T[KeyType];
|
|
42
|
+
} & {};
|
|
40
43
|
|
|
41
44
|
interface ListBaseOpt {
|
|
42
45
|
/** The absolute path of the target folder. */
|
|
@@ -92,4 +95,4 @@ declare function removeFiles({ folderPath, filter }: RemoveFilesOpt): Promise<vo
|
|
|
92
95
|
|
|
93
96
|
declare function readJSON<T = object>(filePath: string, withComments?: boolean): Promise<T>;
|
|
94
97
|
|
|
95
|
-
export { Fn, Nullable, asserted, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, readJSON, remove, removeFiles, sleep, toString };
|
|
98
|
+
export { Fn, Nullable, Prettify, asserted, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, readJSON, remove, removeFiles, sleep, toString };
|