{"size": 2103, "ext": "js", "max_stars_repo_path": "node_modules/@bundle-stats/utils/lib/utils/delta.js", "max_stars_repo_name": "rajrajhans/bundle-stats-action", "max_stars_repo_stars_event_min_datetime": "2020-04-10T10:00:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T20:04:07.000Z", "max_issues_repo_path": "node_modules/@bundle-stats/utils/lib/utils/delta.js", "max_issues_repo_name": "rajrajhans/bundle-stats-action", "max_issues_repo_issues_event_min_datetime": "2020-03-29T00:22:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-04T19:34:55.000Z", "max_forks_repo_path": "node_modules/@bundle-stats/utils/lib/utils/delta.js", "max_forks_repo_name": "rajrajhans/bundle-stats-action", "max_forks_repo_forks_event_min_datetime": "2021-11-25T05:20:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-25T05:20:40.000Z"}
{"max_stars_count": 14, "max_issues_count": 72, "max_forks_count": 1, "avg_line_length": 31.3880597015, "max_line_length": 88, "alphanum_fraction": 0.5872563005}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDeltaType = exports.formatDelta = exports.getDelta = void 0;
const round_1 = __importDefault(require("lodash/round"));
const delta_1 = require("../config/delta");
const getDelta = (baseline, current) => {
    const baselineValue = (baseline && baseline.value) || 0;
    const currentValue = (current && current.value) || 0;
    if (baselineValue === currentValue) {
        return {
            delta: 0,
            deltaPercentage: 0,
        };
    }
    if (baselineValue === 0) {
        return {
            delta: currentValue,
            deltaPercentage: 100,
        };
    }
    return {
        delta: currentValue - baselineValue,
        deltaPercentage: round_1.default((currentValue / baselineValue) * 100 - 100, 8),
    };
};
exports.getDelta = getDelta;
const formatDelta = (value, formatter) => {
    let sign = value > 0
        ? '+'
        : (value < 0 ? '-' : '');
    let absValue = Math.abs(value);
    if (absValue > 0 && absValue < 0.01) {
        sign = `~${sign}`;
        absValue = 0.01;
    }
    if (absValue > 0.01) {
        absValue = round_1.default(absValue, 2);
    }
    return `${sign}${formatter(absValue)}`;
};
exports.formatDelta = formatDelta;
const getDeltaType = (deltaValue, biggerIsBetter) => {
    if (deltaValue === 0) {
        return delta_1.DELTA_TYPE_NO_CHANGE;
    }
    const absDiff = Math.abs(deltaValue);
    let level = '';
    if (absDiff <= 5) {
        level = delta_1.DELTA_TYPE_LEVEL_LOW;
    }
    if (absDiff > 50) {
        level = delta_1.DELTA_TYPE_LEVEL_HIGH;
    }
    let type = '';
    if ((deltaValue > 0 && biggerIsBetter) || (deltaValue < 0 && !biggerIsBetter)) {
        type = delta_1.DELTA_TYPE_POSITIVE;
    }
    else {
        type = delta_1.DELTA_TYPE_NEGATIVE;
    }
    return `${level ? `${level}_` : ''}${type}`;
};
exports.getDeltaType = getDeltaType;
//# sourceMappingURL=delta.js.map