@rg-dev/stdlib 1.0.39 → 1.0.41
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 +6 -2
- package/lib/node-env.js +6 -2
- 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
|
@@ -360,8 +360,12 @@ function createTempDir() {
|
|
|
360
360
|
return tempDirPath;
|
|
361
361
|
}
|
|
362
362
|
function createTempFilePath(ext) {
|
|
363
|
-
if (ext
|
|
364
|
-
|
|
363
|
+
if (typeof ext == "string") {
|
|
364
|
+
if (ext.startsWith(".")) {
|
|
365
|
+
ext = ext.slice(1);
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
ext = void 0;
|
|
365
369
|
}
|
|
366
370
|
const name = `temp_file_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2)}${ext ? `.${ext}` : ""}`;
|
|
367
371
|
const fullPath = import_path.default.join(import_os.default.tmpdir(), name);
|
package/lib/node-env.js
CHANGED
|
@@ -347,8 +347,12 @@ function createTempDir() {
|
|
|
347
347
|
return tempDirPath;
|
|
348
348
|
}
|
|
349
349
|
function createTempFilePath(ext) {
|
|
350
|
-
if (ext
|
|
351
|
-
|
|
350
|
+
if (typeof ext == "string") {
|
|
351
|
+
if (ext.startsWith(".")) {
|
|
352
|
+
ext = ext.slice(1);
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
ext = void 0;
|
|
352
356
|
}
|
|
353
357
|
const name = `temp_file_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2)}${ext ? `.${ext}` : ""}`;
|
|
354
358
|
const fullPath = path.join(os.tmpdir(), name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rg-dev/stdlib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.41",
|
|
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",
|