convert-case Docs

A simple package to switch between multiple case standards effortlessly.

View the Project on GitHub ParadoxInfinite/convert-case

convert-case Docs

Unit Tests GitHub version npm version

A simple package to switch between multiple case standards effortlessly.

Note: This is still under active development, keep an eye out for new features!

Important note

While using the object related functions, make sure your object is not polluted with mixed cases for keys. Errors, other than validations, are no longer thrown but console.errored. So, please be sure to check (error) logs before raising a bug on this.


Installation and Usage

  1. Run the following to install the package
     npm install @paradoxinfinite/convert-case
     # OR
     npm i @paradoxinfinite/convert-case
    
  2. Import the package as
     const convertCase = require('@paradoxinfinite/convert-case');
     // OR
     import convertCase from '@paradoxinfinite/convert-case';
    
  3. Use one of the functions after the import
     const camelCaseString = convertCase.snakeToCamel('hello_world');
     console.log(camelCaseString);
     // Outputs: helloWorld
    

Functions

  1. snakeToCamel()
  2. snakeToKebab()
  3. snakeToPascal()
  4. kebabToCamel()
  5. kebabToSnake()
  6. kebabToPascal()
  7. pascalToCamel()
  8. pascalToSnake()
  9. pascalToKebab()
  10. camelToSnake()
  11. camelToKebab()
  12. camelToPascal()
  13. objSnakeToCamel()
  14. objSnakeToPascal()
  15. objSnakeToKebab()
  16. objCamelToSnake()
  17. objCamelToPascal()
  18. objCamelToKebab()
  19. objPascalToSnake()
  20. objPascalToCamel()
  21. objPascalToKebab()
  22. objKebabToPascal()
  23. objKebabToSnake()
  24. objKebabToCamel()

Contributing

  1. Test Cases: I would really appreciate any help on writing test cases for this package. The more testing it gets, the better it will be.

  2. Bug fixes and feature development: If you want to contribute to the code, feel free to raise a PR as long as it’s a minor change. For a major change, please open an issue and discuss it out before you raise a PR or even get started with coding!

  3. Feature requests: Feature requests will be great, raise an issue with the feature template to let me know what feature you would like added.

  4. Documentation: Documentation and examples are also an amazing way to contribute, so if you notice any mistakes or want to add more content to the docs, you are more than welcome to!


Examples

All examples assume you’ve installed and imported the package by following this.

  1. snakeToCamel()
     console.log(snakeToCamel('convert_case'));
     // Outputs: convertCase
    
  2. snakeToKebab()
     console.log(snakeToKebab('convert_case'));
     // Outputs: convert-case
    
  3. snakeToPascal()
     console.log(snakeToPascal('convert_case'));
     // Outputs: ConvertCase
    
  4. kebabToCamel()
     console.log(kebabToCamel('convert-case'));
     // Outputs: convertCase
    
  5. kebabToSnake()
     console.log(kebabToSnake('convert-case'));
     // Outputs: convert_case
    
  6. kebabToPascal()
     console.log(kebabToPascal('convert-case'));
     // Outputs: ConvertCase
    
  7. pascalToCamel()
     console.log(pascalToCamel('ConvertCase'));
     // Outputs: convertCase
    
  8. pascalToSnake()
     console.log(pascalToSnake('ConvertCase'));
     // Outputs: convert_case
    
  9. pascalToKebab()
     console.log(pascalToKebab('ConvertCase'));
     // Outputs: convert-case
    
  10. camelToSnake()
     console.log(camelToSnake('convertCase'));
     // Outputs: convert_case
    
  11. camelToKebab()
     console.log(camelToKebab('convertCase'));
     // Outputs: convert-case
    
  12. camelToPascal()
     console.log(camelToPascal('convertCase'));
     // Outputs: ConvertCase
    
  13. objSnakeToCamel()
     console.log(objSnakeToCamel({
       key_one: 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    keyOne: 'random value',
     //    key: 3
     //  }
    
  14. objSnakeToPascal()
     console.log(objSnakeToPascal({
       key_one: 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    KeyOne: 'random value',
     //    Key: 3
     //  }
    
  15. objSnakeToKebab()
     console.log(objSnakeToKebab({
       key_one: 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    'key-one': 'random value',
     //    key: 3
     //  }
    
  16. objCamelToSnake()
     console.log(objCamelToSnake({
       keyOne: 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    key_one: 'random value',
     //    key: 3
     //  }
    
  17. objCamelToPascal()
     console.log(objCamelToPascal({
       keyOne: 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    KeyOne: 'random value',
     //    Key: 3
     //  }
    
  18. objCamelToKebab()
     console.log(objCamelToKebab({
       keyOne: 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    'key-one': 'random value',
     //    key: 3
     //  }
    
  19. objPascalToSnake()
     console.log(objPascalToSnake({
       KeyOne: 'random value',
       Key: 3
     }));
     // Outputs: 
     //  {
     //    key_one: 'random value',
     //    key: 3
     //  }
    
  20. objPascalToCamel()
     console.log(objPascalToCamel({
       KeyOne: 'random value',
       Key: 3
     }));
     // Outputs: 
     //  {
     //    keyOne: 'random value',
     //    key: 3
     //  }
    
  21. objPascalToKebab()
     console.log(objPascalToKebab({
       KeyOne: 'random value',
       Key: 3
     }));
     // Outputs: 
     //  {
     //    'key-one': 'random value',
     //    key: 3
     //  }
    
  22. objKebabToPascal()
     console.log(objKebabToPascal({
       'key-one': 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    KeyOne: 'random value',
     //    Key: 3
     //  }
    
  23. objKebabToSnake()
     console.log(objKebabToSnake({
       'key-one': 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    key_one: 'random value',
     //    key: 3
     //  }
    
  24. objKebabToCamel()
     console.log(objKebabToCamel({
       'key-one': 'random value',
       key: 3
     }));
     // Outputs: 
     //  {
     //    keyOne: 'random value',
     //    key: 3
     //  }