@rg-dev/stdlib 1.0.5 → 1.0.7
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/lib/common-env.cjs +8 -0
- package/lib/common-env.d.cts +8 -1
- package/lib/common-env.d.ts +8 -1
- package/lib/common-env.js +8 -0
- package/lib/node-env.cjs +14 -0
- package/lib/node-env.d.cts +2 -1
- package/lib/node-env.d.ts +2 -1
- package/lib/node-env.js +14 -0
- package/package.json +1 -1
package/lib/common-env.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var common_env_exports = {};
|
|
21
21
|
__export(common_env_exports, {
|
|
22
22
|
Optional: () => Optional,
|
|
23
|
+
catchInline: () => catchInline,
|
|
23
24
|
doSafe: () => doSafe,
|
|
24
25
|
isNumber: () => isNumber,
|
|
25
26
|
isRunningOnServer: () => isRunningOnServer,
|
|
@@ -112,6 +113,13 @@ function promiseWithTimeout(promise, timeout, errMsg = "The promise timed out.")
|
|
|
112
113
|
() => clearTimeout(timeoutID)
|
|
113
114
|
);
|
|
114
115
|
}
|
|
116
|
+
async function catchInline(cb) {
|
|
117
|
+
try {
|
|
118
|
+
return { error: void 0, result: await cb };
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return { error: e, result: void 0 };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
115
123
|
function doSafe(safe, onError) {
|
|
116
124
|
var _a;
|
|
117
125
|
if (!safe)
|
package/lib/common-env.d.cts
CHANGED
|
@@ -21,8 +21,15 @@ declare class Optional<T> {
|
|
|
21
21
|
declare function sleep(ms: number): Promise<unknown>;
|
|
22
22
|
declare function isNumber(num: any): boolean;
|
|
23
23
|
declare function promiseWithTimeout<T>(promise: Promise<T>, timeout: number, errMsg?: string): Promise<T>;
|
|
24
|
+
declare function catchInline<T>(cb: Promise<T>): Promise<{
|
|
25
|
+
error: undefined;
|
|
26
|
+
result: T;
|
|
27
|
+
} | {
|
|
28
|
+
error: Error;
|
|
29
|
+
result: undefined;
|
|
30
|
+
}>;
|
|
24
31
|
declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Error) => void): void;
|
|
25
32
|
declare function isRunningOnServer(): boolean;
|
|
26
33
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
27
34
|
|
|
28
|
-
export { type AsyncReturnType, type MyFn, Optional, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
|
35
|
+
export { type AsyncReturnType, type MyFn, Optional, catchInline, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
package/lib/common-env.d.ts
CHANGED
|
@@ -21,8 +21,15 @@ declare class Optional<T> {
|
|
|
21
21
|
declare function sleep(ms: number): Promise<unknown>;
|
|
22
22
|
declare function isNumber(num: any): boolean;
|
|
23
23
|
declare function promiseWithTimeout<T>(promise: Promise<T>, timeout: number, errMsg?: string): Promise<T>;
|
|
24
|
+
declare function catchInline<T>(cb: Promise<T>): Promise<{
|
|
25
|
+
error: undefined;
|
|
26
|
+
result: T;
|
|
27
|
+
} | {
|
|
28
|
+
error: Error;
|
|
29
|
+
result: undefined;
|
|
30
|
+
}>;
|
|
24
31
|
declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Error) => void): void;
|
|
25
32
|
declare function isRunningOnServer(): boolean;
|
|
26
33
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
27
34
|
|
|
28
|
-
export { type AsyncReturnType, type MyFn, Optional, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
|
35
|
+
export { type AsyncReturnType, type MyFn, Optional, catchInline, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
package/lib/common-env.js
CHANGED
|
@@ -80,6 +80,13 @@ function promiseWithTimeout(promise, timeout, errMsg = "The promise timed out.")
|
|
|
80
80
|
() => clearTimeout(timeoutID)
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
|
+
async function catchInline(cb) {
|
|
84
|
+
try {
|
|
85
|
+
return { error: void 0, result: await cb };
|
|
86
|
+
} catch (e) {
|
|
87
|
+
return { error: e, result: void 0 };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
83
90
|
function doSafe(safe, onError) {
|
|
84
91
|
var _a;
|
|
85
92
|
if (!safe)
|
|
@@ -127,6 +134,7 @@ function isPromise(value) {
|
|
|
127
134
|
}
|
|
128
135
|
export {
|
|
129
136
|
Optional,
|
|
137
|
+
catchInline,
|
|
130
138
|
doSafe,
|
|
131
139
|
isNumber,
|
|
132
140
|
isRunningOnServer,
|
package/lib/node-env.cjs
CHANGED
|
@@ -190,6 +190,7 @@ __export(node_env_exports, {
|
|
|
190
190
|
checkCommandExistsOrThrow: () => checkCommandExistsOrThrow,
|
|
191
191
|
checkIfDirExistsOrThrow: () => checkIfDirExistsOrThrow,
|
|
192
192
|
checkIfFileExistsOrThrow: () => checkIfFileExistsOrThrow,
|
|
193
|
+
chmodPlusX: () => chmodPlusX,
|
|
193
194
|
createTempDir: () => createTempDir,
|
|
194
195
|
isWindows: () => isWindows,
|
|
195
196
|
throwIfDirNotEmpty: () => throwIfDirNotEmpty
|
|
@@ -202,6 +203,19 @@ var import_command_exists = __toESM(require_command_exists2(), 1);
|
|
|
202
203
|
function isWindows() {
|
|
203
204
|
return import_os.default.platform() === "win32";
|
|
204
205
|
}
|
|
206
|
+
function chmodPlusX(filePath) {
|
|
207
|
+
if (import_os.default.platform() === "win32") {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const resolvedPath = import_path.default.resolve(filePath);
|
|
212
|
+
const stats = fs.statSync(resolvedPath);
|
|
213
|
+
const newMode = stats.mode | 73;
|
|
214
|
+
fs.chmodSync(resolvedPath, newMode);
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.error(`Failed to chmod +x ${filePath}:`, String((e == null ? void 0 : e.message) || e));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
205
219
|
async function checkIfDirExistsOrThrow(path2) {
|
|
206
220
|
if (!path2)
|
|
207
221
|
throw "path is empty";
|
package/lib/node-env.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
declare function isWindows(): boolean;
|
|
2
|
+
declare function chmodPlusX(filePath: string): void;
|
|
2
3
|
declare function checkIfDirExistsOrThrow(path: string): Promise<void>;
|
|
3
4
|
declare function createTempDir(): string;
|
|
4
5
|
declare function throwIfDirNotEmpty(dir_path: string): Promise<void>;
|
|
5
6
|
declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
|
|
6
7
|
declare function checkIfFileExistsOrThrow(the_path: string): Promise<void>;
|
|
7
8
|
|
|
8
|
-
export { checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, createTempDir, isWindows, throwIfDirNotEmpty };
|
|
9
|
+
export { checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, isWindows, throwIfDirNotEmpty };
|
package/lib/node-env.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
declare function isWindows(): boolean;
|
|
2
|
+
declare function chmodPlusX(filePath: string): void;
|
|
2
3
|
declare function checkIfDirExistsOrThrow(path: string): Promise<void>;
|
|
3
4
|
declare function createTempDir(): string;
|
|
4
5
|
declare function throwIfDirNotEmpty(dir_path: string): Promise<void>;
|
|
5
6
|
declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
|
|
6
7
|
declare function checkIfFileExistsOrThrow(the_path: string): Promise<void>;
|
|
7
8
|
|
|
8
|
-
export { checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, createTempDir, isWindows, throwIfDirNotEmpty };
|
|
9
|
+
export { checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, isWindows, throwIfDirNotEmpty };
|
package/lib/node-env.js
CHANGED
|
@@ -194,6 +194,19 @@ import path from "path";
|
|
|
194
194
|
function isWindows() {
|
|
195
195
|
return os.platform() === "win32";
|
|
196
196
|
}
|
|
197
|
+
function chmodPlusX(filePath) {
|
|
198
|
+
if (os.platform() === "win32") {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const resolvedPath = path.resolve(filePath);
|
|
203
|
+
const stats = fs.statSync(resolvedPath);
|
|
204
|
+
const newMode = stats.mode | 73;
|
|
205
|
+
fs.chmodSync(resolvedPath, newMode);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
console.error(`Failed to chmod +x ${filePath}:`, String((e == null ? void 0 : e.message) || e));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
197
210
|
async function checkIfDirExistsOrThrow(path2) {
|
|
198
211
|
if (!path2)
|
|
199
212
|
throw "path is empty";
|
|
@@ -246,6 +259,7 @@ export {
|
|
|
246
259
|
checkCommandExistsOrThrow,
|
|
247
260
|
checkIfDirExistsOrThrow,
|
|
248
261
|
checkIfFileExistsOrThrow,
|
|
262
|
+
chmodPlusX,
|
|
249
263
|
createTempDir,
|
|
250
264
|
isWindows,
|
|
251
265
|
throwIfDirNotEmpty
|