3 дня назад
История
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 camelCaseToSnakeCase<S>— converts to snake_caseToPascalCase<S>— converts to PascalCaseToKebabCase<S>— converts to kebab-case
Prefixes and suffixes:
RemovePrefix<T, Prefix>— removes a prefixRemoveSuffix<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 keysKeysStartingWith<T, Prefix>— keys starting with a prefixKey— any valid object key (string | number | symbol)OwnKey— key type fromReflect.ownKeys(obj)(string | symbol)KeyToOwn<T>— convertsKeytoOwnKey(number→string)CleanOmit<T, K>—Omitwithout thestringkey artifact on objects with an index signatureExcludeFromProperties<T, E>/DeepExcludeFromProperties<T, E>— excludes values from propertiesIsPlainObject<T>— checks whether a value is a plain object
Nullability (nulls)
DeepRequired<T>— all properties are requiredDeepPartial<T>— all properties are optionalDeepNonNullable<T>— recursively removes null and undefined (mirror ofDeepNullish<T>)DeepNonNullableRequired<T>— removes null/undefined and makes all properties requiredNullish<T>/DeepNullish<T>— nullable properties (null | undefined)Undefinable<T>/DeepUndefinable<T>— properties allow undefinedFullyUndefinable<T>/DeepFullyUndefinable<T>— all properties are optional and allow undefinedIsOptional<T, K>— propertyKinTis declared optionalHasUndefined<T>—undefinedis part of the value typeCopyOptionalAndUndefined<Source, Target, Keys?>— values fromTargetby key, copying optionality andundefinedfromSource
Mutability
DeepReadonly<T, LocalExceptions?>— recursively makes all properties readonlyDeepWritable<T, LocalExceptions?>— recursively removes readonlyReadonlyDate— Date without mutation methodsImmutable,DeepReadonlyExceptions— exception mechanism for DeepReadonly/DeepWritable
HTTP
HttpMethod— union of all HTTP methodsHttpStatusCode— union of all HTTP status codesPathParams<Path>— extracts:paramparameters from a path string
Maybe (optional values)
MaybePromise<T>— value may bePromise<T>or synchronousTMaybeArray<T>— value may be an arrayT[]or a singleT
Common
UnionToIntersection<Union>— converts a union to an intersectionSimplify<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
с ошибкой