odgn-ts-helpers
v0.1.0
Published
TypeScript utility helpers for strings, dates, caching, logging, and more
Downloads
86
Maintainers
Readme
odgn-ts-helpers
TypeScript utility helpers for strings, dates, caching, logging, and more. Built with Bun.
Installation
# npm
npm install odgn-ts-helpers
# bun
bun add odgn-ts-helpersUsage
Import specific modules for tree-shaking:
import { slugify, toCamelCase } from 'odgn-ts-helpers/string';
import { createQueryCache } from 'odgn-ts-helpers/cache';
import { trycatch } from 'odgn-ts-helpers/try-catch';Or import everything from the main entry:
import { slugify, createQueryCache, trycatch } from 'odgn-ts-helpers';Modules
boolean
Boolean parsing and type checking utilities.
isBoolean(value)- Type guard for booleanstoBoolean(value)- Convert strings like "true", "yes", "1" to booleansafeParseBoolean(value, defaultValue)- Safely parse with fallback
cache
LRU cache with TTL support for async/sync functions.
createQueryCache()- Create a query cache instance withwrap,invalidate, andclearmethods
date
Date parsing and ISO string utilities.
isDate(value)- Type guard for Date objectstoIsoDateString(value, defaultValue)- Convert to ISO string without milliseconds
diff
Object comparison utilities using deep-object-diff and fast-json-patch.
isObjectEqual(a, b)- Check if two objects are equalgetObjectDiff(a, b)- Get detailed diff between objectscompareObjects(a, b)- Get JSON patch operations between objects
log
Configurable logger with timestamp prefixes.
createLog(prefix, disabled)- Create a logger with optional prefix and disabled log types
number
Number parsing and conversion utilities.
isNumber(value)- Type guard for numberstoInteger(value, defaultValue)- Convert to integer with fallbacktoNumber(value, defaultValue)- Convert to number with fallbacksafeParseInt(value, defaultValue)- Safely parse integersafeParseFloat(value, defaultValue)- Safely parse floatroundNumberToDecimalPlaces(number, places)- Round to decimal places
random
Pseudo-random number generation with seeding support.
prng(seed)- Basic PRNGprngInt(seed),prngDouble(seed),prngBoolean(seed)- Typed random valuesprngIntRange(seed, min, max),prngDoubleRange(seed, min, max)- Random rangesprngShuffle(seed, array)- Seeded array shufflerandomUnsignedInt(min, max)- Random integer in rangedjb2Hash(str)- DJB2 hash function
string
String manipulation and validation utilities.
slugify(str)- Convert to URL-safe slugtoPascalCase(str),toCamelCase(str),toKebabCase(str),toSnakeCase(str)- Case conversionstoCapitalized(str)- Capitalize wordsisString(value)- Type guard for stringsisEmail(value)- Email validation
time
Time constants and utilities.
- Constants:
ONE_SECOND,ONE_MINUTE,FIVE_MINUTES,ONE_HOUR,ONE_DAY, etc. wait(ms)- Promise-based delayrunAfter(ms, fn)- Run function after delaygetTimestamp()- Get formatted timestamp (HH:MM:SS.SSS)
try-catch
Go-style error handling with tuple returns.
trycatch(operation)- Returns[data, null]on success or[null, error]on failure
unique-name
Random name generation.
generateUniqueName()- Generate a unique name like "brave-red-alice"
Development
bun install # Install dependencies
bun test # Run tests
bun run lint # Lint with ESLint
bun run format # Format with Prettier
bun run type-check # TypeScript type checkingLicense
MIT
