normalize-words
Features
- Automatic removal of spaces and tabs.
- Normalization of words with options:
UPPERCASE
,lowercase
,Uppercase the first letter of the string
,First letter of all capitalized words
. - Set the minimum string length to normalization.
- Set the maximum string size to normalization.
- Do not normalize words with specific length.
- Remove words from the string through a list (array).
- Remove characters from the string through a list (array).
- Enables user customized functions to complement normalization.
- Full Typescript compatibility.
API
Install with NPM or YARN:
$ npm i normalize-words
or
$ yarn add normalize-words
Function
Options {object}
Function Normalization
normalizeWords(): string
Returns the normalized string.
String normalization with removal spaces and/or words.
This function requires an object with the properties for normalizing the string.
;
Options
str: string
Original String to normalize.
This property is mandatory for normalization.
transformType: 'toUpper' | 'toLower' | 'toFirst' | 'toFirstAll'
This property is mandatory for type of normalization.
minLength: number
(Optional)
Minimum of characters required for normalization.
maxLength: number
(Optional)
Maximum character limit accepted for normalization.
ignoreByLength: number
(Optional)
Do not normalize words with a specific length.
removeWords: string[]
(Optional)
Removes specific words from the string based on the array list.
NOTE: Words list is not case sensitive.
removeCharacters: string[]
(Optional)
Remove specific characters from the string based on the array list.
NOTE: Words list is not case sensitive. Only one letter per index is allowed.
applyMethod: Function
(Optional)
Any function to perform after normalizing the string.
How to use
Examples:
- Basic Usage
- With "Word" Removal
- With "Character" Removal
- With Minimum and Maximum Character Length
- Do not normalize words with specific length
- Optional Function to string treatment
- Complete example of normalization
- Example of normalization with option reuse
Basic Usage:
{ transformType: 'toUpper' | 'toLower' | 'toFirst' | 'toFirstAll' }
const normalizeWords = ;;// Returns: "MY CRAZY STRING"
- Basic Typescript example:
;normalizeWords;// Returns: "My Crazy String"
With "Word" Removal:
const normalizeWords = ;;// Returns: "CRAZY STRING"
With "Character" Removal:
{ removeCharacters: string[] }
const normalizeWords = ;;// Returns: "CRAZ STRING"
With "Minimum and Maximum Character Length" to normalize:
{ minLength: number , maxLength: number }
const normalizeWords = ;;// Returns: "John Pallozo"
Do not normalize words with specific length:
const normalizeWords = ;;// Returns: "City of Venice is Located in Italy"// Note: The words: "is" and "in" have not been normalized.
Optional Function to string treatment:
const normalizeWords = ;;// Returns: "John Pallozo - Full Stack Developer."// Note: The parameter "normalizedString" in the fuction is mandatory because// it contains the "Normalized String" previously.
- Another example with Typescript:
;normalizeWords;// Returns: [ 'D', 'I', 'V', 'I', 'D', 'E', ' ', 'S', 'T', 'R', 'I', 'N', 'G']
Complete example of normalization:
const normalizeWords = ;;// Returns: "John Pallozo - Full Stack Developer."
Example of normalization with options reuse:
const normalizeWords = ;const baseOptions =transformType: 'toFirst'minLength: 5maxLength: 30ignoreByLength: 2;const options1 =...baseOptionsstr: 'my CrasY striNG';const options2 =...baseOptionsstr: 'john f pallozo!'transformType: 'toFirstAll'removeCharacters: '!';const mergedOptions =...options2{return `I'm , Full Stack Developer.`;};// RESULTS:;// Returns: "My crazy string";// Returns: "John F Pallozo";// Returns: "I'm John F Pallozo, Full Stack Developer."
Autor
@anselmodev |
---|