0.2.0 • Published 3 years ago
@twigaeng/utils v0.2.0
@twigaeng/utils
This is a collection of tiny but useful utilities that we find ourselves using across our frontend clients.
Stack Description
- TypeScript
- Jest
- Prettier
- ESLint
Usage
$ npm install @twigaeng/utils
Available Utilities
Format Date
// usage with default options
import { formatDate } from "@twigaeng/utils";
const formatedDate = formatDate("12-12-2020");
console.log(formatedDate); // Dec 2020
//usage with options
import { formatDate } from "@twigaeng/utils";
const formatedDate = formatDate("12-12-2020", {
weekday: "short",
month: "short",
year: "numeric",
});
console.log(formatedDate); // Dec 2020 Sat
// usage with locale option
import { formatDate } from "@twigaeng/utils";
const formatedDate = formatDate(
"12-12-2020",
{
weekday: "short",
month: "short",
year: "numeric",
},
"de-DE"
);
console.log(formatedDate); // Dez. 2020 Sa
Format Currency
import { formatCurrency } from "@twigaeng/utils";
const currency = formatCurrency(400);
console.log(currency); // KSH 400
// usage with currency option
import { formatCurrency } from "@twigaeng/utils";
const currency = formatCurrency(400, "USD");
console.log(currency); // $400
// usage with currency and locale option
import { formatCurrency } from "@twigaeng/utils";
const currency = formatCurrency("400", "JPY", "ja-JP");
console.log(currency); // ¥400
Features
- Linting via ESLint.
- Run manually via
yarn lint
. - Integrates with Visual Studio Code via vscode-eslint.
- Highlights type & linting issues.
- Provides debuging options for running Jest tests (once and in watch mode).
- Uses AirBNB ESLint plugin as sane defaults.
import ... from ...
statements are verified for correctness via eslint-plugin-import.
- Run manually via
- Formatting via Prettier.
- Run manually via
yarn format
. - Integrates well with Visual Studio Code via prettier-vscode.
- Automatically formats on save.
- Run manually via
Script Commands
yarn test
-- Runs tests.yarn typecheck
-- Checks TypeScript types for correctness. This is disabled during tests for performance reasons.yarn lint
-- Runs linting.yarn format
-- Reformats all of the.ts
and.tsx
files with Prettier.yarn build
-- Regeneratesdist
folder that gets included into NPM module.
License
MIT