Comparing version 0.1.3 to 0.1.4
25
main.js
@@ -337,2 +337,3 @@ /* global Blob File FormData $ */ | ||
* get value in object using a flat key | ||
* @todo check params | ||
* @param {object} obj | ||
@@ -353,2 +354,26 @@ * @param {string} fkey | ||
return _walk | ||
}, | ||
/** | ||
* set value in object using a flat key | ||
* @todo check params | ||
* @param {object} obj | ||
* @param {string} fkey | ||
* @param {*} val | ||
* @example tools.object.setByFlatKey({}, 'a.b.c', 1) >> { a: { b: {c: 1} } } | ||
*/ | ||
setByFlatKey: function (obj, fkey, val) { | ||
let _path = fkey.split('.') | ||
let _walk = obj | ||
for (let i = 0; i < _path.length; i++) { | ||
if (!_walk[_path[i]]) { | ||
// if it's the last step, add key as undefined | ||
if (i === _path.length - 1) { | ||
_walk[_path[i]] = undefined | ||
return | ||
} | ||
_walk[_path[i]] = {} | ||
} | ||
_walk = _walk[_path[i]] | ||
} | ||
_walk = val | ||
} | ||
@@ -355,0 +380,0 @@ }, |
{ | ||
"name": "a-toolbox", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "basic lightweight tools", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23176
615