StringJs
StringJs is a library that introduces useful and easy functions to manipulate strings in JavaScript

Features
- import this package in your project
- choose a string and the right function in this library
- now you have your formatted string!
Installation
npm install --save stringjs
or
yarn add stringjs
How To Import and Use
const stringjs = require('stringjs')
or
import stringjs from 'stringjs'
After this import you can use any function provided in the section below with this call structure
stringjs.capitalizeFirst()
Functions and Methods
capitalizeFirst | a string | The string with the first letter capitalized |
capitalizeLast | a string | The string with the last letter capitalized |
capitalizeByIndex | a string and a parameter of type number , array or function
| The string with the letter in the index provided (zero-based) capitalized. - In case the provided second parameter is an
array of integers, the string is capitalized in all the index positions - In case the provided second parameter is a
function , the function is used to test if the index matches the boolean condition of the function and then makes that character in uppercase If the index is greater then the string's length, returns the string as provided |
capitalizeByLetter | a string and a parameter of type number , array or function
| Converts in uppercase all the occurencies of the letter provided - In case the provided second parameter is an
array of characters, all the letters included in the array are converted in uppercase - In case the provided second parameter is a
function , the function is used to test if the letter matches the boolean condition of the function and then makes that characters in uppercase
|
deCapitalizeFirst | a string | The string with the first letter decapitalized |
deCapitalizeLast | a string | The string with the last letter decapitalized |
deCapitalizeByIndex | a string and a parameter of type number , array or function
| The string with the letter in the index provided (zero-based) capitalized. - In case the provided second parameter is an
array of integers, the string is decapitalized in all the index positions - In case the provided second parameter is a
function , the function is used to test if the index matches the boolean condition of the function and then makes that character in lowercase If the index is greater then the string's length, returns the string as provided |
deCapitalizeByLetter | a string and a parameter of type number , array or function
| Converts in lowercase all the occurencies of the letter provided - In case the provided second parameter is an
array of characters, all the letters included in the array are converted in lowercase - In case the provided second parameter is a
function , the function is used to test if the letter matches the boolean condition of the function and then makes that characters in lowercase
|
Working Examples
capitalizeFirst
stringjs.capitalizeFirst('my cool string')
capitalizeLast
stringjs.capitalizeLast('my cool string')
capitalizeByIndex
stringjs.capitalizeByIndex('my cool string', 3)
stringjs.capitalizeByIndex('my cool string', 50)
stringjs.capitalizeByIndex('my cool string', [0, 1, 5, 20, 6, 13])
stringjs.capitalizeByIndex('my cool string', (i) => { return i === 3 || i === 5 })
capitalizeByLetter
stringjs.capitalizeByLetter('test', 't')
stringjs.capitalizeByLetter('test', ['t', 'e'])
stringjs.capitalizeByLetter('test', (l) => { return l === 'e' || l === 's' })
deCapitalizeFirst
stringjs.deCapitalizeFirst('TEST')
deCapitalizeLast
stringjs.deCapitalizeLast('TEST')
deCapitalizeByIndex
stringjs.deCapitalizeByIndex('MY COOL STRING', 3)
stringjs.deCapitalizeByIndex('MY COOL STRING', 50)
stringjs.deCapitalizeByIndex('MY COOL STRING', [0, 1, 5, 20, 6, 13])
stringjs.deCapitalizeByIndex('MY COOL STRING', (i) => { return i === 3 || i === 5 })
deCapitalizeByLetter
stringjs.deCapitalizeByLetter('TEST', 'T')
stringjs.deCapitalizeByLetter('TEST', ['T', 'E'])
stringjs.deCapitalizeByLetter('TEST', (l) => { return l === 'E' || l === 'S' })
License
MIT