@blofin/helper
A TypeScript utility library with modular architecture.
Features
- 📦 Modular Architecture: Organized by domain modules
- 🎯 Tree-shaking Support: Import only what you need
- 📚 TypeScript: Full type safety
- 🧪 Jest Testing: Comprehensive test coverage
- 📖 Storybook: Interactive documentation
Installation
pnpm add @blofin/helper
npm install @blofin/helper
yarn add @blofin/helper
Modules
calc
Calculation module using bignumber.js
import { add, subtract, multiply, divide, num } from '@blofin/helper/calc';
add(1, 2);
add(1, 2, 3, 4);
subtract(5, 3);
multiply(2, 3, 4);
divide(10, 2);
num('123.456');
format
Formatting utilities
import {
formatNumber,
displayNumber,
displayCurrency,
displayPercent,
compositeDisplayNumber,
withCurrency,
withThousand
} from '@blofin/helper/format';
formatNumber(123.456, 2);
displayNumber(1234.56, { currency: { symbol: '$' }, thousands: { enabled: true } });
displayCurrency(1234.56, '$');
displayPercent(0.1234);
compositeDisplayNumber(1123.133, displayCurrency, withThousand());
storage
LocalStorage and SessionStorage utilities
import {
getLocalStorage,
setLocalStorage,
removeLocalStorage,
getSessionStorage,
setSessionStorage
} from '@blofin/helper/storage';
setLocalStorage('key', 'value');
const value = getLocalStorage('key');
removeLocalStorage('key');
setSessionStorage('sessionKey', 'sessionValue');
const sessionValue = getSessionStorage('sessionKey');
utils
General utility functions
import { isEmpty, deepClone } from '@blofin/helper/utils';
isEmpty(null);
isEmpty('');
isEmpty([]);
isEmpty({});
deepClone({ a: 1, b: { c: 2 } });
fp
Functional programming utilities
import { compose, pipe, curry, memoize, awaitEither } from '@blofin/helper/fp';
const add = (x: number) => x + 1;
const multiply = (x: number) => x * 2;
const composed = compose(multiply, add);
composed(5);
const piped = pipe(add, multiply);
piped(5);
const addCurried = curry((a: number, b: number) => a + b);
addCurried(1)(2);
const expensiveFn = memoize((n: number) => n * n);
expensiveFn(5);
expensiveFn(5);
ui
UI components (React)
import { Countdown } from '@blofin/helper/ui';
<Countdown target={Date.now() + 60000} />
Usage
Full Import
import * as helper from '@blofin/helper';
helper.calc.add(1, 2);
helper.format.displayNumber(1234.56, { currency: { symbol: '$' } });
helper.utils.isEmpty(null);
helper.storage.setLocalStorage('key', 'value');
Module Import (Recommended)
import { add, multiply } from '@blofin/helper/calc';
import { displayNumber, displayCurrency } from '@blofin/helper/format';
import { isEmpty, deepClone } from '@blofin/helper/utils';
import { compose, pipe } from '@blofin/helper/fp';
This approach enables tree-shaking, so only the imported modules will be bundled.
Development
Setup
pnpm install
Build
pnpm run build
Test
pnpm test
pnpm run test:watch
pnpm run test:coverage
Storybook
pnpm run storybook
Visit http://localhost:6006 to view the documentation.
Build Storybook
pnpm run build-storybook
Project Structure
blofin-helper/
├── src/
│ ├── calc/ # Calculation module
│ ├── format/ # Formatting module
│ ├── storage/ # Storage module
│ ├── utils/ # Utility functions
│ ├── fp/ # Functional programming
│ ├── ui/ # UI components
│ └── index.ts # Main entry point
├── tests/ # Test files
├── stories/ # Storybook stories
├── dist/ # Build output
└── .storybook/ # Storybook configuration
License
MIT