Source: utilities/utilities.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ramda_1 = require("ramda");
;
/**
 * Find and return the first defined property from within the list of provided properties from the object later
 * provided.
 *
 * @param {String[]} props - The properties to check if they are defined
 *
 * @return {Function} A method that will return the first defined property from the object provided
 */
function firstDefinedProperty(props) {
    return (obj) => {
        return ramda_1.prop(ramda_1.compose(ramda_1.head, ramda_1.curry(ramda_1.intersection)(props), ramda_1.keys)(obj), obj);
    };
}
exports.firstDefinedProperty = firstDefinedProperty;
/**
 * A curried method to generate an indexed object from an array of strings. This method will execute the function passed
 * with the string found at each position in the array provided upon final execution, and map the returned value to the
 * key in the final object with the relevant string.
 *
 * @param {Function} method - The function with which to create the objects values
 *
 * @returns {Function} A method that will return a new object whos values are equated from the method provided
 */
function toObjectBy(method) {
    return ramda_1.converge(ramda_1.zipObj, [ramda_1.map(ramda_1.identity), ramda_1.map(method)]);
}
exports.toObjectBy = toObjectBy;
/**
 * Prune any preceeding text from a version identifier, commonly found in Bower declaration files, and return the true
 * version.
 *
 * @param {String} version - The version string to parse
 *
 * @returns {String} The true version from the string provided
 */
function pruneVersionString(version) {
    return /(\*)|(\^|~|<|>|(<|>)=)?((\d.)?(\d.)?)?\d$/.exec(version)[0];
}
exports.pruneVersionString = pruneVersionString;