String Case Transformations Made Simple With The lucky-case JS Library

Category: Javascript , Text | September 13, 2023
Author:magynhard
Views Total:17 views
Official Page:Go to website
Last Update:September 13, 2023
License:MIT

Preview:

String Case Transformations Made Simple With The lucky-case JS Library

Description:

Tired of manually converting between different naming conventions like snake_case and PascalCase? The lucky-case JavaScript library takes the tedium out of case conversion.

This powerful library library provides a full suite of case converters, transformers, checkers, and utilities for managing string cases.

Key Features:

  • One-line conversion between snake_case, PascalCase, camelCase, and more
  • Functions to swap, capitalize, lowercase, and more
  • Checks if a string matches a case style
  • Gets the likely case format(s) of a string
  • Handles Unicode and special characters
  • Simpler than regex or manual manipulation
  • Consistent naming adhering to conventions
  • Coding style guide enforcement made easy

How to use it:

1. Download and include the lucky-case JS library.

// Browser
<script src="/dist/lucky-case.min.js"></script>
// Node.js
const LuckyCase = require('lucky-case');

2. Usages.

// converters
LuckyCase.toSnakeCase('PascalToSnake') // => 'pascal_to_snake'
LuckyCase.toUpperSnakeCase('Train-To-Upper-Snake') // => 'TRAIN_TO_UPPER_SNAKE'
LuckyCase.toPascalCase('snake_to_pascal') // => 'SnakeToPascal'
LuckyCase.toCamelCase('dash-to-camel-case') // => 'dashToCamelCase'
LuckyCase.toDashCase('PascalToDashCase') // => 'pascal-to-dash-case'
LuckyCase.toUpperDashCase('PascalToUpperDash') // => 'PASCAL-TO-UPPER-DASH'
LuckyCase.toTrainCase('snake_to_train_case') // => 'Snake-To-Train-Case'
LuckyCase.toWordCase('PascalToWordCase') // => 'pascal to word case'
LuckyCase.toUpperWordCase('PascalToUpperWord') // => 'PASCAL TO UPPER WORD'
LuckyCase.toCapitalWordCase('snake_to_capital_word') // => 'Snake To Capital Word'
LuckyCase.toSentenceCase('snake_to_sentence_case') // => 'Snake to sentence case'
LuckyCase.toMixedCase('example_snake_string') // => 'Example-snake_STRING'
// converter by type
LuckyCase.convertCase('some_snake', 'PASCAL_CASE') // => 'SomeSnake'
// transformers
LuckyCase.toLowerCase('Some_FuckingShit') // => 'some_fuckingshit'
LuckyCase.toUpperCase('Some_FuckingShit') // => 'SOME_FUCKINGSHIT'
LuckyCase.toCapital('example') // => 'Example'
LuckyCase.capitalize('exAmple') // => 'ExAmple'
LuckyCase.decapitalize('ExAmple') // => 'exAmple'
LuckyCase.swapCase('SomeSwappy_Case-Example') // => 'sOMEsWAPPY-cASE_eXAMPLE'
LuckyCase.constantize('some_constant') // => SomeConstant
LuckyCase.constantize('SOME_CONSTANT') // => SomeConstant
LuckyCase.constantize('some/path_example/folder') // => SomePathExampleFolder
LuckyCase.deconstantize(SomeConstant) // => 'someConstant' // default caseType: 'CAMEL_CASE'
LuckyCase.deconstantize(SomeConstant, caseType: 'SNAKE_CASE') // => 'some_constant'
// identifiers
LuckyCase.case('this_can_only_be_snake_case') // => 'SNAKE_CASE'
LuckyCase.cases('validformultiple') // => [ 'SNAKE_CASE', 'CAMEL_CASE', 'DASH_CASE', 'WORD_CASE' ]
// checkers
LuckyCase.isSnakeCase('valid_snake_case') // => true
LuckyCase.isUpperSnakeCase('UPPER_SNAKE') // => true
LuckyCase.isPascalCase('PascalCase') // => true
LuckyCase.isCamelCase('toCamelCase') // => true
LuckyCase.isDashCase('dash-case') // => true
LuckyCase.isUpperDashCase('DASH-CASE') // => true
LuckyCase.isTrainCase('Train-Case') // => true
LuckyCase.isWordCase('word case') // => true
LuckyCase.isUpperWordCase('UPPER WORD CASE') // => true
LuckyCase.isCapitalWordCase('Capital Word Case') // => true
LuckyCase.isSentenceCase('Sentence case string') // => true
LuckyCase.isMixedCase('mixed_Case') // => true
LuckyCase.isUpperCase('UPPER50984') // => true
LuckyCase.isLowerCase('lower_cheese') // => true
LuckyCase.isCapital('Some') // => true
LuckyCase.isCapitalized('some') // => false
LuckyCase.isNotCapital('soMe') // => true
LuckyCase.isDecapitalized('somE') // => true
LuckyCase.isValidCaseType('SNAKE_CASE') // => true
LuckyCase.isValidCaseType('APPLE_CASE') // => false
LuckyCase.isValidCaseString('validString') // => true
LuckyCase.isValidCaseString('1nV4lid$tring') // => false

You Might Be Interested In:


Leave a Reply