mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 16:33:15 +01:00
34 lines
No EOL
730 B
JavaScript
34 lines
No EOL
730 B
JavaScript
export const EMPTY_OBJECT = Object.freeze({});
|
|
|
|
export function clone(object) {
|
|
return JSON.parse(JSON.stringify(object));
|
|
}
|
|
|
|
|
|
export function traverseObject(root, callback) {
|
|
|
|
const stack = [root];
|
|
|
|
while (stack.length !== 0) {
|
|
|
|
const obj = stack.pop();
|
|
|
|
if (Array.isArray(obj)) {
|
|
obj.forEach((item, i) => {
|
|
if (typeof item === 'object') {
|
|
stack.push(item)
|
|
}
|
|
});
|
|
} else if (obj && typeof obj === 'object') {
|
|
callback(obj);
|
|
Object.keys(obj).forEach(key => {
|
|
const item = obj[key];
|
|
if (typeof item === 'object') {
|
|
stack.push(item);
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
export const allPropsDefined = obj => Object.values(obj).every(x => !!x); |