= "object" || obj === null) { return undefined; } return Object.keys(obj); } /** * Return an array of the given object's values (specifically, its own * enumerable string-keyed property values), or undefined if the argument isn't * an object. * * @param {object} obj * @return {Array|undefined} */ function values(obj) { if (typeof obj !== "object" || obj === null) { return undefined; } return Object.values(obj); } /** * Return the length of an array * * @param {Array} arr * @return {number} */ function length(arr) { return Array.isArray(arr) ? arr.length : undefined; } /** * Given an input array and property name, return an array with each element of * the original array replaced with the given property of that element. * * @param {Array} arr * @param {string} prop * @return {Array} */ function mapToProperty(arr, prop) { return Array.isArray(arr) ? arr.map(elem => elem[prop]) : undefined; } /** * Find all the values that are present in both lists. Returns undefined if * the arguments are not both Arrays. * * @param {Array} listA * @param {Array} listB * @return {Array|undefined} */ function operatorIntersect(listA, listB) { if (!Array.isArray(listA) || !Array.isArray(listB)) { return undefined; } return listA.filter(item => listB.includes(item)); } /** * Matches a string against a regular expression. Returns null if there are * no matches or an Array of matches. * * @param {string} str * @param {string} pattern * @param {string} flags * @return {Array|null} */ function regExpMatch(str, pattern, flags) { const re = new RegExp(pattern, flags); return str.match(re); } /** * Compares v1 to v2 and returns 0 if they are equal, a negative number if * v1 < v2 or a positive number if v1 > v2. * * @param {string} v1 * @param {string} v2 * @return {number} */ function versionCompare(v1, v2) { return Services.vc.compare(v1, v2); } PK