README.md

@cutticat/types

TypeScript type library.

Contents

Overview

This library provides a set of useful TypeScript types for working with strings, objects, nullability, mutability, and HTTP. The types are optimized for strict TypeScript projects and provide compile-time type safety.

Installation

pnpm i @cutticat/types

Quick start

import type {
  ToCamelCase,
  ToSnakeCase,
  DeepReadonly,
  FullyUndefinable,
  PathParams,
} from "@cutticat/types"

// String transformations
type CamelCase = ToCamelCase<"hello-world"> // "helloWorld"
type SnakeCase = ToSnakeCase<"helloWorld">   // "hello_world"

// Working with objects
type ReadonlyConfig = DeepReadonly<{ name: string; age: number }>
type OptionalConfig = FullyUndefinable<{ name: string; age: number }>

// HTTP path parameters
type Params = PathParams<"/users/:id/posts/:postId"> // { id: string; postId: string }

API

Strings

Case conversion:

  • ToCamelCase<S> — converts to camelCase
  • ToSnakeCase<S> — converts to snake_case
  • ToPascalCase<S> — converts to PascalCase
  • ToKebabCase<S> — converts to kebab-case

Prefixes and suffixes:

  • RemovePrefix<T, Prefix> — removes a prefix
  • RemoveSuffix<T, Suffix> — removes a suffix

Utilities:

  • ReplaceAll<S, From, To> — replaces all occurrences of a substring

Objects

  • PrefixKeys<T, Prefix> — adds a prefix to all keys
  • KeysStartingWith<T, Prefix> — keys starting with a prefix
  • Key — any valid object key (string | number | symbol)
  • OwnKey — key type from Reflect.ownKeys(obj) (string | symbol)
  • KeyToOwn<T> — converts Key to OwnKey (numberstring)
  • CleanOmit<T, K>Omit without the string key artifact on objects with an index signature
  • ExcludeFromProperties<T, E> / DeepExcludeFromProperties<T, E> — excludes values from properties
  • IsPlainObject<T> — checks whether a value is a plain object

Nullability (nulls)

  • DeepRequired<T> — all properties are required
  • DeepPartial<T> — all properties are optional
  • DeepNonNullable<T> — recursively removes null and undefined (mirror of DeepNullish<T>)
  • DeepNonNullableRequired<T> — removes null/undefined and makes all properties required
  • Nullish<T> / DeepNullish<T> — nullable properties (null | undefined)
  • Undefinable<T> / DeepUndefinable<T> — properties allow undefined
  • FullyUndefinable<T> / DeepFullyUndefinable<T> — all properties are optional and allow undefined
  • IsOptional<T, K> — property K in T is declared optional
  • HasUndefined<T>undefined is part of the value type
  • CopyOptionalAndUndefined<Source, Target, Keys?> — values from Target by key, copying optionality and undefined from Source

Mutability

  • DeepReadonly<T, LocalExceptions?> — recursively makes all properties readonly
  • DeepWritable<T, LocalExceptions?> — recursively removes readonly
  • ReadonlyDate — Date without mutation methods
  • Immutable, DeepReadonlyExceptions — exception mechanism for DeepReadonly/DeepWritable

HTTP

  • HttpMethod — union of all HTTP methods
  • HttpStatusCode — union of all HTTP status codes
  • PathParams<Path> — extracts :param parameters from a path string

Maybe (optional values)

  • MaybePromise<T> — value may be Promise<T> or synchronous T
  • MaybeArray<T> — value may be an array T[] or a single T

Common

  • UnionToIntersection<Union> — converts a union to an intersection
  • Simplify<T> — simplifies object type display (useful after intersections and conditional types)

Documentation

Detailed documentation:

Full API documentation is available in JSDoc comments. Use IDE autocomplete to browse it.

Requirements

  • Node.js >= 22.0.0
  • pnpm >= 10.17.0
  • TypeScript >= 5.9.0
Описание
TypeScript utility types library
Конвейеры
9 успешных
1 с ошибкой
Разработчики