Normalize Text
Provides a simple API to normalize texts, white-spaces, names, paragraphs & diacritics (accents).
Install
normalize-text
is published under NPM registry, so you can install using any Node.js package manager.
npm install normalize-text --save
yarn add normalize-text
Install from CDN
The bundles of this module are also available on JSDelivr and UNPKG CDNs.
In both you can import just the bundle you want or use default one, UMD.
<script src="https://cdn.jsdelivr.net/npm/normalize-text"></script>
<script src="https://unpkg.com/normalize-text"></script>
<script>
normalizeText.capitalizeFirstLetter('vitor');
</script>
Usage
All the functions are named exported from module.
import { normalizeText } from 'normalize-text';
normalizeText([
'Olá\r\n',
' como está a senhorita?'
]);
API
capitalizeFirstLetter
Capitalize first character of received text.
capitalizeFirstLetter('vitorLuizC');
normalizeDiacritics
If String.prototype.normalize
is supported it normalizes diacritics by replacing them with "clean" character from received text.
It doesn't normalize special characters.
normalizeDiacritics('Olá, você aí');
normalizeDiacritics('àáãâäéèêëíìîïóòõôöúùûüñçÀÁÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ');
normalizeDiacritics('@_$><=-#!,.`\'"');
normalizeName
Normalize received name by normalizing it's white-spaces and capitalizing first letter of every word but exceptions (received in lower-case).
normalizeName(' fernanDA MONTENEGRO');
normalizeName(' wilson da costa', ['da']);
normalizeParagraph
Normalize a paragraph by normalizing its white-spaces, capitalizing first letter and adding a period at end.
normalizeParagraph(' once upon a time');
normalizeParagraph('hello world, my friend\r\n');
normalizeText
Resolve received texts (when receives an Array
) by normalizing its white-spaces and its diacritics and transforming to lower-case.
normalizeText(' so there\'s a Way to NORMALIZE ');
normalizeText(['Olá\r\n', 'como está a senhorita?']);
normalizeWhiteSpaces
Normalize all white-space characters and remove trailing ones received text.
normalizeWhiteSpaces(' What exactly is it? ');
normalizeWhiteSpaces('Hi, how is \r\n everything \t?');
normalizeWhiteSpaces`It is ${temperature}\n degree\r outside. `
License
Released under MIT license. You can see it here.