2.5.3 • Published 2 years ago

case-shift v2.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Case-Shift Simple npm package for converting the case from one format to another.

📦 Install with the help of npm or yarn

npm install case-shift
# or
yarn add case-shift

Case Conversion

The one case string converts the below to all the categories. Follow the further documentation.

camelCase

In this category, all the method converts the camelCase string to another category string. The camelCase method supports both lowerCamelCase(isAnString) and UpperCamelCase(IsAnString) strings for conversion.

const {
	camelToCapital,
	camelToConstant,
	camelToKebab,
	camelToPascal,
	camelToSnake
} = require("case-shift");
  • camelToCapital This method converts camelCase string to capital case.
console.log(camelToCapital("isAnString"));
// Is An String
  • camelToConstant This method converts camelCase string to constant case.
console.log(camelToConstant("isAnString"));
// IS_AN_STRING
  • camelToKebab This method converts camelCase string to kebab case. If the second argument is true, returns capital kebab case string, else small kebab case string. Defaults are true.
console.log(camelToKebab("isAnString"));
// Is-An-String
console.log(camelToKebab("isAnString", false));
// is-an-string
  • camelToPascal This method converts camelCase string to pascal case.
console.log(camelToPascal("isAnString"));
// IsAnString
  • camelToSnake This method converts camelCase string to snake case. If the second argument is true, returns capital snake case string, else small snake case string. Defaults are true.
console.log(camelToSnake("isAnString"));
// Is_An_String
console.log(camelToSnake("isAnString", false));
// is_an_string

Capital Case

In this category, all the method converts the Capital Case string to another category string.

const {
	capitalToCamel,
	capitalToConstant,
	capitalToKebab,
	capitalToPascal,
	capitalToSnake
} = require("case-shift");
  • capitalToCamel This method converts Capital Case string to camelCase case. If second optional argument is true return UpperCamelCase string, default false.
console.log(capitalToCamel("Is An String"));
// isAnString
console.log(capitalToCamel("Is An String", true));
// IsAnString
  • capitalToConstant This method converts Capital Case string to constant case.
console.log(capitalToConstant("Is An String"));
// IS_AN_STRING
  • capitalToKebab This method converts Capital Case string to kebab case. If the second argument is true, returns capital kebab case string, else small kebab case string. Defaults are true.
console.log(capitalToKebab("Is An String"));
// Is-An-String
console.log(capitalToKebab("Is An String", false));
// is-an-string
  • capitalToPascal This method converts Capital Case string to pascal case.
console.log(capitalToPascal("Is An String"));
// IsAnString
  • capitalToSnake This method converts Capital Case string to snake case. If the second argument is true, returns capital snake case string, else small snake case string. Defaults are true.
console.log(capitalToSnake("Is An String"));
// Is_An_String
console.log(capitalToSnake("Is An String", false));
// is_an_string

CONSTANT_CASE

In this category, all the method converts the CONSTANT_CASE string to another category string.

const {
	constantToCamel,
	constantToCapital,
	constantToKebab,
	constantToPascal,
	constantToSnake
} = require("case-shift");
  • constantToCamel This method converts CONSTANT_CASE string to camelCase case. If second optional argument is true return UpperCamelCase string, default false.
console.log(constantToCamel("IS_AN_STRING"));
// isAnString
console.log(constantToCamel("IS_AN_STRING", true));
// IsAnString
  • constantToCapital This method converts CONSTANT_CASE string to Capital Case string.
console.log(constantToCapital("IS_AN_STRING"));
// Is An String
  • constantToKebab This method converts CONSTANT_CASE string to kebab case. If the second argument is true, returns capital kebab case string, else small kebab case string. Defaults are true.
console.log(constantToKebab("IS_AN_STRING"));
// Is-An-String
console.log(constantToKebab("IS_AN_STRING", false));
// is-an-string
  • constantToPascal This method converts CONSTANT_CASE string to pascal case.
console.log(constantToPascal("IS_AN_STRING"));
// IsAnString
  • constantToSnake This method converts CONSTANT_CASE string to snake case. If the second argument is true, returns capital snake case string, else small snake case string. Defaults are true.
console.log(constantToSnake("IS_AN_STRING"));
// Is_An_String
console.log(constantToSnake("IS_AN_STRING", false));
// is_an_string

Kebab-Case

In this category, all the method converts the Kebab-Case string to another category string.

const {
	kebabToCamel,
	kebabToCapital,
	kebabToConstant,
	kebabToPascal,
	kebabToSnake
} = require("case-shift");
  • kebabToCamel This method converts Kebab-Case string to camelCase case. If second optional argument is true return UpperCamelCase string, default false.
console.log(kebabToCamel("Is-An-String"));
// isAnString
console.log(kebabToCamel("Is-An-String", true));
// IsAnString
  • kebabToCapital This method converts Kebab-Case string to Capital Case string.
console.log(kebabToCapital("Is-An-String"));
// Is An String
  • kebabToConstant This method converts Kebab-Case string to CONSTANT_CASE string.
console.log(kebabToConstant("Is-An-String"));
// IS_AN_STRING
  • kebabToPascal This method converts Kebab-Case string to pascal case.
console.log(kebabToPascal("Is-An-String"));
// IsAnString
  • kebabToSnake This method converts Kebab-Case string to snake_case. If the second argument is true, returns capital snake_case string, else small snake_case string. Defaults are true.
console.log(kebabToSnake("Is-An-String"));
// Is_An_String
console.log(kebabToSnake("Is-An-String", false));
// is_an_string

PascalCase

In this category, all the method converts the PascalCase string to another category string.

const {
	pascalToCamel,
	pascalToCapital,
	pascalToConstant,
	pascalToKebab,
	pascalToSnake
} = require("case-shift");
  • pascalToCamel This method converts PascalCase string to camelCase case. If second optional argument is true return UpperCamelCase string, default false.
console.log(pascalToCamel("IsAnString"));
// isAnString
console.log(pascalToCamel("IsAnString", true));
// IsAnString
  • pascalToCapital This method converts PascalCase string to Capital Case string.
console.log(pascalToCapital("IsAnString"));
// Is An String
  • pascalToConstant This method converts PascalCase string to CONSTANT_CASE string.
console.log(pascalToConstant("IsAnString"));
// IS_AN_STRING
  • pascalToKebab This method converts PascalCase string to kebab-case string. If the second argument is true, returns capital kebab case string, else small kebab case string. Defaults are true.
console.log(pascalToKebab("IsAnString"));
// Is-An-String
console.log(pascalToKebab("IsAnString", false));
// is-an-string
  • pascalToSnake This method converts PascalCase string to snake_case. If the second argument is true, returns capital snake_case string, else small snake_case string. Defaults are true.
console.log(pascalToSnake("IsAnString"));
// Is_An_String
console.log(pascalToSnake("IsAnString", false));
// is_an_string

Snake_Case

In this category, all the method converts the Snake_Case string to another category string.

const {
	snakeToCamel,
	snakeToCapital,
	snakeToConstant,
	snakeToPascal,
	snakeToKebab
} = require("case-shift");
  • snakeToCamel This method converts Snake_Case string to camelCase case. If second optional argument is true return UpperCamelCase string, default false.
console.log(snakeToCamel("is_an_string"));
// isAnString
console.log(snakeToCamel("is_an_string", true));
// IsAnString
  • snakeToCapital This method converts Snake_Case string to Capital Case string.
console.log(snakeToCapital("is_an_string"));
// Is An String
  • snakeToConstant This method converts Snake_Case string to CONSTANT_CASE string.
console.log(snakeToConstant("is_an_string"));
// IS_AN_STRING
  • snakeToPascal This method converts Snake_Case string to pascal case.
console.log(snakeToPascal("is_an_string"));
// IsAnString
  • snakeToKebab This method converts Snake_Case string to kebab-case. If the second argument is true, returns capital Kebab-Case string, else small kebab-case string. Defaults are true.
console.log(snakeToKebab("is_an_string"));
// Is-An-String
console.log(snakeToKebab("is_an_string", false));
// is-an-string