Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@rg-dev/stdlib

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rg-dev/stdlib - npm Package Compare versions

Comparing version
1.0.40
to
1.0.41
+91
lib/browser-env.cjs
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
};
+5
-1

@@ -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) {

{
"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",