|
- function replaceChildren(element, newChildren) {
- removeChildren(element);
- addChildren(element, newChildren);
- }
-
- function addChildren(element, children) {
- for (let child of children) {
- element.appendChild(child);
- }
- }
-
- function removeChildren(element) {
- while (element.lastChild) {
- element.removeChild(element.lastChild);
- }
- }
-
- function round(val, places = 0) {
- return Math.round(val * Math.pow(10, places)) / Math.pow(10, places);
- }
-
- function mapObject(obj, func) {
- return deepFreeze(Object.keys(obj).reduce((o, k) => ({ ...o, [k]: func(obj[k])}), {}));
- }
-
- function deepFreeze(object) {
-
- // Retrieve the property names defined on object
- var propNames = Object.getOwnPropertyNames(object);
-
- // Freeze properties before freezing self
-
- for (let name of propNames) {
- let value = object[name];
-
- object[name] = value && typeof value === "object" ?
- deepFreeze(value) : value;
- }
-
- return Object.freeze(object);
- }
|