Skip to content

Latest commit

 

History

History
61 lines (44 loc) · 1.42 KB

README.md

File metadata and controls

61 lines (44 loc) · 1.42 KB

ConvConv

Super simple, zero dependency naming convention converter and validator library.

Cli

As of version 0.3.3 there is cli version of convconv available. Use the following command to install it globally onto your system. npm i -g convconv You can see help for cli by running the following command. convconv --help

Examples

import convconv from "convconv";

// examples:
//   camelCase
//   kebab-case
//   PascalCase
//   snake_case
//   SCREAMING-KEBAB-CASE
//   SCREAMING_SNAKE_CASE

// converts camelCase to kebab-case
// camelCase -> camel-case
convconv.fromCamel("camelCase").toKebab();

// converts kebab-case to snake_case
// kebab-case -> kebab_case
convconv.fromConvention("kebab", "kebab-case").toSnake();

// converts any case to PascalCase
convconv
  .autoFrom("your-input-in-one-of-available-naming-conventions")
  .toPascal();

// throws ConventionNotFoundError
convconv.autoFrom("Random_sTring-with_nOConvention");

// returns 'kebab'
convconv.getConvention("some-kebab-case-string");

// throws ConventionNotFoundError
convconv.getConvention("Random_sTring-with_nOConvention");

// returns true
convconv.isPascal("PascalCase");

// returns true
convconv.isConvention("pascal", "PascalCase");

// throws ConventionViolationError
convconv.fromKebab("NotKebab");

// throws ConventionViolationError
convconv.fromCamel("123startingWithNumber");

Errors

All errors extend from ConvConvError.