@symbo.ls/utils
Advanced tools
Comparing version 2.11.375 to 2.11.394
@@ -296,2 +296,3 @@ "use strict"; | ||
__export2(array_exports, { | ||
addItemAfterEveryElement: () => addItemAfterEveryElement, | ||
arrayContainsOtherArray: () => arrayContainsOtherArray, | ||
@@ -308,2 +309,3 @@ createNestedObject: () => createNestedObject, | ||
removeValueFromArrayAll: () => removeValueFromArrayAll, | ||
reorderArrayByValues: () => reorderArrayByValues, | ||
swapItemsInArray: () => swapItemsInArray | ||
@@ -393,2 +395,23 @@ }); | ||
}; | ||
var addItemAfterEveryElement = (array, item) => { | ||
const result = []; | ||
for (let i = 0; i < array.length; i++) { | ||
result.push(array[i]); | ||
if (i < array.length - 1) { | ||
result.push(item); | ||
} | ||
} | ||
return result; | ||
}; | ||
var reorderArrayByValues = (array, valueToMove, insertBeforeValue) => { | ||
const newArray = [...array]; | ||
const indexToMove = newArray.indexOf(valueToMove); | ||
const indexToInsertBefore = newArray.indexOf(insertBeforeValue); | ||
if (indexToMove !== -1 && indexToInsertBefore !== -1) { | ||
const removedItem = newArray.splice(indexToMove, 1)[0]; | ||
const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1; | ||
newArray.splice(insertIndex, 0, removedItem); | ||
} | ||
return newArray; | ||
}; | ||
} | ||
@@ -670,3 +693,3 @@ }); | ||
}; | ||
var objectToString = (obj, indent = 0) => { | ||
var objectToString = (obj = {}, indent = 0) => { | ||
const spaces = " ".repeat(indent); | ||
@@ -738,3 +761,3 @@ let str = "{\n"; | ||
if ((0, import_types.isString)(objProp)) { | ||
if ((objProp.includes("=>") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) { | ||
if ((objProp.includes("(){") || objProp.includes("() {") || objProp.includes("=>") || objProp.startsWith("()") || objProp.startsWith("async") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) { | ||
try { | ||
@@ -1127,5 +1150,6 @@ const evalProp = import_globals.window.eval(`(${objProp})`); | ||
var import_types = require_types(); | ||
var import_utils3 = require_cjs(); | ||
var isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))(); | ||
var setCookie = (cname, cvalue, exdays = 365) => { | ||
if ((0, import_types.isUndefined)(document) || (0, import_types.isUndefined)(document.cookie)) | ||
if ((0, import_types.isUndefined)(import_utils3.document) || (0, import_types.isUndefined)(import_utils3.document.cookie)) | ||
return; | ||
@@ -1135,9 +1159,9 @@ const d = /* @__PURE__ */ new Date(); | ||
const expires = `expires=${d.toUTCString()}`; | ||
document.cookie = `${cname}=${cvalue};${expires};path=/`; | ||
import_utils3.document.cookie = `${cname}=${cvalue};${expires};path=/`; | ||
}; | ||
var getCookie = (cname) => { | ||
if ((0, import_types.isUndefined)(document) || (0, import_types.isUndefined)(document.cookie)) | ||
if ((0, import_types.isUndefined)(import_utils3.document) || (0, import_types.isUndefined)(import_utils3.document.cookie)) | ||
return; | ||
const name = `${cname}=`; | ||
const decodedCookie = decodeURIComponent(document.cookie); | ||
const decodedCookie = decodeURIComponent(import_utils3.document.cookie); | ||
const ca = decodedCookie.split(";"); | ||
@@ -1144,0 +1168,0 @@ for (let i = 0; i < ca.length; i++) { |
@@ -296,2 +296,3 @@ "use strict"; | ||
__export2(array_exports, { | ||
addItemAfterEveryElement: () => addItemAfterEveryElement, | ||
arrayContainsOtherArray: () => arrayContainsOtherArray, | ||
@@ -308,2 +309,3 @@ createNestedObject: () => createNestedObject, | ||
removeValueFromArrayAll: () => removeValueFromArrayAll, | ||
reorderArrayByValues: () => reorderArrayByValues, | ||
swapItemsInArray: () => swapItemsInArray | ||
@@ -393,2 +395,23 @@ }); | ||
}; | ||
var addItemAfterEveryElement = (array, item) => { | ||
const result = []; | ||
for (let i = 0; i < array.length; i++) { | ||
result.push(array[i]); | ||
if (i < array.length - 1) { | ||
result.push(item); | ||
} | ||
} | ||
return result; | ||
}; | ||
var reorderArrayByValues = (array, valueToMove, insertBeforeValue) => { | ||
const newArray = [...array]; | ||
const indexToMove = newArray.indexOf(valueToMove); | ||
const indexToInsertBefore = newArray.indexOf(insertBeforeValue); | ||
if (indexToMove !== -1 && indexToInsertBefore !== -1) { | ||
const removedItem = newArray.splice(indexToMove, 1)[0]; | ||
const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1; | ||
newArray.splice(insertIndex, 0, removedItem); | ||
} | ||
return newArray; | ||
}; | ||
} | ||
@@ -670,3 +693,3 @@ }); | ||
}; | ||
var objectToString = (obj, indent = 0) => { | ||
var objectToString = (obj = {}, indent = 0) => { | ||
const spaces = " ".repeat(indent); | ||
@@ -738,3 +761,3 @@ let str = "{\n"; | ||
if ((0, import_types.isString)(objProp)) { | ||
if ((objProp.includes("=>") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) { | ||
if ((objProp.includes("(){") || objProp.includes("() {") || objProp.includes("=>") || objProp.startsWith("()") || objProp.startsWith("async") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) { | ||
try { | ||
@@ -1127,5 +1150,6 @@ const evalProp = import_globals.window.eval(`(${objProp})`); | ||
var import_types = require_types(); | ||
var import_utils3 = require_cjs(); | ||
var isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))(); | ||
var setCookie = (cname, cvalue, exdays = 365) => { | ||
if ((0, import_types.isUndefined)(document) || (0, import_types.isUndefined)(document.cookie)) | ||
if ((0, import_types.isUndefined)(import_utils3.document) || (0, import_types.isUndefined)(import_utils3.document.cookie)) | ||
return; | ||
@@ -1135,9 +1159,9 @@ const d = /* @__PURE__ */ new Date(); | ||
const expires = `expires=${d.toUTCString()}`; | ||
document.cookie = `${cname}=${cvalue};${expires};path=/`; | ||
import_utils3.document.cookie = `${cname}=${cvalue};${expires};path=/`; | ||
}; | ||
var getCookie = (cname) => { | ||
if ((0, import_types.isUndefined)(document) || (0, import_types.isUndefined)(document.cookie)) | ||
if ((0, import_types.isUndefined)(import_utils3.document) || (0, import_types.isUndefined)(import_utils3.document.cookie)) | ||
return; | ||
const name = `${cname}=`; | ||
const decodedCookie = decodeURIComponent(document.cookie); | ||
const decodedCookie = decodeURIComponent(import_utils3.document.cookie); | ||
const ca = decodedCookie.split(";"); | ||
@@ -1368,2 +1392,3 @@ for (let i = 0; i < ca.length; i++) { | ||
formatDate: () => formatDate, | ||
loadJavascript: () => loadJavascript, | ||
loadJavascriptFile: () => loadJavascriptFile, | ||
@@ -1450,2 +1475,13 @@ removeChars: () => removeChars, | ||
}; | ||
var loadJavascript = (body, async = true, doc = document, type = "text/javascript") => { | ||
try { | ||
const scriptEle = doc.createElement("script"); | ||
scriptEle.type = type; | ||
scriptEle.async = async; | ||
scriptEle.innerHTML = body; | ||
doc.body.appendChild(scriptEle); | ||
} catch (error) { | ||
console.warn(error); | ||
} | ||
}; | ||
@@ -1479,2 +1515,4 @@ // src/index.js | ||
var toDescriptionCase = (str = "") => { | ||
if (typeof str !== "string") | ||
return; | ||
const result = str.replace(/([A-Z])/g, " $1"); | ||
@@ -1481,0 +1519,0 @@ return result.charAt(0).toUpperCase() + result.slice(1); |
@@ -23,2 +23,3 @@ "use strict"; | ||
__export(load_exports, { | ||
loadJavascript: () => loadJavascript, | ||
loadJavascriptFile: () => loadJavascriptFile | ||
@@ -51,1 +52,12 @@ }); | ||
}; | ||
var loadJavascript = (body, async = true, doc = document, type = "text/javascript") => { | ||
try { | ||
const scriptEle = doc.createElement("script"); | ||
scriptEle.type = type; | ||
scriptEle.async = async; | ||
scriptEle.innerHTML = body; | ||
doc.body.appendChild(scriptEle); | ||
} catch (error) { | ||
console.warn(error); | ||
} | ||
}; |
@@ -133,3 +133,3 @@ "use strict"; | ||
__export2(globals_exports, { | ||
document: () => document2, | ||
document: () => document, | ||
global: () => global, | ||
@@ -143,3 +143,3 @@ self: () => self, | ||
var window = globalThis; | ||
var document2 = window.document; | ||
var document = window.document; | ||
} | ||
@@ -298,2 +298,3 @@ }); | ||
__export2(array_exports, { | ||
addItemAfterEveryElement: () => addItemAfterEveryElement, | ||
arrayContainsOtherArray: () => arrayContainsOtherArray, | ||
@@ -310,2 +311,3 @@ createNestedObject: () => createNestedObject, | ||
removeValueFromArrayAll: () => removeValueFromArrayAll, | ||
reorderArrayByValues: () => reorderArrayByValues, | ||
swapItemsInArray: () => swapItemsInArray | ||
@@ -395,2 +397,23 @@ }); | ||
}; | ||
var addItemAfterEveryElement = (array, item) => { | ||
const result = []; | ||
for (let i = 0; i < array.length; i++) { | ||
result.push(array[i]); | ||
if (i < array.length - 1) { | ||
result.push(item); | ||
} | ||
} | ||
return result; | ||
}; | ||
var reorderArrayByValues = (array, valueToMove, insertBeforeValue) => { | ||
const newArray = [...array]; | ||
const indexToMove = newArray.indexOf(valueToMove); | ||
const indexToInsertBefore = newArray.indexOf(insertBeforeValue); | ||
if (indexToMove !== -1 && indexToInsertBefore !== -1) { | ||
const removedItem = newArray.splice(indexToMove, 1)[0]; | ||
const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1; | ||
newArray.splice(insertIndex, 0, removedItem); | ||
} | ||
return newArray; | ||
}; | ||
} | ||
@@ -672,3 +695,3 @@ }); | ||
}; | ||
var objectToString = (obj, indent = 0) => { | ||
var objectToString = (obj = {}, indent = 0) => { | ||
const spaces = " ".repeat(indent); | ||
@@ -740,3 +763,3 @@ let str = "{\n"; | ||
if ((0, import_types.isString)(objProp)) { | ||
if ((objProp.includes("=>") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) { | ||
if ((objProp.includes("(){") || objProp.includes("() {") || objProp.includes("=>") || objProp.startsWith("()") || objProp.startsWith("async") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) { | ||
try { | ||
@@ -1129,5 +1152,6 @@ const evalProp = import_globals.window.eval(`(${objProp})`); | ||
var import_types = require_types(); | ||
var import_utils2 = require_cjs(); | ||
var isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))(); | ||
var setCookie = (cname, cvalue, exdays = 365) => { | ||
if ((0, import_types.isUndefined)(document) || (0, import_types.isUndefined)(document.cookie)) | ||
if ((0, import_types.isUndefined)(import_utils2.document) || (0, import_types.isUndefined)(import_utils2.document.cookie)) | ||
return; | ||
@@ -1137,9 +1161,9 @@ const d = /* @__PURE__ */ new Date(); | ||
const expires = `expires=${d.toUTCString()}`; | ||
document.cookie = `${cname}=${cvalue};${expires};path=/`; | ||
import_utils2.document.cookie = `${cname}=${cvalue};${expires};path=/`; | ||
}; | ||
var getCookie = (cname) => { | ||
if ((0, import_types.isUndefined)(document) || (0, import_types.isUndefined)(document.cookie)) | ||
if ((0, import_types.isUndefined)(import_utils2.document) || (0, import_types.isUndefined)(import_utils2.document.cookie)) | ||
return; | ||
const name = `${cname}=`; | ||
const decodedCookie = decodeURIComponent(document.cookie); | ||
const decodedCookie = decodeURIComponent(import_utils2.document.cookie); | ||
const ca = decodedCookie.split(";"); | ||
@@ -1146,0 +1170,0 @@ for (let i = 0; i < ca.length; i++) { |
{ | ||
"name": "@symbo.ls/utils", | ||
"version": "2.11.375", | ||
"version": "2.11.394", | ||
"author": "symbo.ls", | ||
@@ -29,3 +29,3 @@ "files": [ | ||
}, | ||
"gitHead": "4fddad68b778dbfd8298ac6ca8d500bdabbb2282" | ||
"gitHead": "96fc31e44dd43084955c647e91b5d0e70d56aee8" | ||
} |
@@ -47,2 +47,3 @@ 'use strict' | ||
export const toDescriptionCase = (str = '') => { | ||
if (typeof str !== 'string') return | ||
const result = str.replace(/([A-Z])/g, ' $1') | ||
@@ -49,0 +50,0 @@ return result.charAt(0).toUpperCase() + result.slice(1) |
@@ -30,1 +30,14 @@ 'use strict' | ||
} | ||
export const loadJavascript = (body, async = true, doc = document, type = 'text/javascript') => { | ||
try { | ||
const scriptEle = doc.createElement('script') | ||
scriptEle.type = type | ||
scriptEle.async = async | ||
scriptEle.innerHTML = body | ||
doc.body.appendChild(scriptEle) | ||
} catch (error) { | ||
console.warn(error) | ||
} | ||
} |
173623
4668