+208
-211
@@ -225,6 +225,3 @@ /** | ||
| */ | ||
| type Repeat<T extends string, times extends number = 0> = All<[ | ||
| IsStringLiteral<T>, | ||
| IsNumberLiteral<times> | ||
| ]> extends true ? times extends 0 ? '' : Math.IsNegative<times> extends false ? Join<TupleOf<times, T>> : never : string; | ||
| type Repeat<T extends string, times extends number = 0> = T extends T ? All<[IsStringLiteral<T>, IsNumberLiteral<times>]> extends true ? times extends 0 ? '' : Math.IsNegative<times> extends false ? Join<TupleOf<times, T>> : never : string : never; | ||
| /** | ||
@@ -308,13 +305,16 @@ * A strongly-typed version of `String.prototype.repeat`. | ||
| /** | ||
| * Trims all whitespaces at the start of a string. | ||
| * T: The string to trim. | ||
| * This function is a strongly-typed counterpart of String.prototype.toLowerCase. | ||
| * @param str the string to make lowercase. | ||
| * @returns the lowercased string. | ||
| * @example toLowerCase('HELLO WORLD') // 'hello world' | ||
| */ | ||
| type TrimStart<T extends string> = T extends ` ${infer rest}` ? TrimStart<rest> : T; | ||
| declare function toLowerCase<T extends string>(str: T): Lowercase<T>; | ||
| /** | ||
| * A strongly-typed version of `String.prototype.trimStart`. | ||
| * @param str the string to trim. | ||
| * @returns the trimmed string in both type level and runtime. | ||
| * @example trimStart(' hello world ') // 'hello world ' | ||
| * This function is a strongly-typed counterpart of String.prototype.toUpperCase. | ||
| * @param str the string to make uppercase. | ||
| * @returns the uppercased string. | ||
| * @example toUpperCase('hello world') // 'HELLO WORLD' | ||
| */ | ||
| declare function trimStart<T extends string>(str: T): TrimStart<T>; | ||
| declare function toUpperCase<T extends string>(str: T): Uppercase<T>; | ||
@@ -335,2 +335,15 @@ /** | ||
| /** | ||
| * Trims all whitespaces at the start of a string. | ||
| * T: The string to trim. | ||
| */ | ||
| type TrimStart<T extends string> = T extends ` ${infer rest}` ? TrimStart<rest> : T; | ||
| /** | ||
| * A strongly-typed version of `String.prototype.trimStart`. | ||
| * @param str the string to trim. | ||
| * @returns the trimmed string in both type level and runtime. | ||
| * @example trimStart(' hello world ') // 'hello world ' | ||
| */ | ||
| declare function trimStart<T extends string>(str: T): TrimStart<T>; | ||
| /** | ||
| * Trims all whitespaces at the start and end of a string. | ||
@@ -348,34 +361,2 @@ * T: The string to trim. | ||
| /** | ||
| * This function is a strongly-typed counterpart of String.prototype.toLowerCase. | ||
| * @param str the string to make lowercase. | ||
| * @returns the lowercased string. | ||
| * @example toLowerCase('HELLO WORLD') // 'hello world' | ||
| */ | ||
| declare function toLowerCase<T extends string>(str: T): Lowercase<T>; | ||
| /** | ||
| * This function is a strongly-typed counterpart of String.prototype.toUpperCase. | ||
| * @param str the string to make uppercase. | ||
| * @returns the uppercased string. | ||
| * @example toUpperCase('hello world') // 'HELLO WORLD' | ||
| */ | ||
| declare function toUpperCase<T extends string>(str: T): Uppercase<T>; | ||
| /** | ||
| * Truncate a string if it's longer than the given maximum length. | ||
| * The last characters of the truncated string are replaced with the omission string which defaults to "...". | ||
| */ | ||
| type Truncate<T extends string, Size extends number, Omission extends string = '...'> = All<[IsStringLiteral<T | Omission>, IsNumberLiteral<Size>]> extends true ? Math.IsNegative<Size> extends true ? Omission : Math.Subtract<Length<T>, Size> extends 0 ? T : Join<[Slice<T, 0, Math.Subtract<Size, Length<Omission>>>, Omission]> : string; | ||
| /** | ||
| * A strongly typed function to truncate a string if it's longer than the given maximum string length. | ||
| * The last characters of the truncated string are replaced with the omission string which defaults to "...". | ||
| * @param sentence the sentence to extract the words from. | ||
| * @param length the maximum length of the string. | ||
| * @param omission the string to append to the end of the truncated string. | ||
| * @returns the truncated string | ||
| * @example truncate('Hello, World', 8) // 'Hello...' | ||
| */ | ||
| declare function truncate<T extends string, S extends number, P extends string = '...'>(sentence: T, length: S, omission?: P): Truncate<T, S, P>; | ||
| type UpperLetters = [ | ||
@@ -452,5 +433,5 @@ 'A', | ||
| */ | ||
| type IsLetter<T extends string> = IsStringLiteral<T> extends true ? T extends Letter ? true : false : boolean; | ||
| type IsLetter<T extends string> = IsStringLiteral<T> extends true ? (T extends Letter ? true : false) : boolean; | ||
| type Digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; | ||
| type Digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; | ||
| type Digit = Digits[number]; | ||
@@ -460,3 +441,3 @@ /** | ||
| */ | ||
| type IsDigit<T extends string> = IsStringLiteral<T> extends true ? T extends Digit ? true : false : boolean; | ||
| type IsDigit<T extends string> = IsStringLiteral<T> extends true ? (T extends Digit ? true : false) : boolean; | ||
@@ -555,2 +536,17 @@ declare const SEPARATORS: readonly ["[", "]", "{", "}", "(", ")", "|", "/", "-", "\\", " ", "_", "."]; | ||
| /** | ||
| * Shallowly transforms the keys of a Record to camelCase. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type CamelKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as CamelCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly transforms the keys of an object to camelCase. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example camelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { 'fizz-buz': true } } | ||
| */ | ||
| declare function camelKeys<T>(obj: T): CamelKeys<T>; | ||
| /** | ||
| * Transforms a string with the specified separator (delimiter). | ||
@@ -593,2 +589,70 @@ */ | ||
| /** | ||
| * Shallowly transforms the keys of a Record to CONSTANT_CASE. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type ConstantKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as ConstantCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly transforms the keys of an object to CONSTANT_CASE. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example constantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { 'fizz-buzz': true } } | ||
| */ | ||
| declare function constantKeys<T>(obj: T): ConstantKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to camelCase. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepCamelKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepCamelKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepCamelKeys<V>[] : { | ||
| [K in keyof T as CamelCase<Extract<K, string>>]: DeepCamelKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to camelCase. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepCamelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { fizzBuzz: true } } | ||
| */ | ||
| declare function deepCamelKeys<T>(obj: T): DeepCamelKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to CONSTANT_CASE. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepConstantKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepConstantKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepConstantKeys<V>[] : { | ||
| [K in keyof T as ConstantCase<Extract<K, string>>]: DeepConstantKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to CONSTANT_CASE. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepConstantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { FIZZ_BUZZ: true } } | ||
| */ | ||
| declare function deepConstantKeys<T>(obj: T): DeepConstantKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to a custom delimiter case. | ||
| * T: the type of the Record to transform. | ||
| * D: the delimiter to use. | ||
| */ | ||
| type DeepDelimiterKeys<T, D extends string> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepDelimiterKeys<T[I], D>; | ||
| } : T extends (infer V)[] ? DeepDelimiterKeys<V, D>[] : { | ||
| [K in keyof T as DelimiterCase<Extract<K, string>, D>]: DeepDelimiterKeys<T[K], D>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to a custom delimiter case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @param delimiter the delimiter to use. | ||
| * @returns the transformed object. | ||
| * @example deepDelimiterKeys({ 'foo-bar': { 'fizz-buzz': true } }, '.') // { 'foo.bar': { 'fizz.buzz': true } } | ||
| */ | ||
| declare function deepDelimiterKeys<T, D extends string>(obj: T, delimiter: D): DeepDelimiterKeys<T, D>; | ||
| /** | ||
| * Transforms a string to kebab-case. | ||
@@ -612,2 +676,36 @@ */ | ||
| /** | ||
| * Recursively transforms the keys of a Record to kebab-case. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepKebabKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepKebabKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepKebabKeys<V>[] : { | ||
| [K in keyof T as KebabCase<Extract<K, string>>]: DeepKebabKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to kebab-case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepKebabKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo-bar': { 'fizz-buzz': true } } | ||
| */ | ||
| declare function deepKebabKeys<T>(obj: T): DeepKebabKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to PascalCase. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepPascalKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepPascalKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepPascalKeys<V>[] : { | ||
| [K in keyof T as PascalCase<Extract<K, string>>]: DeepPascalKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to pascal case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepPascalKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FooBar: { FizzBuzz: true } } | ||
| */ | ||
| declare function deepPascalKeys<T>(obj: T): DeepPascalKeys<T>; | ||
| /** | ||
| * Transforms a string to snake_case. | ||
@@ -631,80 +729,28 @@ */ | ||
| /** | ||
| * Transforms a string to "Title Case". | ||
| */ | ||
| type TitleCase<T extends string> = DelimiterCase<PascalCase<T>, ' '>; | ||
| /** | ||
| * A strongly typed version of `titleCase` that works in both runtime and type level. | ||
| * @param str the string to convert to title case. | ||
| * @returns the title cased string. | ||
| * @example titleCase('hello world') // 'Hello World' | ||
| */ | ||
| declare function titleCase<T extends string>(str: T): TitleCase<T>; | ||
| /** | ||
| * @deprecated | ||
| * Use `titleCase` instead. | ||
| * Read more about the deprecation [here](https://github.com/gustavoguichard/string-ts/issues/44). | ||
| */ | ||
| declare const toTitleCase: typeof titleCase; | ||
| /** | ||
| * Capitalizes the first letter of a string. This is a runtime counterpart of `Capitalize<T>` from `src/types.d.ts`. | ||
| * @param str the string to capitalize. | ||
| * @returns the capitalized string. | ||
| * @example capitalize('hello world') // 'Hello world' | ||
| */ | ||
| declare function capitalize<T extends string>(str: T): Capitalize<T>; | ||
| /** | ||
| * A strongly-typed version of `lowerCase` that works in both runtime and type level. | ||
| * @param str the string to convert to lower case. | ||
| * @returns the lowercased string. | ||
| * @example lowerCase('HELLO-WORLD') // 'hello world' | ||
| */ | ||
| declare function lowerCase<T extends string>(str: T): Lowercase<DelimiterCase<T, ' '>>; | ||
| /** | ||
| * Uncapitalizes the first letter of a string. This is a runtime counterpart of `Uncapitalize<T>` from `src/types.d.ts`. | ||
| * @param str the string to uncapitalize. | ||
| * @returns the uncapitalized string. | ||
| * @example uncapitalize('Hello world') // 'hello world' | ||
| */ | ||
| declare function uncapitalize<T extends string>(str: T): Uncapitalize<T>; | ||
| /** | ||
| * A strongly-typed version of `upperCase` that works in both runtime and type level. | ||
| * @param str the string to convert to upper case. | ||
| * @returns the uppercased string. | ||
| * @example upperCase('hello-world') // 'HELLO WORLD' | ||
| */ | ||
| declare function upperCase<T extends string>(str: T): Uppercase<DelimiterCase<T, ' '>>; | ||
| /** | ||
| * Shallowly transforms the keys of a Record to camelCase. | ||
| * Recursively transforms the keys of a Record to snake_case. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type CamelKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as CamelCase<Extract<K, string>>]: T[K]; | ||
| type DeepSnakeKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepSnakeKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepSnakeKeys<V>[] : { | ||
| [K in keyof T as SnakeCase<Extract<K, string>>]: DeepSnakeKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly transforms the keys of an object to camelCase. The transformation is done both at runtime and type level. | ||
| * A strongly typed function that recursively transforms the keys of an object to snake_case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example camelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { 'fizz-buz': true } } | ||
| * @example deepSnakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz_buzz': true } } | ||
| */ | ||
| declare function camelKeys<T>(obj: T): CamelKeys<T>; | ||
| declare function deepSnakeKeys<T>(obj: T): DeepSnakeKeys<T>; | ||
| /** | ||
| * Shallowly transforms the keys of a Record to CONSTANT_CASE. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type ConstantKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as ConstantCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly transforms the keys of an object to CONSTANT_CASE. The transformation is done both at runtime and type level. | ||
| * This function is used to transform the keys of an object deeply. | ||
| * It will only be transformed at runtime, so it's not type safe. | ||
| * @param obj the object to transform. | ||
| * @param transform the function to transform the keys from string to string. | ||
| * @returns the transformed object. | ||
| * @example constantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { 'fizz-buzz': true } } | ||
| * @example deepTransformKeys({ 'foo-bar': { 'fizz-buzz': true } }, camelCase) | ||
| * // { fooBar: { fizzBuzz: true } } | ||
| */ | ||
| declare function constantKeys<T>(obj: T): ConstantKeys<T>; | ||
| declare function deepTransformKeys<T>(obj: T, transform: (s: string) => string): T; | ||
@@ -759,17 +805,2 @@ /** | ||
| /** | ||
| * Shallowly transforms the keys of a Record to snake_case. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type SnakeKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as SnakeCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly the keys of an object to snake_case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example snakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz-buzz': true } } | ||
| */ | ||
| declare function snakeKeys<T>(obj: T): SnakeKeys<T>; | ||
| /** | ||
| * Shallowly transforms the keys of a Record with `replace`. | ||
@@ -792,116 +823,82 @@ * T: the type of the Record to transform. | ||
| /** | ||
| * Recursively transforms the keys of a Record to camelCase. | ||
| * Shallowly transforms the keys of a Record to snake_case. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepCamelKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepCamelKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepCamelKeys<V>[] : { | ||
| [K in keyof T as CamelCase<Extract<K, string>>]: DeepCamelKeys<T[K]>; | ||
| type SnakeKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as SnakeCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to camelCase. The transformation is done both at runtime and type level. | ||
| * A strongly typed function that shallowly the keys of an object to snake_case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepCamelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { fizzBuzz: true } } | ||
| * @example snakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz-buzz': true } } | ||
| */ | ||
| declare function deepCamelKeys<T>(obj: T): DeepCamelKeys<T>; | ||
| declare function snakeKeys<T>(obj: T): SnakeKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to CONSTANT_CASE. | ||
| * T: the type of the Record to transform. | ||
| * Truncate a string if it's longer than the given maximum length. | ||
| * The last characters of the truncated string are replaced with the omission string which defaults to "...". | ||
| */ | ||
| type DeepConstantKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepConstantKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepConstantKeys<V>[] : { | ||
| [K in keyof T as ConstantCase<Extract<K, string>>]: DeepConstantKeys<T[K]>; | ||
| }; | ||
| type Truncate<T extends string, Size extends number, Omission extends string = '...'> = All<[IsStringLiteral<T | Omission>, IsNumberLiteral<Size>]> extends true ? Math.IsNegative<Size> extends true ? Omission : Math.Subtract<Length<T>, Size> extends 0 ? T : Join<[Slice<T, 0, Math.Subtract<Size, Length<Omission>>>, Omission]> : string; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to CONSTANT_CASE. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepConstantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { FIZZ_BUZZ: true } } | ||
| * A strongly typed function to truncate a string if it's longer than the given maximum string length. | ||
| * The last characters of the truncated string are replaced with the omission string which defaults to "...". | ||
| * @param sentence the sentence to extract the words from. | ||
| * @param length the maximum length of the string. | ||
| * @param omission the string to append to the end of the truncated string. | ||
| * @returns the truncated string | ||
| * @example truncate('Hello, World', 8) // 'Hello...' | ||
| */ | ||
| declare function deepConstantKeys<T>(obj: T): DeepConstantKeys<T>; | ||
| declare function truncate<T extends string, S extends number, P extends string = '...'>(sentence: T, length: S, omission?: P): Truncate<T, S, P>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to a custom delimiter case. | ||
| * T: the type of the Record to transform. | ||
| * D: the delimiter to use. | ||
| * Capitalizes the first letter of a string. This is a runtime counterpart of `Capitalize<T>` from `src/types.d.ts`. | ||
| * @param str the string to capitalize. | ||
| * @returns the capitalized string. | ||
| * @example capitalize('hello world') // 'Hello world' | ||
| */ | ||
| type DeepDelimiterKeys<T, D extends string> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepDelimiterKeys<T[I], D>; | ||
| } : T extends (infer V)[] ? DeepDelimiterKeys<V, D>[] : { | ||
| [K in keyof T as DelimiterCase<Extract<K, string>, D>]: DeepDelimiterKeys<T[K], D>; | ||
| }; | ||
| declare function capitalize<T extends string>(str: T): Capitalize<T>; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to a custom delimiter case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @param delimiter the delimiter to use. | ||
| * @returns the transformed object. | ||
| * @example deepDelimiterKeys({ 'foo-bar': { 'fizz-buzz': true } }, '.') // { 'foo.bar': { 'fizz.buzz': true } } | ||
| * A strongly-typed version of `lowerCase` that works in both runtime and type level. | ||
| * @param str the string to convert to lower case. | ||
| * @returns the lowercased string. | ||
| * @example lowerCase('HELLO-WORLD') // 'hello world' | ||
| */ | ||
| declare function deepDelimiterKeys<T, D extends string>(obj: T, delimiter: D): DeepDelimiterKeys<T, D>; | ||
| declare function lowerCase<T extends string>(str: T): Lowercase<DelimiterCase<T, ' '>>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to kebab-case. | ||
| * T: the type of the Record to transform. | ||
| * Transforms a string to "Title Case". | ||
| */ | ||
| type DeepKebabKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepKebabKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepKebabKeys<V>[] : { | ||
| [K in keyof T as KebabCase<Extract<K, string>>]: DeepKebabKeys<T[K]>; | ||
| }; | ||
| type TitleCase<T extends string> = DelimiterCase<PascalCase<T>, ' '>; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to kebab-case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepKebabKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo-bar': { 'fizz-buzz': true } } | ||
| * A strongly typed version of `titleCase` that works in both runtime and type level. | ||
| * @param str the string to convert to title case. | ||
| * @returns the title cased string. | ||
| * @example titleCase('hello world') // 'Hello World' | ||
| */ | ||
| declare function deepKebabKeys<T>(obj: T): DeepKebabKeys<T>; | ||
| declare function titleCase<T extends string>(str: T): TitleCase<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to PascalCase. | ||
| * T: the type of the Record to transform. | ||
| * @deprecated | ||
| * Use `titleCase` instead. | ||
| * Read more about the deprecation [here](https://github.com/gustavoguichard/string-ts/issues/44). | ||
| */ | ||
| type DeepPascalKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepPascalKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepPascalKeys<V>[] : { | ||
| [K in keyof T as PascalCase<Extract<K, string>>]: DeepPascalKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to pascal case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepPascalKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FooBar: { FizzBuzz: true } } | ||
| */ | ||
| declare function deepPascalKeys<T>(obj: T): DeepPascalKeys<T>; | ||
| declare const toTitleCase: typeof titleCase; | ||
| /** | ||
| * Recursively transforms the keys of a Record to snake_case. | ||
| * T: the type of the Record to transform. | ||
| * Uncapitalizes the first letter of a string. This is a runtime counterpart of `Uncapitalize<T>` from `src/types.d.ts`. | ||
| * @param str the string to uncapitalize. | ||
| * @returns the uncapitalized string. | ||
| * @example uncapitalize('Hello world') // 'hello world' | ||
| */ | ||
| type DeepSnakeKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepSnakeKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepSnakeKeys<V>[] : { | ||
| [K in keyof T as SnakeCase<Extract<K, string>>]: DeepSnakeKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to snake_case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepSnakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz_buzz': true } } | ||
| */ | ||
| declare function deepSnakeKeys<T>(obj: T): DeepSnakeKeys<T>; | ||
| declare function uncapitalize<T extends string>(str: T): Uncapitalize<T>; | ||
| /** | ||
| * This function is used to transform the keys of an object deeply. | ||
| * It will only be transformed at runtime, so it's not type safe. | ||
| * @param obj the object to transform. | ||
| * @param transform the function to transform the keys from string to string. | ||
| * @returns the transformed object. | ||
| * @example deepTransformKeys({ 'foo-bar': { 'fizz-buzz': true } }, camelCase) | ||
| * // { fooBar: { fizzBuzz: true } } | ||
| * A strongly-typed version of `upperCase` that works in both runtime and type level. | ||
| * @param str the string to convert to upper case. | ||
| * @returns the uppercased string. | ||
| * @example upperCase('hello-world') // 'HELLO WORLD' | ||
| */ | ||
| declare function deepTransformKeys<T>(obj: T, transform: (s: string) => string): T; | ||
| declare function upperCase<T extends string>(str: T): Uppercase<DelimiterCase<T, ' '>>; | ||
| export { type CamelCase, type CamelKeys, type CharAt, type Concat, type ConstantCase, type ConstantKeys, type DeepCamelKeys, type DeepConstantKeys, type DeepDelimiterKeys, type DeepKebabKeys, type DeepPascalKeys, type DeepSnakeKeys, type DelimiterCase, type DelimiterKeys, type Digit, type Digits, type EndsWith, type Includes, type IsDigit, type IsLetter, type IsLower, type IsSeparator, type IsSpecial, type IsUpper, type Join, type KebabCase, type KebabKeys, type Length, type Letter, type Letters, type LowerLetter, type LowerLetters, type PadEnd, type PadStart, type PascalCase, type PascalKeys, type Repeat, type Replace, type ReplaceAll, type ReplaceKeys, type Reverse, type Separator, type Separators, type Slice, type SnakeCase, type SnakeKeys, type Split, type StartsWith, type TitleCase, type Trim, type TrimEnd, type TrimStart, type Truncate, type UpperLetter, type UpperLetters, type Words, camelCase, camelKeys, capitalize, charAt, concat, constantCase, constantKeys, deepCamelKeys, deepConstantKeys, deepDelimiterKeys, deepKebabKeys, deepPascalKeys, deepSnakeKeys, deepTransformKeys, delimiterCase, delimiterKeys, endsWith, includes, join, kebabCase, kebabKeys, length, lowerCase, padEnd, padStart, pascalCase, pascalKeys, repeat, replace, replaceAll, replaceKeys, reverse, slice, snakeCase, snakeKeys, split, startsWith, titleCase, toCamelCase, toConstantCase, toDelimiterCase, toKebabCase, toLowerCase, toPascalCase, toSnakeCase, toTitleCase, toUpperCase, trim, trimEnd, trimStart, truncate, uncapitalize, upperCase, words }; |
+208
-211
@@ -225,6 +225,3 @@ /** | ||
| */ | ||
| type Repeat<T extends string, times extends number = 0> = All<[ | ||
| IsStringLiteral<T>, | ||
| IsNumberLiteral<times> | ||
| ]> extends true ? times extends 0 ? '' : Math.IsNegative<times> extends false ? Join<TupleOf<times, T>> : never : string; | ||
| type Repeat<T extends string, times extends number = 0> = T extends T ? All<[IsStringLiteral<T>, IsNumberLiteral<times>]> extends true ? times extends 0 ? '' : Math.IsNegative<times> extends false ? Join<TupleOf<times, T>> : never : string : never; | ||
| /** | ||
@@ -308,13 +305,16 @@ * A strongly-typed version of `String.prototype.repeat`. | ||
| /** | ||
| * Trims all whitespaces at the start of a string. | ||
| * T: The string to trim. | ||
| * This function is a strongly-typed counterpart of String.prototype.toLowerCase. | ||
| * @param str the string to make lowercase. | ||
| * @returns the lowercased string. | ||
| * @example toLowerCase('HELLO WORLD') // 'hello world' | ||
| */ | ||
| type TrimStart<T extends string> = T extends ` ${infer rest}` ? TrimStart<rest> : T; | ||
| declare function toLowerCase<T extends string>(str: T): Lowercase<T>; | ||
| /** | ||
| * A strongly-typed version of `String.prototype.trimStart`. | ||
| * @param str the string to trim. | ||
| * @returns the trimmed string in both type level and runtime. | ||
| * @example trimStart(' hello world ') // 'hello world ' | ||
| * This function is a strongly-typed counterpart of String.prototype.toUpperCase. | ||
| * @param str the string to make uppercase. | ||
| * @returns the uppercased string. | ||
| * @example toUpperCase('hello world') // 'HELLO WORLD' | ||
| */ | ||
| declare function trimStart<T extends string>(str: T): TrimStart<T>; | ||
| declare function toUpperCase<T extends string>(str: T): Uppercase<T>; | ||
@@ -335,2 +335,15 @@ /** | ||
| /** | ||
| * Trims all whitespaces at the start of a string. | ||
| * T: The string to trim. | ||
| */ | ||
| type TrimStart<T extends string> = T extends ` ${infer rest}` ? TrimStart<rest> : T; | ||
| /** | ||
| * A strongly-typed version of `String.prototype.trimStart`. | ||
| * @param str the string to trim. | ||
| * @returns the trimmed string in both type level and runtime. | ||
| * @example trimStart(' hello world ') // 'hello world ' | ||
| */ | ||
| declare function trimStart<T extends string>(str: T): TrimStart<T>; | ||
| /** | ||
| * Trims all whitespaces at the start and end of a string. | ||
@@ -348,34 +361,2 @@ * T: The string to trim. | ||
| /** | ||
| * This function is a strongly-typed counterpart of String.prototype.toLowerCase. | ||
| * @param str the string to make lowercase. | ||
| * @returns the lowercased string. | ||
| * @example toLowerCase('HELLO WORLD') // 'hello world' | ||
| */ | ||
| declare function toLowerCase<T extends string>(str: T): Lowercase<T>; | ||
| /** | ||
| * This function is a strongly-typed counterpart of String.prototype.toUpperCase. | ||
| * @param str the string to make uppercase. | ||
| * @returns the uppercased string. | ||
| * @example toUpperCase('hello world') // 'HELLO WORLD' | ||
| */ | ||
| declare function toUpperCase<T extends string>(str: T): Uppercase<T>; | ||
| /** | ||
| * Truncate a string if it's longer than the given maximum length. | ||
| * The last characters of the truncated string are replaced with the omission string which defaults to "...". | ||
| */ | ||
| type Truncate<T extends string, Size extends number, Omission extends string = '...'> = All<[IsStringLiteral<T | Omission>, IsNumberLiteral<Size>]> extends true ? Math.IsNegative<Size> extends true ? Omission : Math.Subtract<Length<T>, Size> extends 0 ? T : Join<[Slice<T, 0, Math.Subtract<Size, Length<Omission>>>, Omission]> : string; | ||
| /** | ||
| * A strongly typed function to truncate a string if it's longer than the given maximum string length. | ||
| * The last characters of the truncated string are replaced with the omission string which defaults to "...". | ||
| * @param sentence the sentence to extract the words from. | ||
| * @param length the maximum length of the string. | ||
| * @param omission the string to append to the end of the truncated string. | ||
| * @returns the truncated string | ||
| * @example truncate('Hello, World', 8) // 'Hello...' | ||
| */ | ||
| declare function truncate<T extends string, S extends number, P extends string = '...'>(sentence: T, length: S, omission?: P): Truncate<T, S, P>; | ||
| type UpperLetters = [ | ||
@@ -452,5 +433,5 @@ 'A', | ||
| */ | ||
| type IsLetter<T extends string> = IsStringLiteral<T> extends true ? T extends Letter ? true : false : boolean; | ||
| type IsLetter<T extends string> = IsStringLiteral<T> extends true ? (T extends Letter ? true : false) : boolean; | ||
| type Digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; | ||
| type Digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; | ||
| type Digit = Digits[number]; | ||
@@ -460,3 +441,3 @@ /** | ||
| */ | ||
| type IsDigit<T extends string> = IsStringLiteral<T> extends true ? T extends Digit ? true : false : boolean; | ||
| type IsDigit<T extends string> = IsStringLiteral<T> extends true ? (T extends Digit ? true : false) : boolean; | ||
@@ -555,2 +536,17 @@ declare const SEPARATORS: readonly ["[", "]", "{", "}", "(", ")", "|", "/", "-", "\\", " ", "_", "."]; | ||
| /** | ||
| * Shallowly transforms the keys of a Record to camelCase. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type CamelKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as CamelCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly transforms the keys of an object to camelCase. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example camelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { 'fizz-buz': true } } | ||
| */ | ||
| declare function camelKeys<T>(obj: T): CamelKeys<T>; | ||
| /** | ||
| * Transforms a string with the specified separator (delimiter). | ||
@@ -593,2 +589,70 @@ */ | ||
| /** | ||
| * Shallowly transforms the keys of a Record to CONSTANT_CASE. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type ConstantKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as ConstantCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly transforms the keys of an object to CONSTANT_CASE. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example constantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { 'fizz-buzz': true } } | ||
| */ | ||
| declare function constantKeys<T>(obj: T): ConstantKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to camelCase. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepCamelKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepCamelKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepCamelKeys<V>[] : { | ||
| [K in keyof T as CamelCase<Extract<K, string>>]: DeepCamelKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to camelCase. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepCamelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { fizzBuzz: true } } | ||
| */ | ||
| declare function deepCamelKeys<T>(obj: T): DeepCamelKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to CONSTANT_CASE. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepConstantKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepConstantKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepConstantKeys<V>[] : { | ||
| [K in keyof T as ConstantCase<Extract<K, string>>]: DeepConstantKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to CONSTANT_CASE. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepConstantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { FIZZ_BUZZ: true } } | ||
| */ | ||
| declare function deepConstantKeys<T>(obj: T): DeepConstantKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to a custom delimiter case. | ||
| * T: the type of the Record to transform. | ||
| * D: the delimiter to use. | ||
| */ | ||
| type DeepDelimiterKeys<T, D extends string> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepDelimiterKeys<T[I], D>; | ||
| } : T extends (infer V)[] ? DeepDelimiterKeys<V, D>[] : { | ||
| [K in keyof T as DelimiterCase<Extract<K, string>, D>]: DeepDelimiterKeys<T[K], D>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to a custom delimiter case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @param delimiter the delimiter to use. | ||
| * @returns the transformed object. | ||
| * @example deepDelimiterKeys({ 'foo-bar': { 'fizz-buzz': true } }, '.') // { 'foo.bar': { 'fizz.buzz': true } } | ||
| */ | ||
| declare function deepDelimiterKeys<T, D extends string>(obj: T, delimiter: D): DeepDelimiterKeys<T, D>; | ||
| /** | ||
| * Transforms a string to kebab-case. | ||
@@ -612,2 +676,36 @@ */ | ||
| /** | ||
| * Recursively transforms the keys of a Record to kebab-case. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepKebabKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepKebabKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepKebabKeys<V>[] : { | ||
| [K in keyof T as KebabCase<Extract<K, string>>]: DeepKebabKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to kebab-case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepKebabKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo-bar': { 'fizz-buzz': true } } | ||
| */ | ||
| declare function deepKebabKeys<T>(obj: T): DeepKebabKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to PascalCase. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepPascalKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepPascalKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepPascalKeys<V>[] : { | ||
| [K in keyof T as PascalCase<Extract<K, string>>]: DeepPascalKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to pascal case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepPascalKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FooBar: { FizzBuzz: true } } | ||
| */ | ||
| declare function deepPascalKeys<T>(obj: T): DeepPascalKeys<T>; | ||
| /** | ||
| * Transforms a string to snake_case. | ||
@@ -631,80 +729,28 @@ */ | ||
| /** | ||
| * Transforms a string to "Title Case". | ||
| */ | ||
| type TitleCase<T extends string> = DelimiterCase<PascalCase<T>, ' '>; | ||
| /** | ||
| * A strongly typed version of `titleCase` that works in both runtime and type level. | ||
| * @param str the string to convert to title case. | ||
| * @returns the title cased string. | ||
| * @example titleCase('hello world') // 'Hello World' | ||
| */ | ||
| declare function titleCase<T extends string>(str: T): TitleCase<T>; | ||
| /** | ||
| * @deprecated | ||
| * Use `titleCase` instead. | ||
| * Read more about the deprecation [here](https://github.com/gustavoguichard/string-ts/issues/44). | ||
| */ | ||
| declare const toTitleCase: typeof titleCase; | ||
| /** | ||
| * Capitalizes the first letter of a string. This is a runtime counterpart of `Capitalize<T>` from `src/types.d.ts`. | ||
| * @param str the string to capitalize. | ||
| * @returns the capitalized string. | ||
| * @example capitalize('hello world') // 'Hello world' | ||
| */ | ||
| declare function capitalize<T extends string>(str: T): Capitalize<T>; | ||
| /** | ||
| * A strongly-typed version of `lowerCase` that works in both runtime and type level. | ||
| * @param str the string to convert to lower case. | ||
| * @returns the lowercased string. | ||
| * @example lowerCase('HELLO-WORLD') // 'hello world' | ||
| */ | ||
| declare function lowerCase<T extends string>(str: T): Lowercase<DelimiterCase<T, ' '>>; | ||
| /** | ||
| * Uncapitalizes the first letter of a string. This is a runtime counterpart of `Uncapitalize<T>` from `src/types.d.ts`. | ||
| * @param str the string to uncapitalize. | ||
| * @returns the uncapitalized string. | ||
| * @example uncapitalize('Hello world') // 'hello world' | ||
| */ | ||
| declare function uncapitalize<T extends string>(str: T): Uncapitalize<T>; | ||
| /** | ||
| * A strongly-typed version of `upperCase` that works in both runtime and type level. | ||
| * @param str the string to convert to upper case. | ||
| * @returns the uppercased string. | ||
| * @example upperCase('hello-world') // 'HELLO WORLD' | ||
| */ | ||
| declare function upperCase<T extends string>(str: T): Uppercase<DelimiterCase<T, ' '>>; | ||
| /** | ||
| * Shallowly transforms the keys of a Record to camelCase. | ||
| * Recursively transforms the keys of a Record to snake_case. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type CamelKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as CamelCase<Extract<K, string>>]: T[K]; | ||
| type DeepSnakeKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepSnakeKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepSnakeKeys<V>[] : { | ||
| [K in keyof T as SnakeCase<Extract<K, string>>]: DeepSnakeKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly transforms the keys of an object to camelCase. The transformation is done both at runtime and type level. | ||
| * A strongly typed function that recursively transforms the keys of an object to snake_case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example camelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { 'fizz-buz': true } } | ||
| * @example deepSnakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz_buzz': true } } | ||
| */ | ||
| declare function camelKeys<T>(obj: T): CamelKeys<T>; | ||
| declare function deepSnakeKeys<T>(obj: T): DeepSnakeKeys<T>; | ||
| /** | ||
| * Shallowly transforms the keys of a Record to CONSTANT_CASE. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type ConstantKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as ConstantCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly transforms the keys of an object to CONSTANT_CASE. The transformation is done both at runtime and type level. | ||
| * This function is used to transform the keys of an object deeply. | ||
| * It will only be transformed at runtime, so it's not type safe. | ||
| * @param obj the object to transform. | ||
| * @param transform the function to transform the keys from string to string. | ||
| * @returns the transformed object. | ||
| * @example constantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { 'fizz-buzz': true } } | ||
| * @example deepTransformKeys({ 'foo-bar': { 'fizz-buzz': true } }, camelCase) | ||
| * // { fooBar: { fizzBuzz: true } } | ||
| */ | ||
| declare function constantKeys<T>(obj: T): ConstantKeys<T>; | ||
| declare function deepTransformKeys<T>(obj: T, transform: (s: string) => string): T; | ||
@@ -759,17 +805,2 @@ /** | ||
| /** | ||
| * Shallowly transforms the keys of a Record to snake_case. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type SnakeKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as SnakeCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that shallowly the keys of an object to snake_case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example snakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz-buzz': true } } | ||
| */ | ||
| declare function snakeKeys<T>(obj: T): SnakeKeys<T>; | ||
| /** | ||
| * Shallowly transforms the keys of a Record with `replace`. | ||
@@ -792,116 +823,82 @@ * T: the type of the Record to transform. | ||
| /** | ||
| * Recursively transforms the keys of a Record to camelCase. | ||
| * Shallowly transforms the keys of a Record to snake_case. | ||
| * T: the type of the Record to transform. | ||
| */ | ||
| type DeepCamelKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepCamelKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepCamelKeys<V>[] : { | ||
| [K in keyof T as CamelCase<Extract<K, string>>]: DeepCamelKeys<T[K]>; | ||
| type SnakeKeys<T> = T extends [] ? T : { | ||
| [K in keyof T as SnakeCase<Extract<K, string>>]: T[K]; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to camelCase. The transformation is done both at runtime and type level. | ||
| * A strongly typed function that shallowly the keys of an object to snake_case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepCamelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { fizzBuzz: true } } | ||
| * @example snakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz-buzz': true } } | ||
| */ | ||
| declare function deepCamelKeys<T>(obj: T): DeepCamelKeys<T>; | ||
| declare function snakeKeys<T>(obj: T): SnakeKeys<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to CONSTANT_CASE. | ||
| * T: the type of the Record to transform. | ||
| * Truncate a string if it's longer than the given maximum length. | ||
| * The last characters of the truncated string are replaced with the omission string which defaults to "...". | ||
| */ | ||
| type DeepConstantKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepConstantKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepConstantKeys<V>[] : { | ||
| [K in keyof T as ConstantCase<Extract<K, string>>]: DeepConstantKeys<T[K]>; | ||
| }; | ||
| type Truncate<T extends string, Size extends number, Omission extends string = '...'> = All<[IsStringLiteral<T | Omission>, IsNumberLiteral<Size>]> extends true ? Math.IsNegative<Size> extends true ? Omission : Math.Subtract<Length<T>, Size> extends 0 ? T : Join<[Slice<T, 0, Math.Subtract<Size, Length<Omission>>>, Omission]> : string; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to CONSTANT_CASE. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepConstantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { FIZZ_BUZZ: true } } | ||
| * A strongly typed function to truncate a string if it's longer than the given maximum string length. | ||
| * The last characters of the truncated string are replaced with the omission string which defaults to "...". | ||
| * @param sentence the sentence to extract the words from. | ||
| * @param length the maximum length of the string. | ||
| * @param omission the string to append to the end of the truncated string. | ||
| * @returns the truncated string | ||
| * @example truncate('Hello, World', 8) // 'Hello...' | ||
| */ | ||
| declare function deepConstantKeys<T>(obj: T): DeepConstantKeys<T>; | ||
| declare function truncate<T extends string, S extends number, P extends string = '...'>(sentence: T, length: S, omission?: P): Truncate<T, S, P>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to a custom delimiter case. | ||
| * T: the type of the Record to transform. | ||
| * D: the delimiter to use. | ||
| * Capitalizes the first letter of a string. This is a runtime counterpart of `Capitalize<T>` from `src/types.d.ts`. | ||
| * @param str the string to capitalize. | ||
| * @returns the capitalized string. | ||
| * @example capitalize('hello world') // 'Hello world' | ||
| */ | ||
| type DeepDelimiterKeys<T, D extends string> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepDelimiterKeys<T[I], D>; | ||
| } : T extends (infer V)[] ? DeepDelimiterKeys<V, D>[] : { | ||
| [K in keyof T as DelimiterCase<Extract<K, string>, D>]: DeepDelimiterKeys<T[K], D>; | ||
| }; | ||
| declare function capitalize<T extends string>(str: T): Capitalize<T>; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to a custom delimiter case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @param delimiter the delimiter to use. | ||
| * @returns the transformed object. | ||
| * @example deepDelimiterKeys({ 'foo-bar': { 'fizz-buzz': true } }, '.') // { 'foo.bar': { 'fizz.buzz': true } } | ||
| * A strongly-typed version of `lowerCase` that works in both runtime and type level. | ||
| * @param str the string to convert to lower case. | ||
| * @returns the lowercased string. | ||
| * @example lowerCase('HELLO-WORLD') // 'hello world' | ||
| */ | ||
| declare function deepDelimiterKeys<T, D extends string>(obj: T, delimiter: D): DeepDelimiterKeys<T, D>; | ||
| declare function lowerCase<T extends string>(str: T): Lowercase<DelimiterCase<T, ' '>>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to kebab-case. | ||
| * T: the type of the Record to transform. | ||
| * Transforms a string to "Title Case". | ||
| */ | ||
| type DeepKebabKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepKebabKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepKebabKeys<V>[] : { | ||
| [K in keyof T as KebabCase<Extract<K, string>>]: DeepKebabKeys<T[K]>; | ||
| }; | ||
| type TitleCase<T extends string> = DelimiterCase<PascalCase<T>, ' '>; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to kebab-case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepKebabKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo-bar': { 'fizz-buzz': true } } | ||
| * A strongly typed version of `titleCase` that works in both runtime and type level. | ||
| * @param str the string to convert to title case. | ||
| * @returns the title cased string. | ||
| * @example titleCase('hello world') // 'Hello World' | ||
| */ | ||
| declare function deepKebabKeys<T>(obj: T): DeepKebabKeys<T>; | ||
| declare function titleCase<T extends string>(str: T): TitleCase<T>; | ||
| /** | ||
| * Recursively transforms the keys of a Record to PascalCase. | ||
| * T: the type of the Record to transform. | ||
| * @deprecated | ||
| * Use `titleCase` instead. | ||
| * Read more about the deprecation [here](https://github.com/gustavoguichard/string-ts/issues/44). | ||
| */ | ||
| type DeepPascalKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepPascalKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepPascalKeys<V>[] : { | ||
| [K in keyof T as PascalCase<Extract<K, string>>]: DeepPascalKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to pascal case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepPascalKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FooBar: { FizzBuzz: true } } | ||
| */ | ||
| declare function deepPascalKeys<T>(obj: T): DeepPascalKeys<T>; | ||
| declare const toTitleCase: typeof titleCase; | ||
| /** | ||
| * Recursively transforms the keys of a Record to snake_case. | ||
| * T: the type of the Record to transform. | ||
| * Uncapitalizes the first letter of a string. This is a runtime counterpart of `Uncapitalize<T>` from `src/types.d.ts`. | ||
| * @param str the string to uncapitalize. | ||
| * @returns the uncapitalized string. | ||
| * @example uncapitalize('Hello world') // 'hello world' | ||
| */ | ||
| type DeepSnakeKeys<T> = T extends [any, ...any] ? { | ||
| [I in keyof T]: DeepSnakeKeys<T[I]>; | ||
| } : T extends (infer V)[] ? DeepSnakeKeys<V>[] : { | ||
| [K in keyof T as SnakeCase<Extract<K, string>>]: DeepSnakeKeys<T[K]>; | ||
| }; | ||
| /** | ||
| * A strongly typed function that recursively transforms the keys of an object to snake_case. The transformation is done both at runtime and type level. | ||
| * @param obj the object to transform. | ||
| * @returns the transformed object. | ||
| * @example deepSnakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz_buzz': true } } | ||
| */ | ||
| declare function deepSnakeKeys<T>(obj: T): DeepSnakeKeys<T>; | ||
| declare function uncapitalize<T extends string>(str: T): Uncapitalize<T>; | ||
| /** | ||
| * This function is used to transform the keys of an object deeply. | ||
| * It will only be transformed at runtime, so it's not type safe. | ||
| * @param obj the object to transform. | ||
| * @param transform the function to transform the keys from string to string. | ||
| * @returns the transformed object. | ||
| * @example deepTransformKeys({ 'foo-bar': { 'fizz-buzz': true } }, camelCase) | ||
| * // { fooBar: { fizzBuzz: true } } | ||
| * A strongly-typed version of `upperCase` that works in both runtime and type level. | ||
| * @param str the string to convert to upper case. | ||
| * @returns the uppercased string. | ||
| * @example upperCase('hello-world') // 'HELLO WORLD' | ||
| */ | ||
| declare function deepTransformKeys<T>(obj: T, transform: (s: string) => string): T; | ||
| declare function upperCase<T extends string>(str: T): Uppercase<DelimiterCase<T, ' '>>; | ||
| export { type CamelCase, type CamelKeys, type CharAt, type Concat, type ConstantCase, type ConstantKeys, type DeepCamelKeys, type DeepConstantKeys, type DeepDelimiterKeys, type DeepKebabKeys, type DeepPascalKeys, type DeepSnakeKeys, type DelimiterCase, type DelimiterKeys, type Digit, type Digits, type EndsWith, type Includes, type IsDigit, type IsLetter, type IsLower, type IsSeparator, type IsSpecial, type IsUpper, type Join, type KebabCase, type KebabKeys, type Length, type Letter, type Letters, type LowerLetter, type LowerLetters, type PadEnd, type PadStart, type PascalCase, type PascalKeys, type Repeat, type Replace, type ReplaceAll, type ReplaceKeys, type Reverse, type Separator, type Separators, type Slice, type SnakeCase, type SnakeKeys, type Split, type StartsWith, type TitleCase, type Trim, type TrimEnd, type TrimStart, type Truncate, type UpperLetter, type UpperLetters, type Words, camelCase, camelKeys, capitalize, charAt, concat, constantCase, constantKeys, deepCamelKeys, deepConstantKeys, deepDelimiterKeys, deepKebabKeys, deepPascalKeys, deepSnakeKeys, deepTransformKeys, delimiterCase, delimiterKeys, endsWith, includes, join, kebabCase, kebabKeys, length, lowerCase, padEnd, padStart, pascalCase, pascalKeys, repeat, replace, replaceAll, replaceKeys, reverse, slice, snakeCase, snakeKeys, split, startsWith, titleCase, toCamelCase, toConstantCase, toDelimiterCase, toKebabCase, toLowerCase, toPascalCase, toSnakeCase, toTitleCase, toUpperCase, trim, trimEnd, trimStart, truncate, uncapitalize, upperCase, words }; |
+106
-106
@@ -77,10 +77,10 @@ 'use strict'; | ||
| // src/native/trim-start.ts | ||
| function trimStart(str) { | ||
| return str.trimStart(); | ||
| // src/native/to-lower-case.ts | ||
| function toLowerCase(str) { | ||
| return str.toLowerCase(); | ||
| } | ||
| // src/native/trim-end.ts | ||
| function trimEnd(str) { | ||
| return str.trimEnd(); | ||
| // src/native/to-upper-case.ts | ||
| function toUpperCase(str) { | ||
| return str.toUpperCase(); | ||
| } | ||
@@ -93,27 +93,33 @@ | ||
| // src/native/to-lower-case.ts | ||
| function toLowerCase(str) { | ||
| return str.toLowerCase(); | ||
| // src/native/trim-end.ts | ||
| function trimEnd(str) { | ||
| return str.trimEnd(); | ||
| } | ||
| // src/native/to-upper-case.ts | ||
| function toUpperCase(str) { | ||
| return str.toUpperCase(); | ||
| // src/native/trim-start.ts | ||
| function trimStart(str) { | ||
| return str.trimStart(); | ||
| } | ||
| // src/utils/reverse.ts | ||
| function reverse(str) { | ||
| return str.split("").reverse().join(""); | ||
| // src/utils/characters/apostrophe.ts | ||
| function removeApostrophe(str) { | ||
| return replaceAll(str, "'", ""); | ||
| } | ||
| // src/utils/truncate.ts | ||
| function truncate(sentence, length2, omission = "...") { | ||
| if (length2 < 0) return omission; | ||
| if (sentence.length <= length2) return sentence; | ||
| // src/utils/word-case/capitalize.ts | ||
| function capitalize(str) { | ||
| return join([ | ||
| sentence.slice(0, length2 - omission.length), | ||
| omission | ||
| toUpperCase(charAt(str, 0) ?? ""), | ||
| slice(str, 1) | ||
| ]); | ||
| } | ||
| // src/internal/internals.ts | ||
| function typeOf(t) { | ||
| return Object.prototype.toString.call(t).replace(/^\[object (.+)\]$/, "$1").toLowerCase(); | ||
| } | ||
| function pascalCaseAll(words2) { | ||
| return words2.map((v) => capitalize(toLowerCase(v))); | ||
| } | ||
| // src/utils/characters/separators.ts | ||
@@ -146,23 +152,2 @@ var UNESCAPED_SEPARATORS = [ | ||
| // src/utils/characters/apostrophe.ts | ||
| function removeApostrophe(str) { | ||
| return replaceAll(str, "'", ""); | ||
| } | ||
| // src/utils/word-case/capitalize.ts | ||
| function capitalize(str) { | ||
| return join([ | ||
| toUpperCase(charAt(str, 0) ?? ""), | ||
| slice(str, 1) | ||
| ]); | ||
| } | ||
| // src/internal/internals.ts | ||
| function typeOf(t) { | ||
| return Object.prototype.toString.call(t).replace(/^\[object (.+)\]$/, "$1").toLowerCase(); | ||
| } | ||
| function pascalCaseAll(words2) { | ||
| return words2.map((v) => capitalize(toLowerCase(v))); | ||
| } | ||
| // src/utils/word-case/pascal-case.ts | ||
@@ -188,42 +173,2 @@ function pascalCase(str) { | ||
| // src/utils/word-case/delimiter-case.ts | ||
| function delimiterCase(str, delimiter) { | ||
| return join(words(removeApostrophe(str)), delimiter); | ||
| } | ||
| var toDelimiterCase = delimiterCase; | ||
| // src/utils/word-case/constant-case.ts | ||
| function constantCase(str) { | ||
| return toUpperCase(delimiterCase(removeApostrophe(str), "_")); | ||
| } | ||
| var toConstantCase = constantCase; | ||
| // src/utils/word-case/kebab-case.ts | ||
| function kebabCase(str) { | ||
| return toLowerCase(delimiterCase(removeApostrophe(str), "-")); | ||
| } | ||
| var toKebabCase = kebabCase; | ||
| // src/utils/word-case/snake-case.ts | ||
| function snakeCase(str) { | ||
| return toLowerCase(delimiterCase(removeApostrophe(str), "_")); | ||
| } | ||
| var toSnakeCase = snakeCase; | ||
| // src/utils/word-case/title-case.ts | ||
| function titleCase(str) { | ||
| return delimiterCase(pascalCase(str), " "); | ||
| } | ||
| var toTitleCase = titleCase; | ||
| // src/utils/word-case/lower-case.ts | ||
| function lowerCase(str) { | ||
| return toLowerCase(delimiterCase(str, " ")); | ||
| } | ||
| // src/utils/word-case/upper-case.ts | ||
| function upperCase(str) { | ||
| return toUpperCase(delimiterCase(str, " ")); | ||
| } | ||
| // src/utils/object-keys/transform-keys.ts | ||
@@ -244,32 +189,19 @@ function transformKeys(obj, transform) { | ||
| // src/utils/object-keys/constant-keys.ts | ||
| function constantKeys(obj) { | ||
| return transformKeys(obj, constantCase); | ||
| // src/utils/word-case/delimiter-case.ts | ||
| function delimiterCase(str, delimiter) { | ||
| return join(words(removeApostrophe(str)), delimiter); | ||
| } | ||
| var toDelimiterCase = delimiterCase; | ||
| // src/utils/object-keys/delimiter-keys.ts | ||
| function delimiterKeys(obj, delimiter) { | ||
| return transformKeys(obj, (str) => delimiterCase(str, delimiter)); | ||
| // src/utils/word-case/constant-case.ts | ||
| function constantCase(str) { | ||
| return toUpperCase(delimiterCase(removeApostrophe(str), "_")); | ||
| } | ||
| var toConstantCase = constantCase; | ||
| // src/utils/object-keys/kebab-keys.ts | ||
| function kebabKeys(obj) { | ||
| return transformKeys(obj, kebabCase); | ||
| // src/utils/object-keys/constant-keys.ts | ||
| function constantKeys(obj) { | ||
| return transformKeys(obj, constantCase); | ||
| } | ||
| // src/utils/object-keys/pascal-keys.ts | ||
| function pascalKeys(obj) { | ||
| return transformKeys(obj, pascalCase); | ||
| } | ||
| // src/utils/object-keys/snake-keys.ts | ||
| function snakeKeys(obj) { | ||
| return transformKeys(obj, snakeCase); | ||
| } | ||
| // src/utils/object-keys/replace-keys.ts | ||
| function replaceKeys(obj, lookup, replacement = "") { | ||
| return transformKeys(obj, (s) => replace(s, lookup, replacement)); | ||
| } | ||
| // src/utils/object-keys/deep-transform-keys.ts | ||
@@ -303,2 +235,8 @@ function deepTransformKeys(obj, transform) { | ||
| // src/utils/word-case/kebab-case.ts | ||
| function kebabCase(str) { | ||
| return toLowerCase(delimiterCase(removeApostrophe(str), "-")); | ||
| } | ||
| var toKebabCase = kebabCase; | ||
| // src/utils/object-keys/deep-kebab-keys.ts | ||
@@ -314,2 +252,8 @@ function deepKebabKeys(obj) { | ||
| // src/utils/word-case/snake-case.ts | ||
| function snakeCase(str) { | ||
| return toLowerCase(delimiterCase(removeApostrophe(str), "_")); | ||
| } | ||
| var toSnakeCase = snakeCase; | ||
| // src/utils/object-keys/deep-snake-keys.ts | ||
@@ -320,2 +264,58 @@ function deepSnakeKeys(obj) { | ||
| // src/utils/object-keys/delimiter-keys.ts | ||
| function delimiterKeys(obj, delimiter) { | ||
| return transformKeys(obj, (str) => delimiterCase(str, delimiter)); | ||
| } | ||
| // src/utils/object-keys/kebab-keys.ts | ||
| function kebabKeys(obj) { | ||
| return transformKeys(obj, kebabCase); | ||
| } | ||
| // src/utils/object-keys/pascal-keys.ts | ||
| function pascalKeys(obj) { | ||
| return transformKeys(obj, pascalCase); | ||
| } | ||
| // src/utils/object-keys/replace-keys.ts | ||
| function replaceKeys(obj, lookup, replacement = "") { | ||
| return transformKeys(obj, (s) => replace(s, lookup, replacement)); | ||
| } | ||
| // src/utils/object-keys/snake-keys.ts | ||
| function snakeKeys(obj) { | ||
| return transformKeys(obj, snakeCase); | ||
| } | ||
| // src/utils/reverse.ts | ||
| function reverse(str) { | ||
| return str.split("").reverse().join(""); | ||
| } | ||
| // src/utils/truncate.ts | ||
| function truncate(sentence, length2, omission = "...") { | ||
| if (length2 < 0) return omission; | ||
| if (sentence.length <= length2) return sentence; | ||
| return join([ | ||
| sentence.slice(0, length2 - omission.length), | ||
| omission | ||
| ]); | ||
| } | ||
| // src/utils/word-case/lower-case.ts | ||
| function lowerCase(str) { | ||
| return toLowerCase(delimiterCase(str, " ")); | ||
| } | ||
| // src/utils/word-case/title-case.ts | ||
| function titleCase(str) { | ||
| return delimiterCase(pascalCase(str), " "); | ||
| } | ||
| var toTitleCase = titleCase; | ||
| // src/utils/word-case/upper-case.ts | ||
| function upperCase(str) { | ||
| return toUpperCase(delimiterCase(str, " ")); | ||
| } | ||
| exports.camelCase = camelCase; | ||
@@ -322,0 +322,0 @@ exports.camelKeys = camelKeys; |
+106
-106
@@ -75,10 +75,10 @@ // src/native/char-at.ts | ||
| // src/native/trim-start.ts | ||
| function trimStart(str) { | ||
| return str.trimStart(); | ||
| // src/native/to-lower-case.ts | ||
| function toLowerCase(str) { | ||
| return str.toLowerCase(); | ||
| } | ||
| // src/native/trim-end.ts | ||
| function trimEnd(str) { | ||
| return str.trimEnd(); | ||
| // src/native/to-upper-case.ts | ||
| function toUpperCase(str) { | ||
| return str.toUpperCase(); | ||
| } | ||
@@ -91,27 +91,33 @@ | ||
| // src/native/to-lower-case.ts | ||
| function toLowerCase(str) { | ||
| return str.toLowerCase(); | ||
| // src/native/trim-end.ts | ||
| function trimEnd(str) { | ||
| return str.trimEnd(); | ||
| } | ||
| // src/native/to-upper-case.ts | ||
| function toUpperCase(str) { | ||
| return str.toUpperCase(); | ||
| // src/native/trim-start.ts | ||
| function trimStart(str) { | ||
| return str.trimStart(); | ||
| } | ||
| // src/utils/reverse.ts | ||
| function reverse(str) { | ||
| return str.split("").reverse().join(""); | ||
| // src/utils/characters/apostrophe.ts | ||
| function removeApostrophe(str) { | ||
| return replaceAll(str, "'", ""); | ||
| } | ||
| // src/utils/truncate.ts | ||
| function truncate(sentence, length2, omission = "...") { | ||
| if (length2 < 0) return omission; | ||
| if (sentence.length <= length2) return sentence; | ||
| // src/utils/word-case/capitalize.ts | ||
| function capitalize(str) { | ||
| return join([ | ||
| sentence.slice(0, length2 - omission.length), | ||
| omission | ||
| toUpperCase(charAt(str, 0) ?? ""), | ||
| slice(str, 1) | ||
| ]); | ||
| } | ||
| // src/internal/internals.ts | ||
| function typeOf(t) { | ||
| return Object.prototype.toString.call(t).replace(/^\[object (.+)\]$/, "$1").toLowerCase(); | ||
| } | ||
| function pascalCaseAll(words2) { | ||
| return words2.map((v) => capitalize(toLowerCase(v))); | ||
| } | ||
| // src/utils/characters/separators.ts | ||
@@ -144,23 +150,2 @@ var UNESCAPED_SEPARATORS = [ | ||
| // src/utils/characters/apostrophe.ts | ||
| function removeApostrophe(str) { | ||
| return replaceAll(str, "'", ""); | ||
| } | ||
| // src/utils/word-case/capitalize.ts | ||
| function capitalize(str) { | ||
| return join([ | ||
| toUpperCase(charAt(str, 0) ?? ""), | ||
| slice(str, 1) | ||
| ]); | ||
| } | ||
| // src/internal/internals.ts | ||
| function typeOf(t) { | ||
| return Object.prototype.toString.call(t).replace(/^\[object (.+)\]$/, "$1").toLowerCase(); | ||
| } | ||
| function pascalCaseAll(words2) { | ||
| return words2.map((v) => capitalize(toLowerCase(v))); | ||
| } | ||
| // src/utils/word-case/pascal-case.ts | ||
@@ -186,42 +171,2 @@ function pascalCase(str) { | ||
| // src/utils/word-case/delimiter-case.ts | ||
| function delimiterCase(str, delimiter) { | ||
| return join(words(removeApostrophe(str)), delimiter); | ||
| } | ||
| var toDelimiterCase = delimiterCase; | ||
| // src/utils/word-case/constant-case.ts | ||
| function constantCase(str) { | ||
| return toUpperCase(delimiterCase(removeApostrophe(str), "_")); | ||
| } | ||
| var toConstantCase = constantCase; | ||
| // src/utils/word-case/kebab-case.ts | ||
| function kebabCase(str) { | ||
| return toLowerCase(delimiterCase(removeApostrophe(str), "-")); | ||
| } | ||
| var toKebabCase = kebabCase; | ||
| // src/utils/word-case/snake-case.ts | ||
| function snakeCase(str) { | ||
| return toLowerCase(delimiterCase(removeApostrophe(str), "_")); | ||
| } | ||
| var toSnakeCase = snakeCase; | ||
| // src/utils/word-case/title-case.ts | ||
| function titleCase(str) { | ||
| return delimiterCase(pascalCase(str), " "); | ||
| } | ||
| var toTitleCase = titleCase; | ||
| // src/utils/word-case/lower-case.ts | ||
| function lowerCase(str) { | ||
| return toLowerCase(delimiterCase(str, " ")); | ||
| } | ||
| // src/utils/word-case/upper-case.ts | ||
| function upperCase(str) { | ||
| return toUpperCase(delimiterCase(str, " ")); | ||
| } | ||
| // src/utils/object-keys/transform-keys.ts | ||
@@ -242,32 +187,19 @@ function transformKeys(obj, transform) { | ||
| // src/utils/object-keys/constant-keys.ts | ||
| function constantKeys(obj) { | ||
| return transformKeys(obj, constantCase); | ||
| // src/utils/word-case/delimiter-case.ts | ||
| function delimiterCase(str, delimiter) { | ||
| return join(words(removeApostrophe(str)), delimiter); | ||
| } | ||
| var toDelimiterCase = delimiterCase; | ||
| // src/utils/object-keys/delimiter-keys.ts | ||
| function delimiterKeys(obj, delimiter) { | ||
| return transformKeys(obj, (str) => delimiterCase(str, delimiter)); | ||
| // src/utils/word-case/constant-case.ts | ||
| function constantCase(str) { | ||
| return toUpperCase(delimiterCase(removeApostrophe(str), "_")); | ||
| } | ||
| var toConstantCase = constantCase; | ||
| // src/utils/object-keys/kebab-keys.ts | ||
| function kebabKeys(obj) { | ||
| return transformKeys(obj, kebabCase); | ||
| // src/utils/object-keys/constant-keys.ts | ||
| function constantKeys(obj) { | ||
| return transformKeys(obj, constantCase); | ||
| } | ||
| // src/utils/object-keys/pascal-keys.ts | ||
| function pascalKeys(obj) { | ||
| return transformKeys(obj, pascalCase); | ||
| } | ||
| // src/utils/object-keys/snake-keys.ts | ||
| function snakeKeys(obj) { | ||
| return transformKeys(obj, snakeCase); | ||
| } | ||
| // src/utils/object-keys/replace-keys.ts | ||
| function replaceKeys(obj, lookup, replacement = "") { | ||
| return transformKeys(obj, (s) => replace(s, lookup, replacement)); | ||
| } | ||
| // src/utils/object-keys/deep-transform-keys.ts | ||
@@ -301,2 +233,8 @@ function deepTransformKeys(obj, transform) { | ||
| // src/utils/word-case/kebab-case.ts | ||
| function kebabCase(str) { | ||
| return toLowerCase(delimiterCase(removeApostrophe(str), "-")); | ||
| } | ||
| var toKebabCase = kebabCase; | ||
| // src/utils/object-keys/deep-kebab-keys.ts | ||
@@ -312,2 +250,8 @@ function deepKebabKeys(obj) { | ||
| // src/utils/word-case/snake-case.ts | ||
| function snakeCase(str) { | ||
| return toLowerCase(delimiterCase(removeApostrophe(str), "_")); | ||
| } | ||
| var toSnakeCase = snakeCase; | ||
| // src/utils/object-keys/deep-snake-keys.ts | ||
@@ -318,2 +262,58 @@ function deepSnakeKeys(obj) { | ||
| // src/utils/object-keys/delimiter-keys.ts | ||
| function delimiterKeys(obj, delimiter) { | ||
| return transformKeys(obj, (str) => delimiterCase(str, delimiter)); | ||
| } | ||
| // src/utils/object-keys/kebab-keys.ts | ||
| function kebabKeys(obj) { | ||
| return transformKeys(obj, kebabCase); | ||
| } | ||
| // src/utils/object-keys/pascal-keys.ts | ||
| function pascalKeys(obj) { | ||
| return transformKeys(obj, pascalCase); | ||
| } | ||
| // src/utils/object-keys/replace-keys.ts | ||
| function replaceKeys(obj, lookup, replacement = "") { | ||
| return transformKeys(obj, (s) => replace(s, lookup, replacement)); | ||
| } | ||
| // src/utils/object-keys/snake-keys.ts | ||
| function snakeKeys(obj) { | ||
| return transformKeys(obj, snakeCase); | ||
| } | ||
| // src/utils/reverse.ts | ||
| function reverse(str) { | ||
| return str.split("").reverse().join(""); | ||
| } | ||
| // src/utils/truncate.ts | ||
| function truncate(sentence, length2, omission = "...") { | ||
| if (length2 < 0) return omission; | ||
| if (sentence.length <= length2) return sentence; | ||
| return join([ | ||
| sentence.slice(0, length2 - omission.length), | ||
| omission | ||
| ]); | ||
| } | ||
| // src/utils/word-case/lower-case.ts | ||
| function lowerCase(str) { | ||
| return toLowerCase(delimiterCase(str, " ")); | ||
| } | ||
| // src/utils/word-case/title-case.ts | ||
| function titleCase(str) { | ||
| return delimiterCase(pascalCase(str), " "); | ||
| } | ||
| var toTitleCase = titleCase; | ||
| // src/utils/word-case/upper-case.ts | ||
| function upperCase(str) { | ||
| return toUpperCase(delimiterCase(str, " ")); | ||
| } | ||
| export { camelCase, camelKeys, capitalize, charAt, concat, constantCase, constantKeys, deepCamelKeys, deepConstantKeys, deepDelimiterKeys, deepKebabKeys, deepPascalKeys, deepSnakeKeys, deepTransformKeys, delimiterCase, delimiterKeys, endsWith, includes, join, kebabCase, kebabKeys, length, lowerCase, padEnd, padStart, pascalCase, pascalKeys, repeat, replace, replaceAll, replaceKeys, reverse, slice, snakeCase, snakeKeys, split, startsWith, titleCase, toCamelCase, toConstantCase, toDelimiterCase, toKebabCase, toLowerCase, toPascalCase, toSnakeCase, toTitleCase, toUpperCase, trim, trimEnd, trimStart, truncate, uncapitalize, upperCase, words }; |
+2
-1
@@ -20,6 +20,7 @@ import type { | ||
| // biome-ignore lint/complexity/noUselessEmptyExport: <explanation> | ||
| // biome-ignore lint/complexity/noUselessEmptyExport: required to make this a module | ||
| export {} | ||
| declare global { | ||
| // biome-ignore lint/correctness/noUnusedVariables: T is required for interface extension | ||
| interface ReadonlyArray<T> { | ||
@@ -26,0 +27,0 @@ join<const A extends readonly string[], D extends string = ''>( |
+10
-7
| { | ||
| "name": "string-ts", | ||
| "version": "2.3.0", | ||
| "version": "2.3.1", | ||
| "description": "Strongly-typed string functions.", | ||
@@ -38,8 +38,8 @@ "author": "Gustavo Guichard <@gugaguichard>", | ||
| "devDependencies": { | ||
| "@biomejs/biome": "^1.9.4", | ||
| "@types/node": "^22.15.3", | ||
| "@vitest/coverage-v8": "^3.0.5", | ||
| "@biomejs/biome": "^2.3.8", | ||
| "@types/node": "^20.0.0", | ||
| "@vitest/coverage-v8": "^4.0.14", | ||
| "tsup": "latest", | ||
| "tsx": "^4.19.4", | ||
| "typescript": "^5.7.3", | ||
| "tsx": "^4.20.6", | ||
| "typescript": "^5.9.3", | ||
| "vitest": "latest" | ||
@@ -63,5 +63,8 @@ }, | ||
| "esbuild" | ||
| ] | ||
| ], | ||
| "overrides": { | ||
| "vite": "^6.0.0" | ||
| } | ||
| }, | ||
| "packageManager": "pnpm@10.12.4+sha512.5ea8b0deed94ed68691c9bad4c955492705c5eeb8a87ef86bc62c74a26b037b08ff9570f108b2e4dbd1dd1a9186fea925e527f141c648e85af45631074680184" | ||
| } |
+28
-0
@@ -107,2 +107,30 @@ <p align="center"> | ||
| ## 🪄 Native String Method Overrides | ||
| Extracting functions from `string-ts` is the recommended usage, but if you'd like to apply strongly-typed versions of native string methods project-wide, you can do so with a single import. | ||
| Inspired by [ts-reset](https://github.com/total-typescript/ts-reset), this import overrides the native `String.prototype` type declarations, giving you strong typing for supported methods like `charAt`, `startsWith`, `endsWith`, `replace`, `split`, and more. | ||
| ```ts | ||
| import 'string-ts/native' | ||
| const str = 'hello-world' as const | ||
| str.replace('-', '_') | ||
| // ^? 'hello_world' | ||
| str.charAt(6) | ||
| // ^? 'w' | ||
| str.startsWith('hello') | ||
| // ^? true | ||
| str.split('-') | ||
| // ^? ['hello', 'world'] | ||
| ``` | ||
| This has minimal impact on type-checker performance. In our tests, TSC went from 17.21s to 17.41s. | ||
| _Note: Only methods already supported by the library are typed. The `length` property cannot be strongly-typed as it's a read-only property, not a method._ | ||
| --- | ||
@@ -109,0 +137,0 @@ |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
134182
0.87%1014
2.84%1527
-0.13%