Functions for beautify amount of food.
npm i @whisklabs/amounts
import { formatQuantity } from '@whisklabs/amounts';
formatQuantity(100);
const formatQuantity: (quantity: number, unit?: string | undefined) => string;
formatQuantity(12.12, 'tsp') === '12 ⅛';
const formatUnit: (unit: string) => string;
formatUnit('grms') = 'grms';
formatUnit('tbsp') = 'Tbsp';
const formatQtyUnit: (item: { quantity?: number; unit?: string }) => string;
formatQtyUnit({ quantity: 1123.5, unit: 'tsp' }) === '1123 ½ tsp';
const formatFraction: (fraction: string) => string;
formatFraction('1/2') === '½';
const dropZeros: (value: number, decimalPoints?: number) => number;
dropZeros(1.014634, 3) === '1.015';
const getFractions: (value: number) => [number, number, number] | undefined;
getFractions(10.33333333) === [10, 1, 3];
const isFractionalUnit: (unit: string) => boolean;
isFractionalUnit('kg') === false;
isFractionalUnit('tablespoon') === true;
const isCapitalizableUnit: (unit: string) => boolean;
isCapitalizableUnit('kg') === false;
isCapitalizableUnit('tbs') === true;
const isWithoutSpaceUnit: (unit: string) => boolean;
isWithoutSpaceUnit('grms') === false;
isWithoutSpaceUnit('ml') === true;
For convert '1/2' -> '½'
const fractions: {
[key: string]: string;
};
kg, ml, ...
const units: Partial<{
[unit: string]: {
fractional?: true;
withoutSpace?: true;
capitalizable?: true;
};
}>;