@statoscope/helpers
Advanced tools
Comparing version 5.2.0 to 5.3.0-alpha.0
@@ -1,2 +0,28 @@ | ||
declare const _default: () => Record<string, unknown>; | ||
import { Item } from '../network-type-list'; | ||
import { colorFromH } from './colors'; | ||
declare const _default: () => { | ||
stringify: { | ||
(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; | ||
(value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; | ||
}; | ||
toNumber(str: string): number; | ||
formatSize(value: number): string; | ||
formatDate(ts: number, locale?: string | undefined): string; | ||
formatDuration(ms: number): string; | ||
percentFrom(a: number, b: number, toFixed?: number | undefined): number; | ||
toFixed(value: number, digits?: number): string; | ||
color: (value: string) => string; | ||
fileExt: (value?: string | undefined) => string; | ||
fileType: (value?: string | undefined) => string; | ||
toMatchRegexp: (value: string, rx: RegExp) => boolean; | ||
toRegexp: (value: string) => RegExp; | ||
colorFromH: typeof colorFromH; | ||
plural(value: number, words: string[]): string; | ||
pluralWithValue(value: number, words: string[]): string; | ||
pluralRus(value: number, words: string[]): string; | ||
pluralWithValueRus(value: number, words: string[]): string; | ||
getNetworkTypeInfo(networkType: string): Item | null; | ||
getNetworkTypeName(networkType: Item): string | null; | ||
getDownloadTime(size: number, networkType: string): number; | ||
}; | ||
export default _default; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -7,4 +26,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const path_1 = __importDefault(require("path")); | ||
const network_type_list_1 = __importStar(require("../network-type-list")); | ||
const colors_1 = require("./colors"); | ||
const plural_1 = require("./plural"); | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type | ||
exports.default = () => { | ||
@@ -27,4 +48,4 @@ return { | ||
}, | ||
formatDate(ts) { | ||
return new Date(ts).toLocaleString(); | ||
formatDate(ts, locale) { | ||
return new Date(ts).toLocaleString(locale); | ||
}, | ||
@@ -38,3 +59,3 @@ formatDuration(ms) { | ||
} | ||
return (sign * (ms / 1000)).toFixed(0) + ' sec'; | ||
return (sign * (ms / 1000)).toFixed(1) + ' sec'; | ||
} | ||
@@ -60,6 +81,12 @@ return 'n/a'; | ||
color: (value) => colors_1.colorMap[value] ? colors_1.colorMap[value].color : colors_1.generateColor(value), | ||
fileExt: (value = '') => { | ||
fileExt: (value) => { | ||
if (value == null) { | ||
return ''; | ||
} | ||
return path_1.default.extname(value); | ||
}, | ||
fileType: (value = '') => { | ||
fileType: (value) => { | ||
if (value == null) { | ||
return ''; | ||
} | ||
const extname = path_1.default.extname(value); | ||
@@ -83,4 +110,18 @@ return colors_1.fileTypeMap[extname] || extname; | ||
}, | ||
getNetworkTypeInfo(networkType) { | ||
var _a; | ||
return (_a = network_type_list_1.default.find((item) => item.name === networkType)) !== null && _a !== void 0 ? _a : null; | ||
}, | ||
getNetworkTypeName(networkType) { | ||
return `${networkType.type}: ${networkType.name} (${parseFloat((networkType.typicalSpeed / network_type_list_1.bytesInMBit).toFixed(1))} MBit/s)`; | ||
}, | ||
getDownloadTime(size, networkType) { | ||
const item = network_type_list_1.default.find((item) => item.name === networkType); | ||
if (item) { | ||
return (size / item.typicalSpeed) * 1000; | ||
} | ||
throw new Error(`Unknown network type ${networkType}`); | ||
}, | ||
}; | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@statoscope/helpers", | ||
"version": "5.2.0", | ||
"version": "5.3.0-alpha.0", | ||
"description": "Statoscope utils", | ||
@@ -23,3 +23,3 @@ "main": "./dist/index.js", | ||
"homepage": "https://github.com/statoscope/statoscope/", | ||
"gitHead": "f2414604bd60930e3352448e49bbb27af926df35" | ||
"gitHead": "9b35de4f038a2d5426c6119ddc046b0a5096a96f" | ||
} |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
27125
20
448
1