@domql/utils
Advanced tools
Comparing version 2.3.126 to 2.3.137
@@ -25,1 +25,2 @@ "use strict"; | ||
__reExport(utils_exports, require("./log.js"), module.exports); | ||
__reExport(utils_exports, require("./string.js"), module.exports); |
@@ -38,6 +38,8 @@ "use strict"; | ||
mergeIfExisted: () => mergeIfExisted, | ||
objectToString: () => objectToString, | ||
overwrite: () => overwrite, | ||
overwriteDeep: () => overwriteDeep, | ||
overwriteShallow: () => overwriteShallow, | ||
removeFromObject: () => removeFromObject | ||
removeFromObject: () => removeFromObject, | ||
stringToObject: () => stringToObject | ||
}); | ||
@@ -48,2 +50,3 @@ module.exports = __toCommonJS(object_exports); | ||
var import_array = require("./array.js"); | ||
var import_string = require("./string.js"); | ||
const exec = (param, element, state, context) => { | ||
@@ -165,2 +168,21 @@ if ((0, import_types.isFunction)(param)) { | ||
}; | ||
const objectToString = (obj, indent = 0) => { | ||
const spaces = " ".repeat(indent); | ||
let str = "{\n"; | ||
for (const [key, value] of Object.entries(obj)) { | ||
const keyAllowdChars = (0, import_string.stringIncludesAny)(key, ["-", ":"]); | ||
const stringedKey = keyAllowdChars ? `'${key}'` : key; | ||
str += `${spaces} ${stringedKey}: `; | ||
if (typeof value === "object" && value !== null) { | ||
str += objectToString(value, indent + 1); | ||
} else if (typeof value === "string") { | ||
str += `'${value}'`; | ||
} else { | ||
str += value; | ||
} | ||
str += ",\n"; | ||
} | ||
str += `${spaces}}`; | ||
return str; | ||
}; | ||
const detachFunctionsFromObject = (obj, detached = {}) => { | ||
@@ -236,2 +258,12 @@ for (const prop in obj) { | ||
}; | ||
const stringToObject = (str) => { | ||
let obj; | ||
try { | ||
obj = import_globals.window.eval("(" + str + ")"); | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
if (obj) | ||
return obj; | ||
}; | ||
const diffObjects = (original, objToDiff, cache) => { | ||
@@ -238,0 +270,0 @@ for (const e in objToDiff) { |
@@ -10,1 +10,2 @@ 'use strict' | ||
export * from './log.js' | ||
export * from './string.js' |
@@ -6,2 +6,3 @@ 'use strict' | ||
import { mergeAndCloneIfArray, mergeArray } from './array.js' | ||
import { stringIncludesAny } from './string.js' | ||
@@ -139,2 +140,26 @@ export const exec = (param, element, state, context) => { | ||
export const objectToString = (obj, indent = 0) => { | ||
const spaces = ' '.repeat(indent) | ||
let str = '{\n' | ||
for (const [key, value] of Object.entries(obj)) { | ||
const keyAllowdChars = stringIncludesAny(key, ['-', ':']) | ||
const stringedKey = keyAllowdChars ? `'${key}'` : key | ||
str += `${spaces} ${stringedKey}: ` | ||
if (typeof value === 'object' && value !== null) { | ||
str += objectToString(value, indent + 1) | ||
} else if (typeof value === 'string') { | ||
str += `'${value}'` | ||
} else { | ||
str += value | ||
} | ||
str += ',\n' | ||
} | ||
str += `${spaces}}` | ||
return str | ||
} | ||
/** | ||
@@ -210,2 +235,11 @@ * Stringify object | ||
export const stringToObject = (str) => { | ||
let obj | ||
try { | ||
obj = window.eval('(' + str + ')') // eslint-disable-line | ||
} catch (e) { console.warn(e) } | ||
if (obj) return obj | ||
} | ||
export const diffObjects = (original, objToDiff, cache) => { | ||
@@ -212,0 +246,0 @@ for (const e in objToDiff) { |
{ | ||
"name": "@domql/utils", | ||
"version": "2.3.126", | ||
"version": "2.3.137", | ||
"license": "MIT", | ||
@@ -26,3 +26,3 @@ "type": "module", | ||
}, | ||
"gitHead": "6329de71d2e831d0efd9d59e765567aa8c563481", | ||
"gitHead": "07ca3db13100667ebe3915db37a18b6e694a3ce3", | ||
"devDependencies": { | ||
@@ -29,0 +29,0 @@ "@babel/core": "^7.12.0" |
40271
19
1199