@rg-dev/stdlib 1.0.40 → 1.0.42
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/browser-env.cjs +91 -0
- package/lib/browser-env.d.cts +6 -0
- package/lib/browser-env.d.ts +6 -0
- package/lib/browser-env.js +71 -0
- package/lib/common-env.cjs +5 -1
- package/lib/common-env.js +5 -1
- package/lib/node-env.cjs +5 -1
- package/lib/node-env.d.cts +3 -1
- package/lib/node-env.d.ts +3 -1
- package/lib/node-env.js +5 -1
- package/package.json +8 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/browser-env.ts
|
|
20
|
+
var browser_env_exports = {};
|
|
21
|
+
__export(browser_env_exports, {
|
|
22
|
+
copyToClipboard: () => copyToClipboard,
|
|
23
|
+
parseFormData: () => parseFormData
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(browser_env_exports);
|
|
26
|
+
function parseFormData(e) {
|
|
27
|
+
if (e instanceof FormData) {
|
|
28
|
+
return Object.fromEntries(e.entries());
|
|
29
|
+
}
|
|
30
|
+
if (e instanceof HTMLFormElement) {
|
|
31
|
+
const data2 = new FormData(e);
|
|
32
|
+
return Object.fromEntries(data2.entries());
|
|
33
|
+
}
|
|
34
|
+
const data = new FormData(e.target);
|
|
35
|
+
return Object.fromEntries(data.entries());
|
|
36
|
+
}
|
|
37
|
+
async function copyToClipboard(content, opts = { throwOnError: false }) {
|
|
38
|
+
let temp;
|
|
39
|
+
try {
|
|
40
|
+
if (Array.isArray(content)) {
|
|
41
|
+
if (!((temp = navigator == null ? void 0 : navigator.clipboard) == null ? void 0 : temp.write)) {
|
|
42
|
+
for (const c of content) {
|
|
43
|
+
if (typeof c === "string") fallback(c);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
await navigator.clipboard.write([
|
|
47
|
+
new ClipboardItem(
|
|
48
|
+
Object.fromEntries(
|
|
49
|
+
content.map(
|
|
50
|
+
(c) => {
|
|
51
|
+
return [(c == null ? void 0 : c.type) ?? "text/plain", c];
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
]);
|
|
57
|
+
return true;
|
|
58
|
+
} else if (content instanceof Blob) {
|
|
59
|
+
await navigator.clipboard.write([new ClipboardItem({ [content.type]: content })]);
|
|
60
|
+
return true;
|
|
61
|
+
} else {
|
|
62
|
+
try {
|
|
63
|
+
await navigator.clipboard.writeText(String(content));
|
|
64
|
+
return true;
|
|
65
|
+
} catch {
|
|
66
|
+
return fallback(content);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (opts.throwOnError) {
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function fallback(content) {
|
|
77
|
+
if (!document.execCommand) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const el = document.createElement("textarea");
|
|
81
|
+
el.value = String(content);
|
|
82
|
+
el.style.clipPath = "inset(50%)";
|
|
83
|
+
el.ariaHidden = "true";
|
|
84
|
+
document.body.append(el);
|
|
85
|
+
try {
|
|
86
|
+
el.select();
|
|
87
|
+
return document.execCommand("copy");
|
|
88
|
+
} finally {
|
|
89
|
+
el.remove();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/browser-env.ts
|
|
2
|
+
function parseFormData(e) {
|
|
3
|
+
if (e instanceof FormData) {
|
|
4
|
+
return Object.fromEntries(e.entries());
|
|
5
|
+
}
|
|
6
|
+
if (e instanceof HTMLFormElement) {
|
|
7
|
+
const data2 = new FormData(e);
|
|
8
|
+
return Object.fromEntries(data2.entries());
|
|
9
|
+
}
|
|
10
|
+
const data = new FormData(e.target);
|
|
11
|
+
return Object.fromEntries(data.entries());
|
|
12
|
+
}
|
|
13
|
+
async function copyToClipboard(content, opts = { throwOnError: false }) {
|
|
14
|
+
let temp;
|
|
15
|
+
try {
|
|
16
|
+
if (Array.isArray(content)) {
|
|
17
|
+
if (!((temp = navigator == null ? void 0 : navigator.clipboard) == null ? void 0 : temp.write)) {
|
|
18
|
+
for (const c of content) {
|
|
19
|
+
if (typeof c === "string") fallback(c);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
await navigator.clipboard.write([
|
|
23
|
+
new ClipboardItem(
|
|
24
|
+
Object.fromEntries(
|
|
25
|
+
content.map(
|
|
26
|
+
(c) => {
|
|
27
|
+
return [(c == null ? void 0 : c.type) ?? "text/plain", c];
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
]);
|
|
33
|
+
return true;
|
|
34
|
+
} else if (content instanceof Blob) {
|
|
35
|
+
await navigator.clipboard.write([new ClipboardItem({ [content.type]: content })]);
|
|
36
|
+
return true;
|
|
37
|
+
} else {
|
|
38
|
+
try {
|
|
39
|
+
await navigator.clipboard.writeText(String(content));
|
|
40
|
+
return true;
|
|
41
|
+
} catch {
|
|
42
|
+
return fallback(content);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (opts.throwOnError) {
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function fallback(content) {
|
|
53
|
+
if (!document.execCommand) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const el = document.createElement("textarea");
|
|
57
|
+
el.value = String(content);
|
|
58
|
+
el.style.clipPath = "inset(50%)";
|
|
59
|
+
el.ariaHidden = "true";
|
|
60
|
+
document.body.append(el);
|
|
61
|
+
try {
|
|
62
|
+
el.select();
|
|
63
|
+
return document.execCommand("copy");
|
|
64
|
+
} finally {
|
|
65
|
+
el.remove();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
copyToClipboard,
|
|
70
|
+
parseFormData
|
|
71
|
+
};
|
package/lib/common-env.cjs
CHANGED
|
@@ -215,7 +215,11 @@ function doSafe(safe, onError) {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
function isRunningOnServer() {
|
|
218
|
-
|
|
218
|
+
try {
|
|
219
|
+
return (globalThis == null ? void 0 : globalThis.process) !== void 0;
|
|
220
|
+
} catch (e) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
219
223
|
}
|
|
220
224
|
async function useServer(fn, onError) {
|
|
221
225
|
if (isRunningOnServer()) {
|
package/lib/common-env.js
CHANGED
|
@@ -177,7 +177,11 @@ function doSafe(safe, onError) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
function isRunningOnServer() {
|
|
180
|
-
|
|
180
|
+
try {
|
|
181
|
+
return (globalThis == null ? void 0 : globalThis.process) !== void 0;
|
|
182
|
+
} catch (e) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
181
185
|
}
|
|
182
186
|
async function useServer(fn, onError) {
|
|
183
187
|
if (isRunningOnServer()) {
|
package/lib/node-env.cjs
CHANGED
|
@@ -196,7 +196,8 @@ __export(node_env_exports, {
|
|
|
196
196
|
createTempDir: () => createTempDir,
|
|
197
197
|
createTempFilePath: () => createTempFilePath,
|
|
198
198
|
isWindows: () => isWindows,
|
|
199
|
-
throwIfDirNotEmpty: () => throwIfDirNotEmpty
|
|
199
|
+
throwIfDirNotEmpty: () => throwIfDirNotEmpty,
|
|
200
|
+
typedSystemArch: () => typedSystemArch
|
|
200
201
|
});
|
|
201
202
|
module.exports = __toCommonJS(node_env_exports);
|
|
202
203
|
var fs = __toESM(require("fs-extra"), 1);
|
|
@@ -327,6 +328,9 @@ var SSEClient = class extends import_events.EventEmitter {
|
|
|
327
328
|
function isWindows() {
|
|
328
329
|
return import_os.default.platform() === "win32";
|
|
329
330
|
}
|
|
331
|
+
function typedSystemArch() {
|
|
332
|
+
return import_os.default.arch();
|
|
333
|
+
}
|
|
330
334
|
function chmodPlusX(filePath) {
|
|
331
335
|
if (import_os.default.platform() === "win32") {
|
|
332
336
|
return;
|
package/lib/node-env.d.cts
CHANGED
|
@@ -28,6 +28,8 @@ declare class SSEClient extends EventEmitter {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
declare function isWindows(): boolean;
|
|
31
|
+
type SystemArch = "x64" | "arm64" | "arm" | "ia32" | "ppc64" | "s390x" | "loong64" | "riscv64";
|
|
32
|
+
declare function typedSystemArch(): SystemArch;
|
|
31
33
|
declare function chmodPlusX(filePath: string): void;
|
|
32
34
|
declare function checkIfDirExistsOrThrow(path: string): Promise<void>;
|
|
33
35
|
declare function createTempDir(): string;
|
|
@@ -39,4 +41,4 @@ declare function throwIfDirNotEmpty(dirPath: string): Promise<void>;
|
|
|
39
41
|
declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
|
|
40
42
|
declare function checkIfFileExistsOrThrow(thePath: string): Promise<void>;
|
|
41
43
|
|
|
42
|
-
export { SSEClient, SSEResponse, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty };
|
|
44
|
+
export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty, typedSystemArch };
|
package/lib/node-env.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ declare class SSEClient extends EventEmitter {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
declare function isWindows(): boolean;
|
|
31
|
+
type SystemArch = "x64" | "arm64" | "arm" | "ia32" | "ppc64" | "s390x" | "loong64" | "riscv64";
|
|
32
|
+
declare function typedSystemArch(): SystemArch;
|
|
31
33
|
declare function chmodPlusX(filePath: string): void;
|
|
32
34
|
declare function checkIfDirExistsOrThrow(path: string): Promise<void>;
|
|
33
35
|
declare function createTempDir(): string;
|
|
@@ -39,4 +41,4 @@ declare function throwIfDirNotEmpty(dirPath: string): Promise<void>;
|
|
|
39
41
|
declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
|
|
40
42
|
declare function checkIfFileExistsOrThrow(thePath: string): Promise<void>;
|
|
41
43
|
|
|
42
|
-
export { SSEClient, SSEResponse, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty };
|
|
44
|
+
export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty, typedSystemArch };
|
package/lib/node-env.js
CHANGED
|
@@ -314,6 +314,9 @@ var SSEClient = class extends EventEmitter {
|
|
|
314
314
|
function isWindows() {
|
|
315
315
|
return os.platform() === "win32";
|
|
316
316
|
}
|
|
317
|
+
function typedSystemArch() {
|
|
318
|
+
return os.arch();
|
|
319
|
+
}
|
|
317
320
|
function chmodPlusX(filePath) {
|
|
318
321
|
if (os.platform() === "win32") {
|
|
319
322
|
return;
|
|
@@ -409,5 +412,6 @@ export {
|
|
|
409
412
|
createTempDir,
|
|
410
413
|
createTempFilePath,
|
|
411
414
|
isWindows,
|
|
412
|
-
throwIfDirNotEmpty
|
|
415
|
+
throwIfDirNotEmpty,
|
|
416
|
+
typedSystemArch
|
|
413
417
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rg-dev/stdlib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"*": {
|
|
16
16
|
"lib/common-env": [
|
|
17
17
|
"lib/common-env.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"lib/browser-env": [
|
|
20
|
+
"lib/browser-env.d.ts"
|
|
18
21
|
],
|
|
19
22
|
"lib/node-env": [
|
|
20
23
|
"lib/node-env.d.ts"
|
|
@@ -33,6 +36,10 @@
|
|
|
33
36
|
"require": "./lib/node-env.cjs",
|
|
34
37
|
"types": "./lib/node-env.d.ts"
|
|
35
38
|
},
|
|
39
|
+
"./lib/browser-env": {
|
|
40
|
+
"import": "./lib/browser-env.js",
|
|
41
|
+
"types": "./lib/browser-env.d.ts"
|
|
42
|
+
},
|
|
36
43
|
"./lib/common-env": {
|
|
37
44
|
"import": "./lib/common-env.js",
|
|
38
45
|
"require": "./lib/common-env.cjs",
|