@rg-dev/stdlib
Advanced tools
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/browser-env.ts | ||
| var browser_env_exports = {}; | ||
| __export(browser_env_exports, { | ||
| copyToClipboard: () => copyToClipboard, | ||
| parseFormData: () => parseFormData | ||
| }); | ||
| module.exports = __toCommonJS(browser_env_exports); | ||
| function parseFormData(e) { | ||
| if (e instanceof FormData) { | ||
| return Object.fromEntries(e.entries()); | ||
| } | ||
| if (e instanceof HTMLFormElement) { | ||
| const data2 = new FormData(e); | ||
| return Object.fromEntries(data2.entries()); | ||
| } | ||
| const data = new FormData(e.target); | ||
| return Object.fromEntries(data.entries()); | ||
| } | ||
| async function copyToClipboard(content, opts = { throwOnError: false }) { | ||
| let temp; | ||
| try { | ||
| if (Array.isArray(content)) { | ||
| if (!((temp = navigator == null ? void 0 : navigator.clipboard) == null ? void 0 : temp.write)) { | ||
| for (const c of content) { | ||
| if (typeof c === "string") fallback(c); | ||
| } | ||
| } | ||
| await navigator.clipboard.write([ | ||
| new ClipboardItem( | ||
| Object.fromEntries( | ||
| content.map( | ||
| (c) => { | ||
| return [(c == null ? void 0 : c.type) ?? "text/plain", c]; | ||
| } | ||
| ) | ||
| ) | ||
| ) | ||
| ]); | ||
| return true; | ||
| } else if (content instanceof Blob) { | ||
| await navigator.clipboard.write([new ClipboardItem({ [content.type]: content })]); | ||
| return true; | ||
| } else { | ||
| try { | ||
| await navigator.clipboard.writeText(String(content)); | ||
| return true; | ||
| } catch { | ||
| return fallback(content); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| if (opts.throwOnError) { | ||
| throw err; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| function fallback(content) { | ||
| if (!document.execCommand) { | ||
| return false; | ||
| } | ||
| const el = document.createElement("textarea"); | ||
| el.value = String(content); | ||
| el.style.clipPath = "inset(50%)"; | ||
| el.ariaHidden = "true"; | ||
| document.body.append(el); | ||
| try { | ||
| el.select(); | ||
| return document.execCommand("copy"); | ||
| } finally { | ||
| el.remove(); | ||
| } | ||
| } |
| declare function parseFormData<T = Record<string, string>>(e: Event | FormData | HTMLFormElement): T; | ||
| declare function copyToClipboard(content: any, opts?: { | ||
| throwOnError: boolean; | ||
| }): Promise<boolean>; | ||
| export { copyToClipboard, parseFormData }; |
| declare function parseFormData<T = Record<string, string>>(e: Event | FormData | HTMLFormElement): T; | ||
| declare function copyToClipboard(content: any, opts?: { | ||
| throwOnError: boolean; | ||
| }): Promise<boolean>; | ||
| export { copyToClipboard, parseFormData }; |
| // src/browser-env.ts | ||
| function parseFormData(e) { | ||
| if (e instanceof FormData) { | ||
| return Object.fromEntries(e.entries()); | ||
| } | ||
| if (e instanceof HTMLFormElement) { | ||
| const data2 = new FormData(e); | ||
| return Object.fromEntries(data2.entries()); | ||
| } | ||
| const data = new FormData(e.target); | ||
| return Object.fromEntries(data.entries()); | ||
| } | ||
| async function copyToClipboard(content, opts = { throwOnError: false }) { | ||
| let temp; | ||
| try { | ||
| if (Array.isArray(content)) { | ||
| if (!((temp = navigator == null ? void 0 : navigator.clipboard) == null ? void 0 : temp.write)) { | ||
| for (const c of content) { | ||
| if (typeof c === "string") fallback(c); | ||
| } | ||
| } | ||
| await navigator.clipboard.write([ | ||
| new ClipboardItem( | ||
| Object.fromEntries( | ||
| content.map( | ||
| (c) => { | ||
| return [(c == null ? void 0 : c.type) ?? "text/plain", c]; | ||
| } | ||
| ) | ||
| ) | ||
| ) | ||
| ]); | ||
| return true; | ||
| } else if (content instanceof Blob) { | ||
| await navigator.clipboard.write([new ClipboardItem({ [content.type]: content })]); | ||
| return true; | ||
| } else { | ||
| try { | ||
| await navigator.clipboard.writeText(String(content)); | ||
| return true; | ||
| } catch { | ||
| return fallback(content); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| if (opts.throwOnError) { | ||
| throw err; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| function fallback(content) { | ||
| if (!document.execCommand) { | ||
| return false; | ||
| } | ||
| const el = document.createElement("textarea"); | ||
| el.value = String(content); | ||
| el.style.clipPath = "inset(50%)"; | ||
| el.ariaHidden = "true"; | ||
| document.body.append(el); | ||
| try { | ||
| el.select(); | ||
| return document.execCommand("copy"); | ||
| } finally { | ||
| el.remove(); | ||
| } | ||
| } | ||
| export { | ||
| copyToClipboard, | ||
| parseFormData | ||
| }; |
@@ -218,3 +218,7 @@ var __defProp = Object.defineProperty; | ||
| function isRunningOnServer() { | ||
| return (globalThis == null ? void 0 : globalThis.process) !== void 0; | ||
| try { | ||
| return (globalThis == null ? void 0 : globalThis.process) !== void 0; | ||
| } catch (e) { | ||
| return false; | ||
| } | ||
| } | ||
@@ -221,0 +225,0 @@ async function useServer(fn, onError) { |
@@ -180,3 +180,7 @@ // src/promise-retry.ts | ||
| function isRunningOnServer() { | ||
| return (globalThis == null ? void 0 : globalThis.process) !== void 0; | ||
| try { | ||
| return (globalThis == null ? void 0 : globalThis.process) !== void 0; | ||
| } catch (e) { | ||
| return false; | ||
| } | ||
| } | ||
@@ -183,0 +187,0 @@ async function useServer(fn, onError) { |
+8
-1
| { | ||
| "name": "@rg-dev/stdlib", | ||
| "version": "1.0.40", | ||
| "version": "1.0.41", | ||
| "description": "", | ||
@@ -19,2 +19,5 @@ "scripts": { | ||
| ], | ||
| "lib/browser-env": [ | ||
| "lib/browser-env.d.ts" | ||
| ], | ||
| "lib/node-env": [ | ||
@@ -37,2 +40,6 @@ "lib/node-env.d.ts" | ||
| }, | ||
| "./lib/browser-env": { | ||
| "import": "./lib/browser-env.js", | ||
| "types": "./lib/browser-env.d.ts" | ||
| }, | ||
| "./lib/common-env": { | ||
@@ -39,0 +46,0 @@ "import": "./lib/common-env.js", |
Network access
Supply chain riskThis module accesses the network.
Found 4 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 4 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
547008
0.98%21
23.53%13740
1.28%