UNPKG

type-fest

Version:

A collection of essential TypeScript types

47 lines (36 loc) • 1.16 kB
import type {DelimiterCasedProperties} from './delimiter-cased-properties.d.ts'; import type {WordsOptions} from './words.d.ts'; import type {SnakeCase} from './snake-case.d.ts'; // For `@link` import type {SnakeCasedPropertiesDeep} from './snake-cased-properties-deep.d.ts'; // For `@link` /** Convert top-level object properties to snake case. This can be useful when, for example, converting some API types from a different style. @see {@link SnakeCase} @see {@link SnakeCasedPropertiesDeep} @example ``` import type {SnakeCasedProperties} from 'type-fest'; type User = { userId: number; userName: string; }; const result: SnakeCasedProperties<User> = { user_id: 1, user_name: 'Tom', }; const splitOnNumbers: SnakeCasedProperties<{line1: string}, {splitOnNumbers: true}> = { 'line_1': 'string', }; const noSplitOnPunctuation: SnakeCasedProperties<{'foo::bar': string}, {splitOnPunctuation: false}> = { 'foo::bar': 'string', }; ``` @category Change case @category Template literal @category Object */ export type SnakeCasedProperties< Value, Options extends WordsOptions = {}, > = DelimiterCasedProperties<Value, '_', Options>; export {};