{"size": 1371, "ext": "js", "max_stars_repo_path": "src/color/hexToRGB.js", "max_stars_repo_name": "bhavjitChauhan/Essentials", "max_stars_repo_stars_event_min_datetime": "2021-03-28T16:10:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-27T05:40:19.000Z", "max_issues_repo_path": "src/color/hexToRGB.js", "max_issues_repo_name": "bhavjitChauhan/Essentials", "max_issues_repo_issues_event_min_datetime": "2019-07-16T23:32:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-26T23:22:13.000Z", "max_forks_repo_path": "src/color/hexToRGB.js", "max_forks_repo_name": "bhavjitChauhan/Essentials", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": 87, "max_forks_count": null, "avg_line_length": 27.42, "max_line_length": 124, "alphanum_fraction": 0.5149525894}
/**
 * Converts hex to RGB color type.
 * 
 * @category Color
 *
 * @param {string} hex hex color value
 * @param {boolean} [color=true] return color integer or array
 *
 * @returns {color|Array}
 *
 * @example
 * const col = hexToRGB('#006FDE');
 * println(hex(col, 6));
 * // expected output: '006FDE'
 * 
 * @example
 * println(hexToRGB('#AAAA', false));
 * // expected output: [170, 170, 170, 170]
 * 
 * @example
 * const hex = '#F00';
 * colorMode(RGB, 1, 1, 1, 1);
 * println(hexToRGB(hex, false));
 * // expected output: [1, 0, 0, 1]
 */
hexToRGB = (hex, color = true) => {
    const currentColorMode = getColorMode();
    hex = hex.replace('#', '');
    switch (hex.length) {
        case 3:
        case 6:
            hex = hex.replace(/^([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b) => r + r + g + g + b + b);
            break;
        case 4:
        case 8:
            hex = hex.replace(/^([a-f\d])([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b, a) => r + r + g + g + b + b + a + a);
            break;
    }
    let arr = hex
        .match(/.{2}/g)
        .map(x => parseInt(x, 16));
    if (arr.length == 3) arr.push(RGB_COLOR_RANGE[3]);
    if (!isDefaultColorRange() && currentColorMode == p.RGB) {
        arr = mapColorRange(arr);
    }
    let result = arr;
    if (color) result = _createColor(arr, p.RGB, currentColorMode);
    return result;
};
