Add more zlib utils
This commit is contained in:
parent
542d0c0ee4
commit
53b4bed979
|
@ -1,4 +1,5 @@
|
|||
import Utilities from "@modules/utilities";
|
||||
import {comparator} from "@structs/semver";
|
||||
|
||||
|
||||
/**
|
||||
|
@ -71,6 +72,27 @@ const Utils = {
|
|||
*/
|
||||
className() {
|
||||
return Utilities.className(...arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets a nested value (if it exists) of an object safely. keyPath should be something like `key.key2.key3`.
|
||||
* Numbers can be used for arrays as well like `key.key2.array.0.id`.
|
||||
* @param {object} obj - object to get nested value from
|
||||
* @param {string} keyPath - key path to the desired value
|
||||
*/
|
||||
getNestedValue(obj, keyPath) {
|
||||
return Utilities.getNestedValue(obj, keyPath);
|
||||
},
|
||||
|
||||
/**
|
||||
* This works on semantic versioning e.g. "1.0.0".
|
||||
*
|
||||
* @param {string} currentVersion
|
||||
* @param {string} newVersion
|
||||
* @returns {number} 0 indicates equal, -1 indicates left hand greater, 1 indicates right hand greater
|
||||
*/
|
||||
semverCompare(currentVersion, newVersion) {
|
||||
return comparator(currentVersion, newVersion);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -216,4 +216,16 @@ export default class Utilities {
|
|||
|
||||
return classes.join(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a nested value (if it exists) safely. Path should be something like `prop.prop2.prop3`.
|
||||
* Numbers can be used for arrays as well like `prop.prop2.array.0.id`.
|
||||
* @param {Object} obj - object to get nested value of
|
||||
* @param {string} path - representation of the key path to obtain
|
||||
*/
|
||||
static getNestedValue(obj, path) {
|
||||
return path.split(".").reduce(function(ob, prop) {
|
||||
return ob && ob[prop];
|
||||
}, obj);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue