@symbo.ls/utils
Advanced tools
Comparing version 2.11.421 to 2.11.429
@@ -345,6 +345,6 @@ "use strict"; | ||
var mergeArray = (arr, excludeFrom = []) => { | ||
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, excludeFrom), excludeFrom), {}); | ||
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepCloneWithExtend)(c, excludeFrom), excludeFrom), {}); | ||
}; | ||
var mergeAndCloneIfArray = (obj) => { | ||
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepClone)(obj); | ||
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepCloneWithExtend)(obj); | ||
}; | ||
@@ -455,2 +455,4 @@ var cutArrayBeforeValue = (arr, value) => { | ||
customEncodeURIComponent: () => customEncodeURIComponent, | ||
decodeNewlines: () => decodeNewlines, | ||
encodeNewlines: () => encodeNewlines, | ||
findKeyPosition: () => findKeyPosition, | ||
@@ -559,2 +561,8 @@ lowercaseFirstLetter: () => lowercaseFirstLetter, | ||
}; | ||
var encodeNewlines = (str) => { | ||
return str.split("\n").join("/////n").split("`").join("/////tilde").split("$").join("/////dlrsgn"); | ||
}; | ||
var decodeNewlines = (encodedStr) => { | ||
return encodedStr.split("/////n").join("\n").split("/////tilde").join("`").split("/////dlrsgn").join("$"); | ||
}; | ||
var customEncodeURIComponent = (str) => { | ||
@@ -992,3 +1000,3 @@ return str.split("").map((char) => { | ||
for (const e in params) { | ||
if (e === "__proto__") | ||
if (e === "__ref") | ||
continue; | ||
@@ -995,0 +1003,0 @@ if (excludeFrom.includes(e) || e.startsWith("__")) |
@@ -345,6 +345,6 @@ "use strict"; | ||
var mergeArray = (arr, excludeFrom = []) => { | ||
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, excludeFrom), excludeFrom), {}); | ||
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepCloneWithExtend)(c, excludeFrom), excludeFrom), {}); | ||
}; | ||
var mergeAndCloneIfArray = (obj) => { | ||
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepClone)(obj); | ||
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepCloneWithExtend)(obj); | ||
}; | ||
@@ -455,2 +455,4 @@ var cutArrayBeforeValue = (arr, value) => { | ||
customEncodeURIComponent: () => customEncodeURIComponent, | ||
decodeNewlines: () => decodeNewlines, | ||
encodeNewlines: () => encodeNewlines, | ||
findKeyPosition: () => findKeyPosition, | ||
@@ -559,2 +561,8 @@ lowercaseFirstLetter: () => lowercaseFirstLetter, | ||
}; | ||
var encodeNewlines = (str) => { | ||
return str.split("\n").join("/////n").split("`").join("/////tilde").split("$").join("/////dlrsgn"); | ||
}; | ||
var decodeNewlines = (encodedStr) => { | ||
return encodedStr.split("/////n").join("\n").split("/////tilde").join("`").split("/////dlrsgn").join("$"); | ||
}; | ||
var customEncodeURIComponent = (str) => { | ||
@@ -992,3 +1000,3 @@ return str.split("").map((char) => { | ||
for (const e in params) { | ||
if (e === "__proto__") | ||
if (e === "__ref") | ||
continue; | ||
@@ -1529,2 +1537,3 @@ if (excludeFrom.includes(e) || e.startsWith("__")) | ||
arrayzeValue: () => arrayzeValue, | ||
copyJavaScriptToClipboard: () => copyJavaScriptToClipboard, | ||
copyStringToClipboard: () => copyStringToClipboard, | ||
@@ -1671,12 +1680,19 @@ fibonacciNumberByIndex: () => fibonacciNumberByIndex, | ||
// src/index.js | ||
var copyStringToClipboard = (str) => { | ||
const el = document.createElement("textarea"); | ||
el.value = str; | ||
el.setAttribute("readonly", ""); | ||
el.style = { position: "absolute", left: "-9999px" }; | ||
document.body.appendChild(el); | ||
el.select(); | ||
document.execCommand("copy"); | ||
document.body.removeChild(el); | ||
var copyStringToClipboard = async (str) => { | ||
try { | ||
await navigator.clipboard.writeText(str); | ||
} catch (err) { | ||
console.warn("Failed to copy text: ", err); | ||
} | ||
}; | ||
var copyJavaScriptToClipboard = async (jsCode) => { | ||
try { | ||
const blob = new Blob([jsCode], { type: "text/javascript" }); | ||
const clipboardItem = new window.ClipboardItem({ "text/plain": blob }); | ||
await navigator.clipboard.write([clipboardItem]); | ||
console.log("JavaScript code copied to clipboard as text/javascript"); | ||
} catch (err) { | ||
console.error("Failed to copy JavaScript code: ", err); | ||
} | ||
}; | ||
var removeChars = (str) => { | ||
@@ -1683,0 +1699,0 @@ return str.replace(/[^a-zA-Z0-9_]/g, ""); |
@@ -345,6 +345,6 @@ "use strict"; | ||
var mergeArray = (arr, excludeFrom = []) => { | ||
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, excludeFrom), excludeFrom), {}); | ||
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepCloneWithExtend)(c, excludeFrom), excludeFrom), {}); | ||
}; | ||
var mergeAndCloneIfArray = (obj) => { | ||
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepClone)(obj); | ||
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepCloneWithExtend)(obj); | ||
}; | ||
@@ -455,2 +455,4 @@ var cutArrayBeforeValue = (arr, value) => { | ||
customEncodeURIComponent: () => customEncodeURIComponent, | ||
decodeNewlines: () => decodeNewlines, | ||
encodeNewlines: () => encodeNewlines, | ||
findKeyPosition: () => findKeyPosition, | ||
@@ -559,2 +561,8 @@ lowercaseFirstLetter: () => lowercaseFirstLetter, | ||
}; | ||
var encodeNewlines = (str) => { | ||
return str.split("\n").join("/////n").split("`").join("/////tilde").split("$").join("/////dlrsgn"); | ||
}; | ||
var decodeNewlines = (encodedStr) => { | ||
return encodedStr.split("/////n").join("\n").split("/////tilde").join("`").split("/////dlrsgn").join("$"); | ||
}; | ||
var customEncodeURIComponent = (str) => { | ||
@@ -992,3 +1000,3 @@ return str.split("").map((char) => { | ||
for (const e in params) { | ||
if (e === "__proto__") | ||
if (e === "__ref") | ||
continue; | ||
@@ -995,0 +1003,0 @@ if (excludeFrom.includes(e) || e.startsWith("__")) |
{ | ||
"name": "@symbo.ls/utils", | ||
"version": "2.11.421", | ||
"version": "2.11.429", | ||
"author": "symbo.ls", | ||
@@ -29,3 +29,3 @@ "files": [ | ||
}, | ||
"gitHead": "c8c0374c888db13ddd96d6602f441ab80f13c203" | ||
"gitHead": "ff81d19b0ad978bbba24590f269a7bdbb6799798" | ||
} |
@@ -12,13 +12,27 @@ 'use strict' | ||
export const copyStringToClipboard = str => { | ||
const el = document.createElement('textarea') | ||
el.value = str | ||
el.setAttribute('readonly', '') | ||
el.style = { position: 'absolute', left: '-9999px' } | ||
document.body.appendChild(el) | ||
el.select() | ||
document.execCommand('copy') | ||
document.body.removeChild(el) | ||
export const copyStringToClipboard = async (str) => { | ||
try { | ||
await navigator.clipboard.writeText(str) | ||
} catch (err) { | ||
console.warn('Failed to copy text: ', err) | ||
} | ||
} | ||
export const copyJavaScriptToClipboard = async (jsCode) => { | ||
try { | ||
// Create a Blob for the JavaScript code with the 'text/javascript' MIME type | ||
const blob = new Blob([jsCode], { type: 'text/javascript' }) | ||
// Create a ClipboardItem with the 'text/javascript' Blob | ||
const clipboardItem = new window.ClipboardItem({ 'text/plain': blob }) | ||
// Copy the ClipboardItem to the clipboard | ||
await navigator.clipboard.write([clipboardItem]) | ||
console.log('JavaScript code copied to clipboard as text/javascript') | ||
} catch (err) { | ||
console.error('Failed to copy JavaScript code: ', err) | ||
} | ||
} | ||
export const removeChars = str => { | ||
@@ -25,0 +39,0 @@ return str.replace(/[^a-zA-Z0-9_]/g, '') |
196436
5284