-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
443 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const camelToKebab = (value: string) => | ||
value.replace(/([A-Z])/g, (match, $1) => `-${$1.toLowerCase()}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const camelToPascal = (value: string) => | ||
value.replace(/^([a-z])/, (match, $1) => $1.toUpperCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const camelToScreamingKebab = (value: string) => | ||
value.replace(/([A-Z])/g, (match, $1) => `-${$1}`).toUpperCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const camelToScreamingSnake = (value: string) => | ||
value.replace(/([A-Z])/g, (match, $1) => `_${$1}`).toUpperCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const camelToSnake = (value: string) => | ||
value.replace(/([A-Z])/g, (match, $1) => `_${$1.toLowerCase()}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { fromCamel } from "./from/camel"; | ||
import { fromKebab } from "./from/kebab"; | ||
import { fromPascal } from "./from/pascal"; | ||
import { fromScreamingKebab } from "./from/screaming-kebab"; | ||
import { fromScreamingSnake } from "./from/screaming-snake"; | ||
import { fromSnake } from "./from/snake"; | ||
import { toCamel } from "./to/camel"; | ||
import { toKebab } from "./to/kebab"; | ||
import { toPascal } from "./to/pascal"; | ||
import { toScreamingKebab } from "./to/screaming-kebab"; | ||
import { toScreamingSnake } from "./to/screaming-snake"; | ||
import { toSnake } from "./to/snake"; | ||
|
||
export const convert = { | ||
snake: { | ||
from: toSnake, | ||
to: fromSnake, | ||
}, | ||
kebab: { | ||
from: toKebab, | ||
to: fromKebab, | ||
}, | ||
screamingSnake: { | ||
from: toScreamingSnake, | ||
to: fromScreamingSnake, | ||
}, | ||
screamingKebab: { | ||
from: toScreamingKebab, | ||
to: fromScreamingKebab, | ||
}, | ||
camel: { | ||
from: toCamel, | ||
to: fromCamel, | ||
}, | ||
pascal: { | ||
from: toPascal, | ||
to: fromPascal, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { fromCamel } from "./from/camel"; | ||
import { fromKebab } from "./from/kebab"; | ||
import { fromPascal } from "./from/pascal"; | ||
import { fromScreamingKebab } from "./from/screaming-kebab"; | ||
import { fromScreamingSnake } from "./from/screaming-snake"; | ||
import { fromSnake } from "./from/snake"; | ||
|
||
export const from = { | ||
camel: { to: fromCamel }, | ||
pascal: { to: fromPascal }, | ||
kebab: { to: fromKebab }, | ||
snake: { to: fromSnake }, | ||
screamingKebab: { to: fromScreamingKebab }, | ||
screamingSnake: { to: fromScreamingSnake }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { camelToKebab } from "../camel/kebab"; | ||
import { camelToPascal } from "../camel/pascal"; | ||
import { camelToScreamingKebab } from "../camel/screaming-kebab"; | ||
import { camelToScreamingSnake } from "../camel/screaming-snake"; | ||
import { camelToSnake } from "../camel/snake"; | ||
import { keep } from "../keep"; | ||
|
||
export const fromCamel = { | ||
snake: camelToSnake, | ||
kebab: camelToKebab, | ||
screamingSnake: camelToScreamingSnake, | ||
screamingKebab: camelToScreamingKebab, | ||
camel: keep, | ||
pascal: camelToPascal, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { kebabToCamel } from "../kebab/camel"; | ||
import { kebabToPascal } from "../kebab/pascal"; | ||
import { kebabToScreamingKebab } from "../kebab/screaming-kebab"; | ||
import { kebabToScreamingSnake } from "../kebab/screaming-snake"; | ||
import { kebabToSnake } from "../kebab/snake"; | ||
import { keep } from "../keep"; | ||
|
||
export const fromKebab = { | ||
snake: kebabToSnake, | ||
kebab: keep, | ||
screamingSnake: kebabToScreamingSnake, | ||
screamingKebab: kebabToScreamingKebab, | ||
camel: kebabToCamel, | ||
pascal: kebabToPascal, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { keep } from "../keep"; | ||
import { pascalToCamel } from "../pascal/camel"; | ||
import { pascalToKebab } from "../pascal/kebab"; | ||
import { pascalToScreamingKebab } from "../pascal/screaming-kebab"; | ||
import { pascalToScreamingSnake } from "../pascal/screaming-snake"; | ||
import { pascalToSnake } from "../pascal/snake"; | ||
|
||
export const fromPascal = { | ||
snake: pascalToSnake, | ||
kebab: pascalToKebab, | ||
screamingSnake: pascalToScreamingSnake, | ||
screamingKebab: pascalToScreamingKebab, | ||
camel: pascalToCamel, | ||
pascal: keep, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { keep } from "../keep"; | ||
import { screamingKebabToCamel } from "../screaming-kebab/camel"; | ||
import { screamingKebabToKebab } from "../screaming-kebab/kebab"; | ||
import { screamingKebabToPascal } from "../screaming-kebab/pascal"; | ||
import { screamingKebabToScreamingSnake } from "../screaming-kebab/screaming-snake"; | ||
import { screamingKebabToSnake } from "../screaming-kebab/snake"; | ||
|
||
export const fromScreamingKebab = { | ||
snake: screamingKebabToSnake, | ||
kebab: screamingKebabToKebab, | ||
screamingSnake: screamingKebabToScreamingSnake, | ||
screamingKebab: keep, | ||
camel: screamingKebabToCamel, | ||
pascal: screamingKebabToPascal, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { keep } from "../keep"; | ||
import { screamingSnakeToCamel } from "../screaming-snake/camel"; | ||
import { screamingSnakeToKebab } from "../screaming-snake/kebab"; | ||
import { screamingSnakeToPascal } from "../screaming-snake/pascal"; | ||
import { screamingSnakeToScreamingKebab } from "../screaming-snake/screaming-kebab"; | ||
import { screamingSnakeToSnake } from "../screaming-snake/snake"; | ||
|
||
export const fromScreamingSnake = { | ||
snake: screamingSnakeToSnake, | ||
kebab: screamingSnakeToKebab, | ||
screamingSnake: keep, | ||
screamingKebab: screamingSnakeToScreamingKebab, | ||
camel: screamingSnakeToCamel, | ||
pascal: screamingSnakeToPascal, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { keep } from "../keep"; | ||
import { snakeToCamel } from "../snake/camel"; | ||
import { snakeToKebab } from "../snake/kebab"; | ||
import { snakeToPascal } from "../snake/pascal"; | ||
import { snakeToScreamingKebab } from "../snake/screaming-kebab"; | ||
import { snakeToScreamingSnake } from "../snake/screaming-snake"; | ||
|
||
export const fromSnake = { | ||
snake: keep, | ||
kebab: snakeToKebab, | ||
screamingSnake: snakeToScreamingSnake, | ||
screamingKebab: snakeToScreamingKebab, | ||
camel: snakeToCamel, | ||
pascal: snakeToPascal, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { is } from "./is"; | ||
import { Variant } from "./types"; | ||
import { variants } from "./variants"; | ||
|
||
export const getCase = (value: string): Variant | "unknown" | "uppercase" | "lowercase" => { | ||
for (const variant of variants) { | ||
if (is[variant](value)) { | ||
return variant; | ||
} | ||
} | ||
if (!/[-_a-z]/.exec(value)) { | ||
return "uppercase"; | ||
} | ||
if (!/[-_A-Z]/.exec(value)) { | ||
return "lowercase"; | ||
} | ||
return "unknown"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { toCase } from "./to-case"; | ||
|
||
export default toCase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isButton } from "./is/button"; | ||
import { isCamel } from "./is/camel"; | ||
import { isKebab } from "./is/kebab"; | ||
import { isLower } from "./is/lower"; | ||
import { isPascal } from "./is/pascal"; | ||
import { isScreamingKebab } from "./is/screaming-kebab"; | ||
import { isScreamingSnake } from "./is/screaming-snake"; | ||
import { isSentence } from "./is/sentence"; | ||
import { isSnake } from "./is/snake"; | ||
import { isUpper } from "./is/upper"; | ||
|
||
export const is = { | ||
camel: isCamel, | ||
pascal: isPascal, | ||
kebab: isKebab, | ||
snake: isSnake, | ||
screamingKebab: isScreamingKebab, | ||
screamingSnake: isScreamingSnake, | ||
lower: isLower, | ||
upper: isUpper, | ||
sentence: isSentence, | ||
button: isButton, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const buttonPattern = /^[A-Z]([a-z0-9]+)(\s([A-Z][a-z0-9]+)+)+$/; | ||
export const isButton = (value: string) => Boolean(buttonPattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const camelPattern = /^[a-z]([0-9a-z]+)?[A-Z]([a-zA-Z0-9]+)?$/; | ||
export const isCamel = (value: string) => Boolean(camelPattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const kebabPattern = /^[a-z]+([a-z0-9]+)?(-[a-z0-9]+)+$/; | ||
export const isKebab = (value: string) => Boolean(kebabPattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const lowerPattern = /^[a-z]([a-z0-9]+)?$/; | ||
export const isLower = (value: string) => Boolean(lowerPattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const pascalPattern = /^[A-Z]+[a-z0-9]+([A-Z]([a-z0-9]+))+$/; | ||
export const isPascal = (value: string) => Boolean(pascalPattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const screamingKebabPattern = /^[A-Z]([A-Z0-9]+)?(-[A-Z0-9]+)+$/; | ||
export const isScreamingKebab = (value: string) => Boolean(screamingKebabPattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const screamingSnakePattern = /^[A-Z]([A-Z0-9]+)?(_[A-Z0-9]+)+$/; | ||
export const isScreamingSnake = (value: string) => Boolean(screamingSnakePattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const sentencePattern = /^[A-Z]([a-z0-9\s]+)$/; | ||
export const isSentence = (value: string) => Boolean(sentencePattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const snakePattern = /^[a-z]([a-z0-9]+)?(_[a-z0-9]+)+$/; | ||
export const isSnake = (value: string) => Boolean(snakePattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const upperPattern = /^[A-Z]([A-Z0-9]+)?$/; | ||
export const isUpper = (value: string) => Boolean(upperPattern.exec(value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const kebabToCamel = (value: string) => | ||
value.replace(/-([a-z])/g, (match, $1) => $1.toUpperCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const kebabToPascal = (value: string) => | ||
value | ||
.replace(/-([a-z])/g, (match, $1) => $1.toUpperCase()) | ||
.replace(/^([a-z])/, (match, $1) => $1.toUpperCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const kebabToScreamingKebab = (value: string) => value.toUpperCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const kebabToScreamingSnake = (value: string) => | ||
value.replace(/-([a-z])/g, (match, $1) => `_${$1}`).toUpperCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const kebabToSnake = (value: string) => value.replace(/-([a-z])/g, (match, $1) => `_${$1}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const keep = (value: string) => value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const pascalToCamel = (value: string) => | ||
value.replace(/^([A-Z])/, (match, $1) => $1.toLowerCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const pascalToKebab = (value: string) => | ||
value | ||
.replace(/([A-Z])/g, (match, $1) => `-${$1}`) | ||
.toLowerCase() | ||
.substr(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const pascalToScreamingKebab = (value: string) => | ||
value | ||
.replace(/([A-Z])/g, (match, $1) => `-${$1}`) | ||
.toUpperCase() | ||
.substr(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const pascalToScreamingSnake = (value: string) => | ||
value | ||
.replace(/([A-Z])/g, (match, $1) => `_${$1}`) | ||
.toUpperCase() | ||
.substr(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const pascalToSnake = (value: string) => | ||
value | ||
.replace(/([A-Z])/g, (match, $1) => `_${$1}`) | ||
.toLowerCase() | ||
.substr(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { kebabToCamel } from "../kebab/camel"; | ||
|
||
export const screamingKebabToCamel = (value: string) => kebabToCamel(value.toLowerCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const screamingKebabToKebab = (value: string) => value.toLowerCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { kebabToPascal } from "../kebab/pascal"; | ||
|
||
export const screamingKebabToPascal = (value: string) => kebabToPascal(value.toLowerCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const screamingKebabToScreamingSnake = (value: string) => value.replace(/-/g, "_"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { kebabToSnake } from "../kebab/snake"; | ||
|
||
export const screamingKebabToSnake = (value: string) => kebabToSnake(value.toLowerCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { snakeToCamel } from "../snake/camel"; | ||
|
||
export const screamingSnakeToCamel = (value: string) => snakeToCamel(value.toLowerCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { snakeToKebab } from "../snake/kebab"; | ||
|
||
export const screamingSnakeToKebab = (value: string) => snakeToKebab(value.toLowerCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { snakeToPascal } from "../snake/pascal"; | ||
|
||
export const screamingSnakeToPascal = (value: string) => snakeToPascal(value.toLowerCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const screamingSnakeToScreamingKebab = (value: string) => value.replace(/_/g, "-"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const screamingSnakeToSnake = (value: string) => value.toLowerCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const snakeToCamel = (value: string) => | ||
value.replace(/_([a-z])/g, (match, $1) => $1.toUpperCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const snakeToKebab = (value: string) => value.replace(/_([a-z])/g, (match, $1) => `-${$1}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const snakeToPascal = (value: string) => | ||
value | ||
.replace(/_([a-z])/g, (match, $1) => $1.toUpperCase()) | ||
.replace(/^([a-z])/, (match, $1) => $1.toUpperCase()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const snakeToScreamingKebab = (value: string) => | ||
value.replace(/_([a-z])/g, (match, $1) => `-${$1}`).toUpperCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const snakeToScreamingSnake = (value: string) => value.toUpperCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getCase } from "./get-case"; | ||
import { toCamel } from "./to/camel"; | ||
|
||
export const toCamelCase = (value: string) => toCamel[getCase(value)](value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { convert } from "./convert"; | ||
import { getCase } from "./get-case"; | ||
import { Variant } from "./types"; | ||
|
||
export const toCase = (value: string, nextCase: Variant) => { | ||
const previousCase = getCase(value); | ||
switch (previousCase) { | ||
case "camel": | ||
case "pascal": | ||
case "kebab": | ||
case "snake": | ||
case "screamingKebab": | ||
case "screamingSnake": | ||
return convert[previousCase].to[nextCase](value); | ||
case "unknown": | ||
case "uppercase": | ||
case "lowercase": | ||
default: | ||
return value; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getCase } from "./get-case"; | ||
import { toKebab } from "./to/kebab"; | ||
|
||
export const toKebabCase = (value: string) => toKebab[getCase(value)](value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getCase } from "./get-case"; | ||
import { toPascal } from "./to/pascal"; | ||
|
||
export const toPascalCase = (value: string) => toPascal[getCase(value)](value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getCase } from "./get-case"; | ||
import { toScreamingKebab } from "./to/screaming-kebab"; | ||
|
||
export const toScreamingKebabCase = (value: string) => toScreamingKebab[getCase(value)](value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getCase } from "./get-case"; | ||
import { toScreamingSnake } from "./to/screaming-snake"; | ||
|
||
export const toScreamingSnakeCase = (value: string) => toScreamingSnake[getCase(value)](value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getCase } from "./get-case"; | ||
import { toSnake } from "./to/snake"; | ||
|
||
export const toSnakeCase = (value: string) => toSnake[getCase(value)](value); |
Oops, something went wrong.