{"size": 2404, "ext": "js", "max_stars_repo_path": "src/randomColor.js", "max_stars_repo_name": "ready-research/licia", "max_stars_repo_stars_event_min_datetime": "2018-05-06T11:33:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T01:00:54.000Z", "max_issues_repo_path": "src/r/randomColor.js", "max_issues_repo_name": "d3m0n-r00t/licia", "max_issues_repo_issues_event_min_datetime": "2018-05-07T06:46:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-17T03:38:04.000Z", "max_forks_repo_path": "src/r/randomColor.js", "max_forks_repo_name": "d3m0n-r00t/licia", "max_forks_repo_forks_event_min_datetime": "2018-05-07T02:58:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T16:04:23.000Z"}
{"max_stars_count": 1778, "max_issues_count": 16, "max_forks_count": 137, "avg_line_length": 24.7835051546, "max_line_length": 78, "alphanum_fraction": 0.4546589018}
/* Random color generator.
 *
 * |Name   |Desc          |
 * |-------|--------------|
 * |options|Random options|
 * |return |Random color  |
 *
 * Available options:
 *
 * |Name      |Desc                             |
 * |----------|---------------------------------|
 * |count=1   |Color number                     |
 * |hue       |Hue, number between 0 and 360    |
 * |lightness |Lightness, number between 0 and 1|
 * |format=hex|Color format, hex, hsl or rgb    |
 * |seed      |Random color seed                |
 */

/* example
 * randomColor({
 *     count: 2
 * }); // -> ['#fed7f4', '#526498']
 */

/* module
 * env: all
 * since: 1.12.0
 */

/* typescript
 * export declare function randomColor(): string;
 * export declare function randomColor(options: {
 *     count?: number;
 *     hue?: number;
 *     lightness?: number;
 *     format?: string;
 *     seed?: number;
 * }): string | string[];
 */

_('defaults random Color seedRandom isFn');

exports = function(options = {}) {
    defaults(options, defOpts);

    const { count } = options;
    let { randomH, randomL, randomS } = options;
    if (!isFn(randomH)) {
        const seed = options.seed || random(0, 100000);
        randomH = seedRandom(seed, 0, 360, false);
        randomL = seedRandom(seed + 1, 0, 1);
        randomS = seedRandom(seed + 2, 0, 1);
    }
    if (count > 1) {
        const colors = [];
        for (let i = 0; i < count; i++) {
            colors.push(
                exports(
                    defaults(
                        {
                            count: 1,
                            randomH,
                            randomL,
                            randomS
                        },
                        options
                    )
                )
            );
        }
        return colors;
    }

    const hue = options.hue || randomH();
    const lightness = options.lightness || randomL().toFixed(2);
    const saturation = options.saturation || randomS().toFixed(2);

    const color = new Color({
        val: [hue, Math.round(saturation * 100), Math.round(lightness * 100)],
        model: 'hsl'
    });

    switch (options.format) {
        case 'hsl':
            return color.toHsl();
        case 'rgb':
            return color.toRgb();
        default:
            return color.toHex();
    }
};

const defOpts = {
    count: 1,
    format: 'hex'
};
