human-format
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -24,7 +24,15 @@ type BinaryPrefix = "" | "Ki" | "Mi" | "Gi" | "Ti" | "Pi" | "Ei" | "Zi" | "Yi"; | ||
export type Prefix<S extends ScaleName> = S extends "binary" | ||
export type Scale<T extends string> = humanFormat.Scale<T>; | ||
export type ScaleLike = Scale<string> | ScaleName; | ||
export type Prefix<S extends ScaleLike> = S extends Scale<infer U> | ||
? U | ||
: S extends "binary" | ||
? BinaryPrefix | ||
: SIPrefix; | ||
: S extends "SI" | ||
? SIPrefix | ||
: never; | ||
export declare interface Options<S extends ScaleName> { | ||
export declare interface Options<S extends ScaleLike> { | ||
maxDecimals?: number | "auto"; | ||
@@ -39,3 +47,3 @@ separator?: string; | ||
export declare interface Info<S extends ScaleName> { | ||
export declare interface Info<S extends ScaleLike> { | ||
value: number; | ||
@@ -46,3 +54,3 @@ prefix: Prefix<S>; | ||
export declare interface ParsedInfo<S extends ScaleName> { | ||
export declare interface ParsedInfo<S extends ScaleLike> { | ||
value: number; | ||
@@ -54,3 +62,3 @@ factor: number; | ||
export declare function humanFormat<S extends ScaleName>( | ||
export declare function humanFormat<S extends ScaleLike>( | ||
value: number, | ||
@@ -61,8 +69,8 @@ opts?: Options<S> | ||
export declare namespace humanFormat { | ||
function bytes<S extends ScaleName>(value: number, opts?: Options<S>): string; | ||
function bytes<S extends ScaleLike>(value: number, opts?: Options<S>): string; | ||
function parse<S extends ScaleName>(str: string, opts?: Options<S>): number; | ||
function parse<S extends ScaleLike>(str: string, opts?: Options<S>): number; | ||
namespace parse { | ||
function raw<S extends ScaleName>( | ||
function raw<S extends ScaleLike>( | ||
str: string, | ||
@@ -73,7 +81,19 @@ opts?: Options<S> | ||
function raw<S extends ScaleName>(value: number, opts?: Options<S>): Info<S>; | ||
function raw<S extends ScaleLike>(value: number, opts?: Options<S>): Info<S>; | ||
export { bytes, parse, raw, Prefix, BinaryPrefix }; | ||
class Scale<P extends string> { | ||
constructor(prefixes: Record<P, number>); | ||
} | ||
namespace Scale { | ||
function create<P extends string>( | ||
prefixes: P[], | ||
base: number, | ||
initExp?: number | ||
): Scale<P>; | ||
} | ||
export { bytes, parse, raw, Prefix, BinaryPrefix, Scale }; | ||
} | ||
export default humanFormat; |
{ | ||
"name": "human-format", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"license": "ISC", | ||
@@ -5,0 +5,0 @@ "description": "Converts a number to/from a human readable string: `1337` ↔ `1.34kB`", |
@@ -92,2 +92,7 @@ # human-format | ||
// Helper when the scale is regular, i.e. prefixes are powers of a constant factor | ||
var binaryScale = humanFormat.Scale.create(["", "Ki", "Mi", "Gi", "Ti"], 1024); | ||
humanFormat(173559053, { scale: binaryScale }); | ||
//=> 165.52 Mi | ||
// You can force a prefix to be used. | ||
@@ -94,0 +99,0 @@ humanFormat(100, { unit: "m", prefix: "k" }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16484
375
150