Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.6 KB
|
Line | |
---|
1 | # decode-uri-component
|
---|
2 |
|
---|
3 | [![Build Status](https://travis-ci.org/SamVerschueren/decode-uri-component.svg?branch=master)](https://travis-ci.org/SamVerschueren/decode-uri-component) [![Coverage Status](https://coveralls.io/repos/SamVerschueren/decode-uri-component/badge.svg?branch=master&service=github)](https://coveralls.io/github/SamVerschueren/decode-uri-component?branch=master)
|
---|
4 |
|
---|
5 | > A better [decodeURIComponent](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
|
---|
6 |
|
---|
7 |
|
---|
8 | ## Why?
|
---|
9 |
|
---|
10 | - Decodes `+` to a space.
|
---|
11 | - Converts the [BOM](https://en.wikipedia.org/wiki/Byte_order_mark) to a [replacement character](https://en.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character) `�`.
|
---|
12 | - Does not throw with invalid encoded input.
|
---|
13 | - Decodes as much of the string as possible.
|
---|
14 |
|
---|
15 |
|
---|
16 | ## Install
|
---|
17 |
|
---|
18 | ```
|
---|
19 | $ npm install --save decode-uri-component
|
---|
20 | ```
|
---|
21 |
|
---|
22 |
|
---|
23 | ## Usage
|
---|
24 |
|
---|
25 | ```js
|
---|
26 | const decodeUriComponent = require('decode-uri-component');
|
---|
27 |
|
---|
28 | decodeUriComponent('%25');
|
---|
29 | //=> '%'
|
---|
30 |
|
---|
31 | decodeUriComponent('%');
|
---|
32 | //=> '%'
|
---|
33 |
|
---|
34 | decodeUriComponent('st%C3%A5le');
|
---|
35 | //=> 'ståle'
|
---|
36 |
|
---|
37 | decodeUriComponent('%st%C3%A5le%');
|
---|
38 | //=> '%ståle%'
|
---|
39 |
|
---|
40 | decodeUriComponent('%%7Bst%C3%A5le%7D%');
|
---|
41 | //=> '%{ståle}%'
|
---|
42 |
|
---|
43 | decodeUriComponent('%7B%ab%%7C%de%%7D');
|
---|
44 | //=> '{%ab%|%de%}'
|
---|
45 |
|
---|
46 | decodeUriComponent('%FE%FF');
|
---|
47 | //=> '\uFFFD\uFFFD'
|
---|
48 |
|
---|
49 | decodeUriComponent('%C2');
|
---|
50 | //=> '\uFFFD'
|
---|
51 |
|
---|
52 | decodeUriComponent('%C2%B5');
|
---|
53 | //=> 'µ'
|
---|
54 | ```
|
---|
55 |
|
---|
56 |
|
---|
57 | ## API
|
---|
58 |
|
---|
59 | ### decodeUriComponent(encodedURI)
|
---|
60 |
|
---|
61 | #### encodedURI
|
---|
62 |
|
---|
63 | Type: `string`
|
---|
64 |
|
---|
65 | An encoded component of a Uniform Resource Identifier.
|
---|
66 |
|
---|
67 |
|
---|
68 | ## License
|
---|
69 |
|
---|
70 | MIT © [Sam Verschueren](https://github.com/SamVerschueren)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.