@blofin/helper
v0.2.2
Published
A TypeScript utility library with modular architecture
Readme
@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
# or
npm install @blofin/helper
# or
yarn add @blofin/helperModules
calc
Calculation module using bignumber.js
import { add, subtract, multiply, divide, num } from '@blofin/helper/calc';
add(1, 2); // '3'
add(1, 2, 3, 4); // '10'
subtract(5, 3); // '2'
multiply(2, 3, 4); // '24'
divide(10, 2); // '5'
num('123.456'); // BigNumber instanceformat
Formatting utilities
import {
formatNumber,
displayNumber,
useCurrency,
usePercent,
compositeDisplayNumber,
withCurrency,
withThousand
} from '@blofin/helper/format';
// Core number formatting (returns number)
formatNumber(123.456, 2); // 123.46
// Display formatting (returns string)
displayNumber(1234.56, { currency: { symbol: '$' }, thousands: { enabled: true } });
// '$1,234.56'
// Quick entry functions
useCurrency(1234.56, '$'); // '$1,234.56'
usePercent(0.1234); // '12.34%'
// Composite display with function composition
compositeDisplayNumber(1123.133, useCurrency, withThousand());
// '$1,123.13'storage
LocalStorage and SessionStorage utilities
import {
getLocalStorage,
setLocalStorage,
removeLocalStorage,
getSessionStorage,
setSessionStorage
} from '@blofin/helper/storage';
setLocalStorage('key', 'value');
const value = getLocalStorage('key'); // 'value'
removeLocalStorage('key');
setSessionStorage('sessionKey', 'sessionValue');
const sessionValue = getSessionStorage('sessionKey');utils
General utility functions
import { isEmpty, deepClone } from '@blofin/helper/utils';
isEmpty(null); // true
isEmpty(''); // true
isEmpty([]); // true
isEmpty({}); // true
deepClone({ a: 1, b: { c: 2 } }); // { a: 1, b: { c: 2 } }fp
Functional programming utilities
import { compose, pipe, curry, memoize, awaitEither } from '@blofin/helper/fp';
// Compose functions (right to left)
const add = (x: number) => x + 1;
const multiply = (x: number) => x * 2;
const composed = compose(multiply, add);
composed(5); // 12 (5+1 then *2)
// Pipe functions (left to right)
const piped = pipe(add, multiply);
piped(5); // 12 (5+1 then *2)
// Curry
const addCurried = curry((a: number, b: number) => a + b);
addCurried(1)(2); // 3
// Memoize
const expensiveFn = memoize((n: number) => n * n);
expensiveFn(5); // 25 (computed)
expensiveFn(5); // 25 (cached)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); // '3'
helper.format.displayNumber(1234.56, { currency: { symbol: '$' } }); // '$1,234.56'
helper.utils.isEmpty(null); // true
helper.storage.setLocalStorage('key', 'value');Module Import (Recommended)
import { add, multiply } from '@blofin/helper/calc';
import { displayNumber, useCurrency } 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 installBuild
pnpm run buildTest
pnpm test
pnpm run test:watch
pnpm run test:coverageStorybook
pnpm run storybookVisit http://localhost:6006 to view the documentation.
Build Storybook
pnpm run build-storybookProject 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 configurationLicense
MIT
