A TypeScript utility library with modular architecture
npm install @blofin/helperA TypeScript utility library with modular architecture.
- ๐ฆ 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
``bash`
pnpm add @blofin/helperor
npm install @blofin/helperor
yarn add @blofin/helper
`typescript
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 instance
`
`typescript
import {
formatNumber,
displayNumber,
displayCurrency,
displayPercent,
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
displayCurrency(1234.56, '$'); // '$1,234.56'
displayPercent(0.1234); // '12.34%'
// Composite display with function composition
compositeDisplayNumber(1123.133, displayCurrency, withThousand());
// '$1,123.13'
`
`typescript
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');
`
`typescript
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 } }
`
`typescript
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)
`
`typescript
import { Countdown } from '@blofin/helper/ui';
`
`typescript
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');
`
`typescript`
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.
`bash`
pnpm install
`bash`
pnpm run build
`bash`
pnpm test
pnpm run test:watch
pnpm run test:coverage
`bash`
pnpm run storybook
Visit http://localhost:6006 to view the documentation.
`bash`
pnpm run build-storybook
```
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
MIT