Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rename casing functions and deprecate old ones #76

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ It also only work with common ASCII characters characters. We don't plan to supp
- [trimEnd](#trimend)
- [trimStart](#trimstart)
- [Strongly-typed alternatives to common loosely-typed functions](#strongly-typed-alternatives-to-common-loosely-typed-functions)
- [toCamelCase](#tocamelcase)
- [toConstantCase](#toconstantcase)
- [toDelimiterCase](#todelimitercase)
- [toKebabCase](#tokebabcase)
- [toPascalCase](#topascalcase)
- [toSnakeCase](#tosnakecase)
- [toTitleCase](#totitlecase)
- [camelCase](#camelcase)
- [constantCase](#constantcase)
- [delimiterCase](#delimitercase)
- [kebabCase](#kebabcase)
- [pascalCase](#pascalcase)
- [snakeCase](#snakecase)
- [titleCase](#titlecase)
- [truncate](#truncate)
- [words](#words)
- [Strongly-typed shallow transformation of objects](#strongly-typed-shallow-transformation-of-objects)
Expand Down Expand Up @@ -441,87 +441,87 @@ const result = lowerCase(str)
// ^ 'hello world'
```

### toCamelCase
### camelCase

This function converts a string to `camelCase` at both runtime and type levels.

```ts
import { toCamelCase } from 'string-ts'
import { camelCase } from 'string-ts'

const str = 'hello-world'
const result = toCamelCase(str)
const result = camelCase(str)
// ^ 'helloWorld'
```

### toConstantCase
### constantCase

This function converts a string to `CONSTANT_CASE` at both runtime and type levels.

```ts
import { toConstantCase } from 'string-ts'
import { constantCase } from 'string-ts'

const str = 'helloWorld'
const result = toConstantCase(str)
const result = constantCase(str)
// ^ 'HELLO_WORLD'
```

### toDelimiterCase
### delimiterCase

This function converts a string to a new case with a custom delimiter at both runtime and type levels.

```ts
import { toDelimiterCase } from 'string-ts'
import { delimiterCase } from 'string-ts'

const str = 'helloWorld'
const result = toDelimiterCase(str, '.')
const result = delimiterCase(str, '.')
// ^ 'hello.World'
```

### toKebabCase
### kebabCase

This function converts a string to `kebab-case` at both runtime and type levels.

```ts
import { toKebabCase } from 'string-ts'
import { kebabCase } from 'string-ts'

const str = 'helloWorld'
const result = toKebabCase(str)
const result = kebabCase(str)
// ^ 'hello-world'
```

### toPascalCase
### pascalCase

This function converts a string to `PascalCase` at both runtime and type levels.

```ts
import { toPascalCase } from 'string-ts'
import { pascalCase } from 'string-ts'

const str = 'hello-world'
const result = toPascalCase(str)
const result = pascalCase(str)
// ^ 'HelloWorld'
```

### toSnakeCase
### snakeCase

This function converts a string to `snake_case` at both runtime and type levels.

```ts
import { toSnakeCase } from 'string-ts'
import { snakeCase } from 'string-ts'

const str = 'helloWorld'
const result = toSnakeCase(str)
const result = snakeCase(str)
// ^ 'hello_world'
```

### toTitleCase
### titleCase

This function converts a string to `Title Case` at both runtime and type levels.

```ts
import { toTitleCase } from 'string-ts'
import { titleCase } from 'string-ts'

const str = 'helloWorld'
const result = toTitleCase(str)
const result = titleCase(str)
// ^ 'Hello World'
```

Expand Down
38 changes: 22 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export { replaceAll } from './native/replace-all.js'
export { slice } from './native/slice.js'
export { split } from './native/split.js'
export { startsWith } from './native/starts-with.js'
export { toLowerCase } from './native/to-lower-case.js'
export { toUpperCase } from './native/to-upper-case.js'
export { trimStart } from './native/trim-start.js'
export { trimEnd } from './native/trim-end.js'

Expand All @@ -48,25 +50,29 @@ export type { IsSpecial } from './utils/characters/special.js'
export type { Separator, IsSeparator } from './utils/characters/separators.js'

// Word casing
export type { CamelCase } from './utils/word-case/to-camel-case.js'
export type { ConstantCase } from './utils/word-case/to-constant-case.js'
export type { DelimiterCase } from './utils/word-case/to-delimiter-case.js'
export type { KebabCase } from './utils/word-case/to-kebab-case.js'
export type { PascalCase } from './utils/word-case/to-pascal-case.js'
export type { SnakeCase } from './utils/word-case/to-snake-case.js'
export type { TitleCase } from './utils/word-case/to-title-case.js'
export type { CamelCase } from './utils/word-case/camel-case.js'
export type { ConstantCase } from './utils/word-case/constant-case.js'
export type { DelimiterCase } from './utils/word-case/delimiter-case.js'
export type { KebabCase } from './utils/word-case/kebab-case.js'
export type { PascalCase } from './utils/word-case/pascal-case.js'
export type { SnakeCase } from './utils/word-case/snake-case.js'
export type { TitleCase } from './utils/word-case/title-case.js'

export { capitalize } from './utils/capitalize.js'
export { lowerCase } from './utils/word-case/lower-case.js'
export { toCamelCase } from './utils/word-case/to-camel-case.js'
export { toConstantCase } from './utils/word-case/to-constant-case.js'
export { toDelimiterCase } from './utils/word-case/to-delimiter-case.js'
export { toKebabCase } from './utils/word-case/to-kebab-case.js'
export { toLowerCase } from './native/to-lower-case.js'
export { toPascalCase } from './utils/word-case/to-pascal-case.js'
export { toSnakeCase } from './utils/word-case/to-snake-case.js'
export { toTitleCase } from './utils/word-case/to-title-case.js'
export { toUpperCase } from './native/to-upper-case.js'
export { camelCase, toCamelCase } from './utils/word-case/camel-case.js'
export {
constantCase,
toConstantCase,
} from './utils/word-case/constant-case.js'
export {
delimiterCase,
toDelimiterCase,
} from './utils/word-case/delimiter-case.js'
export { kebabCase, toKebabCase } from './utils/word-case/kebab-case.js'
export { pascalCase, toPascalCase } from './utils/word-case/pascal-case.js'
export { snakeCase, toSnakeCase } from './utils/word-case/snake-case.js'
export { titleCase, toTitleCase } from './utils/word-case/title-case.js'
export { uncapitalize } from './utils/uncapitalize.js'
export { upperCase } from './utils/word-case/upper-case.js'

Expand Down
4 changes: 2 additions & 2 deletions src/utils/object-keys/camel-keys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { transformKeys } from './transform-keys.js'
import { type CamelCase, toCamelCase } from '../word-case/to-camel-case.js'
import { type CamelCase, camelCase } from '../word-case/camel-case.js'

/**
* Shallowly transforms the keys of an Record to camelCase.
Expand All @@ -15,5 +15,5 @@ export type CamelKeys<T> = T extends []
* @example camelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { 'fizz-buz': true } }
*/
export function camelKeys<T>(obj: T): CamelKeys<T> {
return transformKeys(obj, toCamelCase) as never
return transformKeys(obj, camelCase) as never
}
7 changes: 2 additions & 5 deletions src/utils/object-keys/constant-keys.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { transformKeys } from './transform-keys.js'
import {
type ConstantCase,
toConstantCase,
} from '../word-case/to-constant-case.js'
import { type ConstantCase, constantCase } from '../word-case/constant-case.js'

/**
* Shallowly transforms the keys of an Record to CONSTANT_CASE.
Expand All @@ -18,5 +15,5 @@ export type ConstantKeys<T> = T extends []
* @example constantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { 'fizz-buzz': true } }
*/
export function constantKeys<T>(obj: T): ConstantKeys<T> {
return transformKeys(obj, toConstantCase) as never
return transformKeys(obj, constantCase) as never
}
4 changes: 2 additions & 2 deletions src/utils/object-keys/deep-camel-keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type CamelCase, toCamelCase } from '../word-case/to-camel-case.js'
import { type CamelCase, camelCase } from '../word-case/camel-case.js'
import { deepTransformKeys } from './deep-transform-keys.js'

/**
Expand All @@ -19,5 +19,5 @@ export type DeepCamelKeys<T> = T extends [any, ...any]
* @example deepCamelKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { fooBar: { fizzBuzz: true } }
*/
export function deepCamelKeys<T>(obj: T): DeepCamelKeys<T> {
return deepTransformKeys(obj, toCamelCase) as never
return deepTransformKeys(obj, camelCase) as never
}
7 changes: 2 additions & 5 deletions src/utils/object-keys/deep-constant-keys.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
type ConstantCase,
toConstantCase,
} from '../word-case/to-constant-case.js'
import { type ConstantCase, constantCase } from '../word-case/constant-case.js'
import { deepTransformKeys } from './deep-transform-keys.js'

/**
Expand All @@ -22,5 +19,5 @@ export type DeepConstantKeys<T> = T extends [any, ...any]
* @example deepConstantKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FOO_BAR: { FIZZ_BUZZ: true } }
*/
export function deepConstantKeys<T>(obj: T): DeepConstantKeys<T> {
return deepTransformKeys(obj, toConstantCase) as never
return deepTransformKeys(obj, constantCase) as never
}
8 changes: 3 additions & 5 deletions src/utils/object-keys/deep-delimiter-keys.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
type DelimiterCase,
toDelimiterCase,
} from '../word-case/to-delimiter-case.js'
delimiterCase,
} from '../word-case/delimiter-case.js'
import { deepTransformKeys } from './deep-transform-keys.js'

/**
Expand Down Expand Up @@ -30,7 +30,5 @@ export function deepDelimiterKeys<T, D extends string>(
obj: T,
delimiter: D,
): DeepDelimiterKeys<T, D> {
return deepTransformKeys(obj, (str) =>
toDelimiterCase(str, delimiter),
) as never
return deepTransformKeys(obj, (str) => delimiterCase(str, delimiter)) as never
}
4 changes: 2 additions & 2 deletions src/utils/object-keys/deep-kebab-keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type KebabCase, toKebabCase } from '../word-case/to-kebab-case.js'
import { type KebabCase, kebabCase } from '../word-case/kebab-case.js'
import { deepTransformKeys } from './deep-transform-keys.js'

/**
Expand All @@ -19,5 +19,5 @@ export type DeepKebabKeys<T> = T extends [any, ...any]
* @example deepKebabKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo-bar': { 'fizz-buzz': true } }
*/
export function deepKebabKeys<T>(obj: T): DeepKebabKeys<T> {
return deepTransformKeys(obj, toKebabCase) as never
return deepTransformKeys(obj, kebabCase) as never
}
4 changes: 2 additions & 2 deletions src/utils/object-keys/deep-pascal-keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type PascalCase, toPascalCase } from '../word-case/to-pascal-case.js'
import { type PascalCase, pascalCase } from '../word-case/pascal-case.js'
import { deepTransformKeys } from './deep-transform-keys.js'

/**
Expand All @@ -19,5 +19,5 @@ export type DeepPascalKeys<T> = T extends [any, ...any]
* @example deepPascalKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FooBar: { FizzBuzz: true } }
*/
export function deepPascalKeys<T>(obj: T): DeepPascalKeys<T> {
return deepTransformKeys(obj, toPascalCase) as never
return deepTransformKeys(obj, pascalCase) as never
}
4 changes: 2 additions & 2 deletions src/utils/object-keys/deep-snake-keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type SnakeCase, toSnakeCase } from '../word-case/to-snake-case.js'
import { type SnakeCase, snakeCase } from '../word-case/snake-case.js'
import { deepTransformKeys } from './deep-transform-keys.js'

/**
Expand All @@ -19,5 +19,5 @@ export type DeepSnakeKeys<T> = T extends [any, ...any]
* @example deepSnakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz_buzz': true } }
*/
export function deepSnakeKeys<T>(obj: T): DeepSnakeKeys<T> {
return deepTransformKeys(obj, toSnakeCase) as never
return deepTransformKeys(obj, snakeCase) as never
}
2 changes: 1 addition & 1 deletion src/utils/object-keys/deep-transform-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { typeOf } from '../../internal/internals.js'
* @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 } }, toCamelCase)
* @example deepTransformKeys({ 'foo-bar': { 'fizz-buzz': true } }, camelCase)
* // { fooBar: { fizzBuzz: true } }
*/
export function deepTransformKeys<T>(
Expand Down
6 changes: 3 additions & 3 deletions src/utils/object-keys/delimiter-keys.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { transformKeys } from './transform-keys.js'
import {
type DelimiterCase,
toDelimiterCase,
} from '../word-case/to-delimiter-case.js'
delimiterCase,
} from '../word-case/delimiter-case.js'

/**
* Shallowly transforms the keys of an Record to a custom delimiter case.
Expand All @@ -23,5 +23,5 @@ export function delimiterKeys<T, D extends string>(
obj: T,
delimiter: D,
): DelimiterKeys<T, D> {
return transformKeys(obj, (str) => toDelimiterCase(str, delimiter)) as never
return transformKeys(obj, (str) => delimiterCase(str, delimiter)) as never
}
4 changes: 2 additions & 2 deletions src/utils/object-keys/kebab-keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type KebabCase, toKebabCase } from '../word-case/to-kebab-case.js'
import { type KebabCase, kebabCase } from '../word-case/kebab-case.js'
import { transformKeys } from './transform-keys.js'

/**
Expand All @@ -17,5 +17,5 @@ export type KebabKeys<T> = T extends []
* @example kebabKeys({ fooBar: { fizzBuzz: true } }) // { 'foo-bar': { fizzBuzz: true } }
*/
export function kebabKeys<T>(obj: T): KebabKeys<T> {
return transformKeys(obj, toKebabCase) as never
return transformKeys(obj, kebabCase) as never
}
4 changes: 2 additions & 2 deletions src/utils/object-keys/pascal-keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type PascalCase, toPascalCase } from '../word-case/to-pascal-case.js'
import { type PascalCase, pascalCase } from '../word-case/pascal-case.js'
import { transformKeys } from './transform-keys.js'

/**
Expand All @@ -15,5 +15,5 @@ export type PascalKeys<T> = T extends []
* @example pascalKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { FooBar: { 'fizz-buzz': true } }
*/
export function pascalKeys<T>(obj: T): PascalKeys<T> {
return transformKeys(obj, toPascalCase) as never
return transformKeys(obj, pascalCase) as never
}
4 changes: 2 additions & 2 deletions src/utils/object-keys/snake-keys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { transformKeys } from './transform-keys.js'
import { type SnakeCase, toSnakeCase } from '../word-case/to-snake-case.js'
import { type SnakeCase, snakeCase } from '../word-case/snake-case.js'

/**
* Shallowly transforms the keys of an Record to snake_case.
Expand All @@ -15,5 +15,5 @@ export type SnakeKeys<T> = T extends []
* @example snakeKeys({ 'foo-bar': { 'fizz-buzz': true } }) // { 'foo_bar': { 'fizz-buzz': true } }
*/
export function snakeKeys<T>(obj: T): SnakeKeys<T> {
return transformKeys(obj, toSnakeCase) as never
return transformKeys(obj, snakeCase) as never
}
2 changes: 1 addition & 1 deletion src/utils/object-keys/transform-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { typeOf } from '../../internal/internals.js'
* @param obj the object to transform.
* @param transform the function to transform the keys from string to string.
* @returns the transformed object.
* @example transformKeys({ 'foo-bar': { 'fizz-buzz': true } }, toCamelCase)
* @example transformKeys({ 'foo-bar': { 'fizz-buzz': true } }, camelCase)
* // { fooBar: { 'fizz-buzz': true } }
*/
export function transformKeys<T>(obj: T, transform: (s: string) => string): T {
Expand Down
Loading
Loading