@statoscope/helpers
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -0,3 +1,32 @@ | ||
import { SemVer } from 'semver'; | ||
import { Item } from '../network-type-list'; | ||
import { colorFromH } from './colors'; | ||
export interface BaseDiffItem { | ||
id?: string; | ||
title?: string; | ||
} | ||
export interface TimeDiffItem extends BaseDiffItem { | ||
type: 'time'; | ||
a: number; | ||
b: number; | ||
} | ||
export interface SizeDiffItem extends BaseDiffItem { | ||
type: 'size'; | ||
a: number; | ||
b: number; | ||
} | ||
export interface NumberDiffItem extends BaseDiffItem { | ||
type: 'number'; | ||
a: number; | ||
b: number; | ||
plural?: { | ||
words: string[]; | ||
}; | ||
} | ||
export interface VersionDiffItem extends BaseDiffItem { | ||
type: 'version'; | ||
a: string; | ||
b: string; | ||
} | ||
export declare type DiffItem = TimeDiffItem | SizeDiffItem | NumberDiffItem | VersionDiffItem; | ||
declare const _default: () => { | ||
@@ -27,3 +56,11 @@ stringify: { | ||
getDownloadTime(size: number, networkType: string): number; | ||
semverGT(a: string, b: string): boolean; | ||
semverGTE(a: string, b: string): boolean; | ||
semverLT(a: string, b: string): boolean; | ||
semverLTE(a: string, b: string): boolean; | ||
semverEQ(a: string, b: string): boolean; | ||
semverDiff(a: string, b: string): string | null; | ||
semverParse(version?: string | undefined): SemVer | null; | ||
formatDiff(value: DiffItem): string; | ||
}; | ||
export default _default; |
@@ -26,2 +26,9 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const diff_1 = __importDefault(require("semver/functions/diff")); | ||
const gt_1 = __importDefault(require("semver/functions/gt")); | ||
const gte_1 = __importDefault(require("semver/functions/gte")); | ||
const lt_1 = __importDefault(require("semver/functions/lt")); | ||
const lte_1 = __importDefault(require("semver/functions/lte")); | ||
const eq_1 = __importDefault(require("semver/functions/eq")); | ||
const parse_1 = __importDefault(require("semver/functions/parse")); | ||
const network_type_list_1 = __importStar(require("../network-type-list")); | ||
@@ -32,3 +39,3 @@ const colors_1 = require("./colors"); | ||
exports.default = () => { | ||
return { | ||
const helpers = { | ||
stringify: JSON.stringify, | ||
@@ -122,4 +129,44 @@ toNumber(str) { | ||
}, | ||
semverGT(a, b) { | ||
return gt_1.default(a, b); | ||
}, | ||
semverGTE(a, b) { | ||
return gte_1.default(a, b); | ||
}, | ||
semverLT(a, b) { | ||
return lt_1.default(a, b); | ||
}, | ||
semverLTE(a, b) { | ||
return lte_1.default(a, b); | ||
}, | ||
semverEQ(a, b) { | ||
return eq_1.default(a, b); | ||
}, | ||
semverDiff(a, b) { | ||
return diff_1.default(a, b); | ||
}, | ||
semverParse(version) { | ||
return parse_1.default(version); | ||
}, | ||
formatDiff(value) { | ||
var _a; | ||
if (value.type === 'size') { | ||
return helpers.formatSize(value.b - value.a); | ||
} | ||
if (value.type === 'time') { | ||
return helpers.formatDuration(value.b - value.a); | ||
} | ||
if (value.type === 'version') { | ||
const diff = diff_1.default(value.a, value.b); | ||
const type = gt_1.default(value.a, value.b) ? 'downgrade' : 'upgrade'; | ||
return diff ? `${diff} ${type} from ${value.a}` : ''; | ||
} | ||
if ((_a = value.plural) === null || _a === void 0 ? void 0 : _a.words) { | ||
return helpers.pluralWithValue(value.b - value.a, value.plural.words); | ||
} | ||
return (value.b - value.a).toString(); | ||
}, | ||
}; | ||
return helpers; | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@statoscope/helpers", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"description": "Statoscope utils", | ||
@@ -23,3 +23,9 @@ "main": "./dist/index.js", | ||
"homepage": "https://github.com/statoscope/statoscope/", | ||
"gitHead": "7fd6be7180eda342c57f2d9cd3b5ed228779d22c" | ||
"dependencies": { | ||
"semver": "^7.3.5" | ||
}, | ||
"devDependencies": { | ||
"@types/semver": "^7.3.6" | ||
}, | ||
"gitHead": "82bb8b83ef2d967918519f878ab0ced3c1a8448c" | ||
} |
Sorry, the diff of this file is not supported yet
31655
544
1
1
+ Addedsemver@^7.3.5
+ Addedsemver@7.6.3(transitive)