to-inches
Version:
Convert metric to imperial measurements with fractions
102 lines (86 loc) • 2.81 kB
TypeScript
declare type ClassKey = `${keyof Length}Class`;
declare type Formatter = {
format: (mm: number) => Inch;
};
declare type FractionKey = `${keyof Length}Fraction`;
declare type FractionValue = boolean | number | 'fraction';
export declare class Inch {
#private;
minus: boolean;
miles: number;
yards: number;
feet: number;
inches: number;
fraction: string;
constructor(mm: number, options?: OptionParams);
/**
* Rounds a number to a specified precision.
* If precision greater than 1 or less than 0, it will be treated as a number of decimal places.
* If precision is between 0 and 1, the decimals will be treated as a multiplier.
* Pay attention: to round to 1/4, you should pass 0.4, not 0.25.
* If precision is 0, the number will be rounded down.
* If precision is not specified, the number will be rounded.
* Negative precision can help with rounding integers. For example: round(123456789, -3) returns 123457000.
*/
static round(value: number, precision?: number): number;
/**
* Returns the greatest common divisor of two numbers.
*/
static gcd(a: number, b: number): number;
get mm(): number;
get precise(): Length;
get reminders(): Length;
toString(): string;
toJSON(): {
minus: boolean;
miles: number;
yards: number;
feet: number;
inches: number;
fraction: string;
};
parts(): Array<string | number>;
items(): ItemsData;
html(): string;
}
declare type ItemsData = Array<{
type: string;
value: number;
fraction?: string;
} | {
type: 'sign';
value: string;
}>;
declare interface Length {
miles: number;
yards: number;
feet: number;
inches: number;
}
declare type OptionParams = Omit<Partial<Options>, 'templates'> & {
templates?: Partial<Templates>;
};
declare type Options = Record<FractionKey, FractionValue> & Record<TitleKey | ClassKey, StringValue> & Record<keyof Length, boolean> & {
denominator: number;
input: 'mm' | 'cm' | 'm' | 'km' | 'in' | 'ft' | 'yd' | 'mi';
fractionClass: string | null;
templates: Templates;
};
declare type StringValue = string | null;
declare type Template<I> = {
itemTemplate: I;
fractionTemplate?: string;
minus?: string;
joiner?: string;
};
declare interface Templates {
string: Template<string>;
parts: Template<Array<string>>;
html: Template<string>;
}
declare type TitleKey = `${keyof Length}Title`;
declare function toInches(options: OptionParams): Formatter;
declare function toInches(mm: number, options?: OptionParams): Inch;
export default toInches;
export { toInches }
export { }