Skip to content

Commit

Permalink
docs: add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
askuzminov committed Dec 10, 2020
1 parent 01b7a5b commit 090e8f0
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
run: |
npm run check-types
npm run lint
npm run test
- name: Build
run: npm run build
- name: Release GITHUB
Expand Down
128 changes: 128 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
- [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)

<!-- /TOC -->

Expand All @@ -12,8 +26,122 @@

## 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;
};
}>;
```

0 comments on commit 090e8f0

Please sign in to comment.