Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/whisklabs/amounts
Formatter library for amounts
https://github.com/whisklabs/amounts
Last synced: 2 months ago
JSON representation
Formatter library for amounts
- Host: GitHub
- URL: https://github.com/whisklabs/amounts
- Owner: whisklabs
- License: mit
- Created: 2020-12-10T13:01:16.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-10T16:00:39.000Z (about 4 years ago)
- Last Synced: 2024-11-05T14:06:08.172Z (2 months ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 9
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
- [Whisk formatter library for amounts](#whisk-formatter-library-for-amounts)
- [Description](#description)
- [Install](#install)
- [Usage](#usage)
- [Methods](#methods)
- [Format values](#format-values)
- [Capitalize some unit (tbs, tbsp)](#capitalize-some-unit-tbs-tbsp)
- [Format with unit](#format-with-unit)
- [Get UTF-8 fraction](#get-utf-8-fraction)
- [Round numbers](#round-numbers)
- [Get round of fraction](#get-round-of-fraction)
- [Check unit fraction](#check-unit-fraction)
- [Check unit capitalize](#check-unit-capitalize)
- [Check unit white space](#check-unit-white-space)
- [Constants](#constants)
- [Fractions](#fractions)
- [Units](#units)# Whisk formatter library for amounts
## Description
Functions for beautify amount of food.
## Install
```bash
npm i @whisklabs/amounts
```## Usage
```ts
import { formatQuantity } from '@whisklabs/amounts';formatQuantity(100);
```## Methods
### Format values
```ts
const formatQuantity: (quantity: number, unit?: string | undefined) => string;formatQuantity(12.12, 'tsp') === '12 ⅛';
```### Capitalize some unit (tbs, tbsp)
```ts
const formatUnit: (unit: string) => string;formatUnit('grms') = 'grms';
formatUnit('tbsp') = 'Tbsp';
```### Format with unit
```ts
const formatQtyUnit: (item: { quantity?: number; unit?: string }) => string;formatQtyUnit({ quantity: 1123.5, unit: 'tsp' }) === '1123 ½ tsp';
```### Get UTF-8 fraction
```ts
const formatFraction: (fraction: string) => string;formatFraction('1/2') === '½';
```### Round numbers
```ts
const dropZeros: (value: number, decimalPoints?: number) => number;dropZeros(1.014634, 3) === '1.015';
```### Get round of fraction
```ts
const getFractions: (value: number) => [number, number, number] | undefined;getFractions(10.33333333) === [10, 1, 3];
```### Check unit fraction
```ts
const isFractionalUnit: (unit: string) => boolean;isFractionalUnit('kg') === false;
isFractionalUnit('tablespoon') === true;
```### Check unit capitalize
```ts
const isCapitalizableUnit: (unit: string) => boolean;isCapitalizableUnit('kg') === false;
isCapitalizableUnit('tbs') === true;
```### Check unit white space
```ts
const isWithoutSpaceUnit: (unit: string) => boolean;isWithoutSpaceUnit('grms') === false;
isWithoutSpaceUnit('ml') === true;
```## Constants
### Fractions
For convert '1/2' -> '½'
```ts
const fractions: {
[key: string]: string;
};
```### Units
kg, ml, ...
```ts
const units: Partial<{
[unit: string]: {
fractional?: true;
withoutSpace?: true;
capitalizable?: true;
};
}>;
```