@adiranids/strcaseconvert
v0.0.1
Published
light weight package to convert string from one form to another
Downloads
3
Readme
String case converter
A light weight package to convert string from one case to another.
Installation
Using NPM
npm install @adiranids/strcaseconvert --save
Using CDN
<script src="https://unpkg.com/@adiranids/[email protected]"></script>
Usage
Currently these cases are supported
camelCase, kebab-case, snake_case, sentence case
1. Camel case to sentence case and vice versa
Using NPM
import {camelToSentence} from '@adiranids/strcaseconvert'
const result = camelToSentence("adityaKadam")
console.log(result)
//Aditya Kadam
Using CDN
<!-- insert the script tag in your HTML head section -->
const result = camelToSentence("adityaKadam")
console.log(result)
//Aditya Kadam
The function takes following parameters camelToSentence(strToConvert, firstLetterCapital=true, reverseFlag=false)
If you want first letter in lowercase or the original case then just pass second parameter as false
const result = camelToSentence("adityaKadam", false)
console.log(result)
//aditya Kadam
To convert from sentence case to camel case, pass third parameter as true.
const result = camelToSentence("aditya kadam", false, true)
console.log(result)
//adityaKadam
2. Convert from snake or kebab case to sentence case and vice versa
Using NPM
import {convertToSentence} from '@adiranids/strcaseconvert'
const result = convertToSentence("snake", "aditya-kadam")
console.log(result)
//Aditya kadam
Using CDN
<!-- insert the script tag in your HTML head section -->
const result = convertToSentence("snake", "aditya-kadam")
console.log(result)
//Aditya kadam
The function has following parameters
convertToSentence(from, originalText, firstLetterCapital = true, reverseFlag=false)
from -> possible values 'snake', 'kebab'
originalText -> depending on the value of from the text can be either snake or kebab case string. If you want to reverse convert then this originalText should be in sentence case.
firstLetterCapital -> determines whether the first letter should be capital or not. By default true ,
reverseFlag -> if set to true then converts sentence case to from case. By default false.
3. Convert from one case to another
Using NPM
import {convert} from '@adiranids/strcaseconvert'
const result = convert("kebab", "snake", "aditya-kadam")
console.log(result)
//aditya_kadam
Using CDN
<!-- insert the script tag in your HTML head section -->
const result = convert("kebab", "snake", "aditya-kadam")
console.log(result)
//aditya_kadam
The function has following parameters
convert(from, to, originalText, firstLetterCapital)
from and to can have following possible values
'snake', 'kebab', 'camel'
depending on from value originalText must be in respective case.
firstLetterCapital here is by default set to false. If the first letter needs to be upper case then just set this value to true.
License
MIT License
Copyright (c) 2021 Adirani Digital Solutions Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.