|
4 | 4 |
|
5 | 5 | Provides an API with useful normalization functions. |
6 | 6 |
|
7 | | -## Getting Started |
| 7 | +## Install |
| 8 | + |
| 9 | +`normalize-text` is published under NPM registry, so you can install using any Node.js package manager. |
8 | 10 |
|
9 | 11 | ```sh |
10 | | -npm i normalize-text |
| 12 | +npm install normalize-text --save |
| 13 | + |
| 14 | +# If you're using Yarn. |
| 15 | +yarn add normalize-text |
11 | 16 | ``` |
12 | 17 |
|
| 18 | +## Usage |
| 19 | + |
13 | 20 | ```js |
14 | | -import normalize, { normalizeWhitespaces, normalizeDiacritics } from 'normalize-text' |
| 21 | +import normalize from 'normalize-text'; |
15 | 22 |
|
16 | | -const input = document.querySelector('input[name="name"]') |
17 | | -const name = normalize(input.value) |
| 23 | +const input = document.querySelector('input[name="name"]'); |
| 24 | +const name = normalize(input.value); |
18 | 25 | ``` |
19 | 26 |
|
20 | 27 | ## API |
21 | 28 |
|
22 | | -### `normalize: (string|Array<string>) => string` |
| 29 | +- `normalize` |
23 | 30 |
|
24 | | -Join arguments (when receives an `Array`), transform to lower case and normalize its whitespaces and diacritics. |
| 31 | + ```ts |
| 32 | + export default function normalize (values: string | Array<string>): string; |
| 33 | + ``` |
25 | 34 |
|
26 | | -```js |
27 | | -normalize([ |
28 | | - ' Olá, \n', |
29 | | - 'Vitor LUIz \tcavalcanti' |
30 | | -]) === 'ola, vitor luiz cavalcanti' |
31 | | -``` |
| 35 | + Join arguments (when receives an `Array`), normalize it's whitespaces, normalize it's diacritics and transform to lower case. |
32 | 36 |
|
33 | | -### `normalizeWhitespaces: (string) => string` |
| 37 | + ```js |
| 38 | + normalize([ |
| 39 | + ' Olá, \r\n', |
| 40 | + 'Fernanda \t MONtenegro' |
| 41 | + ]) |
| 42 | + // => 'ola, fernanda montenegro' |
| 43 | + ``` |
34 | 44 |
|
35 | | -Normalizes whitespaces, line-endings and tabs. |
| 45 | +- `normalizeWhitespaces` |
36 | 46 |
|
37 | | -```js |
38 | | -normalizeWhitespaces(' Vitor \nLuiz\tCavalcanti ') === 'Vitor Luiz Cavalcanti' |
39 | | -``` |
| 47 | + ```ts |
| 48 | + export function normalizeWhitespaces (value: string): string; |
| 49 | + ``` |
40 | 50 |
|
41 | | -### `normalizeDiacritics: (string) => string` |
| 51 | + Remove spaces from start and end, transform multiple spaces into single one and every space character into whitespace character. |
42 | 52 |
|
43 | | -Normalizes character accents and diacritics. |
| 53 | + ```js |
| 54 | + normalizeWhitespaces(' Fernanda \t Montenegro\r\n') |
| 55 | + // => 'Fernanda Montenegro' |
| 56 | + ``` |
44 | 57 |
|
45 | | -```js |
46 | | -normalizeDiacritics('Olá, você aí!') === 'Ola, voce ai!' |
47 | | -``` |
| 58 | +- `normalizeDiacritics` |
48 | 59 |
|
49 | | -### `normalizeParagraph: (string) => string` |
| 60 | + ```ts |
| 61 | + export function normalizeDiacritics (value: string): string; |
| 62 | + ``` |
50 | 63 |
|
51 | | -Normalize whitespaces, coloca ponto final |
| 64 | + Normalize diacritics removing diacritics (accents) from letters. |
52 | 65 |
|
53 | | -```js |
54 | | -normalizeParagraph('era uma vez no mundo encantando ') === 'Era uma vez no mundo encantado.' |
55 | | -``` |
| 66 | + ```js |
| 67 | + normalizeDiacritics('Olá, você aí!') |
| 68 | + // => 'Ola, voce ai!' |
| 69 | + ``` |
| 70 | + |
| 71 | +- `normalizeParagraph` |
| 72 | + |
| 73 | + ```ts |
| 74 | + export function normalizeParagraph (value: string): string; |
| 75 | + ``` |
| 76 | + |
| 77 | + Normalize a paragraph. Normalize it's whitespaces, transform first letter to upper case and put a dot at end. |
| 78 | + |
| 79 | + ```js |
| 80 | + normalizeParagraph('hello world, my friend\r\n') |
| 81 | + // => 'Hello world, my friend.' |
| 82 | + ``` |
56 | 83 |
|
57 | 84 | ## License |
58 | 85 |
|
|
0 commit comments