Utility Functions for WorkStudio Platform
npm install @workstudio/utilitiesSmall collection of lightweight TypeScript utility functions used across Workstudio projects.
This package exposes a few focused helpers under src/utils/:
- random — random booleans, integers, floats, UUIDs, and secure strings
- formatter — date and currency formatting helpers
- converter — base64 / URL helpers and a small hashing helper
During development you can import directly from src:
``ts
import { randomUUID, randomString } from './src/utils/random';
import { formatDate, formatCurrency } from './src/utils/formatter';
import { base64Encode, base64Decode } from './src/utils/converter';
console.log(randomUUID());
console.log(formatDate(new Date()));
console.log(base64Encode({ hello: 'world' }));
`
- randomBoolean(probability?: number): boolean — random boolean with optional probability of true (0..1)randomInteger(min?: number, max?: number): number
- — integer in inclusive rangerandomFloat(min?: number, max?: number): number
- — float in [min, max)randomUUID(): string
- — cryptographically generated UUIDrandomString(bytes?: number): string
- — secure hex string (bytes * 2 length)
- formatDate(date, locale?) — formats Date/ISO/timestamp to long human dateformatCurrency(amount, currency?, locale?)
- — formats number as currency
- base64Encode(value) — base64 encode, JSON-stringifies objectsbase64Decode(str)
- — base64 decode and attempt JSON.parse, falls back to stringurlEncode
- / urlDecode — wrappers around encodeURIComponent / decodeURIComponenthash(value, alg?)
- — return hex digest (default sha256)
Run TypeScript checks / build from the package root:
`bash`
pnpm install
pnpm run build
pnpm run build will compile to dist/ using the local tsconfig.json.
Small, well-scoped improvements are welcome. Preferred changes:
- Add unit tests for helpers you modify
- Keep runtime dependencies minimal
MIT — see package.json` for details.