Typedash Utility Functions

3.3.3 · active · verified Sun Apr 19

Typedash is a modern, type-safe collection of utility functions designed for TypeScript environments, offering a robust alternative to libraries like Lodash with a strong focus on simplicity, tree-shaking, and precise type inference. It currently stands at version 3.3.3 and maintains a fairly active release cadence with frequent minor and patch updates, as evidenced by recent changelog entries. Key differentiators include its complete type-safety, ensuring type-level transformations for string casing functions and precise key/value types for object utilities. The library boasts zero runtime dependencies, making it highly tree-shakeable and performant. It operates on the principle of "trust the compiler" by leveraging TypeScript's robust type system for correctness rather than relying on extensive runtime checks. Typedash provides over 60 utility functions categorized for Array, Object, String, Type Guards, Function, and Math operations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates `typedash`'s core features including `pick` for object property selection, `objectKeys` for precise key inference, `camelCase` for type-level string transformations, and `compact` for array filtering, all with robust TypeScript support.

import { pick, objectKeys, camelCase, compact } from 'typedash';

interface User {
  id: string;
  firstName: string;
  lastName: string;
  email: string;
  isAdmin?: boolean;
  'user-role': string;
}

const userData: User = {
  id: '123',
  firstName: 'John',
  lastName: 'Doe',
  email: 'john.doe@example.com',
  isAdmin: false,
  'user-role': 'admin'
};

// Demonstrate pick for selecting properties with preserved types
const publicInfo = pick(userData, ['id', 'firstName', 'lastName']);
console.log('Public Info:', publicInfo);
// Expected type: { id: string; firstName: string; lastName: string; }

// Demonstrate objectKeys with precise type inference for array of keys
const keys = objectKeys(publicInfo);
console.log('Keys:', keys);
// Expected type: ("id" | "firstName" | "lastName")[]

// Demonstrate camelCase for string literal transformation
const userRoleKey = camelCase(userData['user-role']);
console.log('CamelCased Role Key:', userRoleKey);
// Expected type: "userRole"

// Demonstrate compact for array filtering, inferring non-falsy types
const values = [0, 1, false, '', 'hello', null, undefined];
const compacted = compact(values);
console.log('Compacted Array:', compacted);
// Expected type: (1 | "hello")[]

view raw JSON →