From 090e8f01167b98b74d5c3965fb7f7f4b9b8f0277 Mon Sep 17 00:00:00 2001 From: Kuzminov Alexander Date: Thu, 10 Dec 2020 18:11:11 +0300 Subject: [PATCH] docs: add readme --- .github/workflows/release.yml | 1 - readme.md | 128 ++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4bcaf2d..56cbe23 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/readme.md b/readme.md index f72fdf0..559fec5 100644 --- a/readme.md +++ b/readme.md @@ -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) @@ -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; + }; +}>; +```