JSFiddle - React, Tailwind, and code Playground
by migontech
JavaScript
if (!Object.keys) {
Object.keys = (function() {
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({
toString: null
}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
return function(obj) {
if (typeof obj !== 'function' && (typeof obj !== 'object' || obj === null)) {
throw new TypeError('Object.keys called on non-object');
}
var result = [],
prop, i;
for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}
if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
}());
}
const log = {
debug: function() {
console.log.apply(null, arguments);
}
}
function parseDotNotation(str, val, obj) {
var
_currentObj = obj,
_keys = str.split("."),
_key = _keys[0],
_arrayKey, _match, _idx, _lastKey = _keys[_keys.length - 1],
_lastKeyIsArray = _lastKey && /(.+)\[(\d+)\]$/.test(_lastKey);
var i, l = _keys.length - (_lastKeyIsArray ? 0 : 1);
for (i = 0; i < l; i++) {
_key = _keys[i];
if (/(.+)\[(\d+)\]$/.test(_key)) {
_match = /(.+)\[(\d+)\]$/.exec(_key);
_arrayKey = _match[1];
_idx = parseInt(_match[2]);
if (!(_currentObj[_arrayKey] instanceof Array)) {
_currentObj[_arrayKey] = []
}
if (_currentObj[_arrayKey][_idx]) {
_currentObj[_arrayKey][_idx] = _currentObj[_arrayKey][_idx];
_currentObj =...