Skip to content

Commit 691c8fa

Browse files
committed
📝 create new README docs
1 parent a18b8e8 commit 691c8fa

File tree

1 file changed

+69
-43
lines changed

1 file changed

+69
-43
lines changed

README.md

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Library minified size](https://badgen.net/bundlephobia/min/normalize-text)](https://bundlephobia.com/result?p=normalize-text)
66
[![Library minified + gzipped size](https://badgen.net/bundlephobia/minzip/normalize-text)](https://bundlephobia.com/result?p=normalize-text)
77

8-
Provides a simple API to normalize texts, white-spaces, paragraphs & diacritics.
8+
Provides a simple API to normalize texts, white-spaces, names, paragraphs & diacritics (accents).
99

1010
## Install
1111

@@ -18,90 +18,116 @@ npm install normalize-text --save
1818
yarn add normalize-text
1919
```
2020

21+
### Install from CDN
22+
23+
The bundles of this module are also available on JSDelivr and UNPKG CDNs.
24+
25+
In both you can import just the bundle you want or use default one, UMD.
26+
27+
```html
28+
<!-- Using default bundle from JSDelivr -->
29+
<script src="https://cdn.jsdelivr.net/npm/normalize-text"></script>
30+
31+
<!-- Using default bundle from UNPKG -->
32+
<script src="https://unpkg.com/normalize-text"></script>
33+
34+
<script>
35+
/**
36+
* UMD bundle expose brazilian-values through `normalizeText` object.
37+
*/
38+
normalizeText.capitalizeFirstLetter('vitor');
39+
//=> "Vitor"
40+
</script>
41+
```
42+
2143
## Usage
2244

45+
All the functions are named exported from module.
46+
2347
```js
24-
import normalize from 'normalize-text';
48+
import { normalizeText } from 'normalize-text';
2549

26-
const input = document.querySelector('input[name="name"]');
27-
const name = normalize(input.value);
50+
normalizeText([
51+
'Olá\r\n',
52+
' como está a senhorita?'
53+
]);
54+
//=> "ola como esta a senhorita?"
2855
```
2956

3057
## API
3158

32-
### `normalize`
59+
### `capitalizeFirstLetter`
3360

34-
Join arguments (when receives an `Array`), normalize it's whitespaces, normalize it's diacritics and transform to lower case.
61+
Capitalize first character of received text.
3562

3663
```js
37-
normalize([' Olá, \r\n', 'Fernanda \t MONtenegro']);
38-
// => 'ola, fernanda montenegro'
64+
capitalizeFirstLetter('vitorLuizC');
65+
//=> "VitorLuizC"
3966
```
4067

41-
#### Type definition
42-
43-
```ts
44-
export default function normalize(values: string | string[]): string;
45-
```
68+
### `normalizeDiacritics`
4669

47-
### `normalizeWhitespaces`
70+
If `String.prototype.normalize` is supported it normalizes diacritics by replacing them with "clean" character from received text.
4871

49-
Remove spaces from start and end, transform multiple spaces into single one and every space character into whitespace character.
72+
> It doesn't normalize special characters.
5073
5174
```js
52-
normalizeWhitespaces(' Fernanda \t Montenegro\r\n');
53-
// => 'Fernanda Montenegro'
54-
```
75+
normalizeDiacritics('Olá, você aí');
76+
//=> 'Ola, voce ai'
5577

56-
#### Type definition
78+
normalizeDiacritics('àáãâäéèêëíìîïóòõôöúùûüñçÀÁÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ');
79+
//=> "aaaaaeeeeiiiiooooouuuuncAAAAAEEEEIIIIOOOOOUUUUNC"
5780

58-
```ts
59-
export function normalizeWhitespaces(value: string): string;
81+
normalizeDiacritics('@_$><=-#!,.`\'"')
82+
//=> "@_$><=-#!,.`'\"";
6083
```
6184

62-
### `normalizeDiacritics`
85+
### `normalizeName`
6386

64-
Normalize diacritics removing diacritics (accents) from letters.
87+
Normalize received name by normalizing it's white-spaces and capitalizing first letter of every word but exceptions (received in lower-case).
6588

6689
```js
67-
normalizeDiacritics('Olá, você aí!');
68-
// => 'Ola, voce ai!'
69-
```
90+
normalizeName(' fernanDA MONTENEGRO');
91+
//=> "Fernanda Montenegro"
7092

71-
#### Type definition
72-
73-
```ts
74-
export function normalizeDiacritics(value: string): string;
93+
normalizeName(' wilson da costa', ['da']);
94+
//=> "Wilson da Costa"
7595
```
7696

7797
### `normalizeParagraph`
7898

79-
Normalize a paragraph. Normalize it's whitespaces, transform first letter to upper case and put a dot at end.
99+
Normalize a paragraph by normalizing its white-spaces, capitalizing first letter and adding a period at end.
80100

81101
```js
102+
normalizeParagraph(' once upon a time');
103+
//=> "Once upon a time."
104+
82105
normalizeParagraph('hello world, my friend\r\n');
83106
// => 'Hello world, my friend.'
84107
```
85108

86-
#### Type definition
109+
### `normalizeText`
110+
111+
Resolve received texts (when receives an `Array`) by normalizing its white-spaces and its diacritics and transforming to lower-case.
87112

88-
```ts
89-
export function normalizeParagraph(value: string): string;
113+
```js
114+
normalizeText(' so there\'s a Way to NORMALIZE ');
115+
//=> "so there\'s a way to normalize"
116+
117+
normalizeText(['Olá\r\n', 'como está a senhorita?']);
118+
//=> "ola como esta a senhorita?"
90119
```
91120

92-
### `normalizeName`
121+
### `normalizeWhiteSpaces`
93122

94-
Normalize a name. Normalize it's whitespaces and capitalize letters.
123+
Normalize all white-space characters and remove trailing ones received text.
95124

96125
```js
97-
normalizeName(' fernanda \tMONTENEGRO');
98-
// => 'Fernanda Montenegro'
99-
```
100-
101-
#### Type definition
126+
normalizeWhiteSpaces(' What exactly is it? ');
127+
//=> "What exactly is it?"
102128

103-
```ts
104-
export function normalizeName(value: string): string;
129+
normalizeWhiteSpaces('Hi, how is \r\n everything \t?');
130+
//=> 'Hi, how is everything ?'
105131
```
106132

107133
## License

0 commit comments

Comments
 (0)