Essential developer utilities for your daily coding needs.
npm install tovexFormat numbers with customizable separators and decimal handling.
import { formatNumber } from "tovex";
formatNumber({ value: 1000000 });
// "1,000,000"
formatNumber({ value: 1234.567, decimalScale: 2 });
// "1,234.57"
formatNumber({ value: 100000, thousandsGroupStyle: "lakh" });
// "1,00,000"Configurable logger with log levels and formatting.
import { createLogger } from "tovex";
const logger = createLogger();
logger.info("Application started");
logger.warn("Warning message");
logger.error("Error occurred");
logger.debug("Debug info");Generate unique IDs with customizable options.
import { generateId } from "tovex";
generateId();
generateId({ prefix: "user_" });
generateId({ format: "uuid" });
generateId({ length: 16 });Filter an array of objects by key and optional value.
import { where } from "tovex";
where({ data: users, key: "role", value: "admin" });Shorten long text and append "..." (or custom string).
import { truncate } from "tovex";
truncate("Hello world", 5);Get a new array with duplicate values removed.
import { unique } from "tovex";
unique([1, 1, 2, 3]);
// [1, 2, 3]Pick a random item from an array.
import { randomFromArray } from "tovex";
randomFromArray(["apple", "banana", "orange"]);Pause execution for a given amount of time.
import { sleep } from "tovex";
await sleep(1000);Safely execute an async function without repetitive try/catch blocks.
import { tryCatch } from "tovex";
const [error, result] = await tryCatch(fetchData);Convert seconds into a human-readable duration string.
import { formatDuration } from "tovex";
formatDuration(3661);Format a date into a relative time string.
import { timeAgo } from "tovex";
timeAgo(new Date(Date.now() - 60000));MIT