README
Normalize Text
Provides a simple API to normalize texts, white-spaces, names, paragraphs & diacritics (accents).
📦 Distributions in ESM, CommonJS, UMD and UMD minified formats.
⚡ Lightweight:
🔋 Bateries included:
- Its not based on newer browser's APIs or es2015+ features.
- Only needs
String.prototype.normalize
polyfill for older browsers, and don't crashes without it.
🏷 Safe:
- Type declarations for IDEs and editor's autocomplete/intellisense.
- Made with TypeScript as strict as possible.
- Unit tests with Jest.
- Travis CI that keeps tests running.
Install
normalize-text
is published under NPM registry, so you can install using any Node.js package manager.
npm install normalize-text --save
# If you're using Yarn.
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.
<!-- Using default bundle from JSDelivr -->
<script src="https://cdn.jsdelivr.net/npm/normalize-text"></script>
<!-- Using default bundle from UNPKG -->
<script src="https://unpkg.com/normalize-text"></script>
<script>
/**
* UMD bundle expose brazilian-values through `normalizeText` object.
*/
normalizeText.capitalizeFirstLetter('vitor');
//=> "Vitor"
</script>
Usage
All the functions are named exported from module.
import { normalizeText } from 'normalize-text';
normalizeText([
'Olá\r\n',
' como está a senhorita?'
]);
//=> "ola como esta a senhorita?"
API
capitalizeFirstLetter
Capitalize first character of received text.
capitalizeFirstLetter('vitorLuizC');
//=> "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í');
//=> 'Ola, voce ai'
normalizeDiacritics('àáãâäéèêëíìîïóòõôöúùûüñçÀÁÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ');
//=> "aaaaaeeeeiiiiooooouuuuncAAAAAEEEEIIIIOOOOOUUUUNC"
normalizeDiacritics('@_