UNPKG

1.96 kBMarkdownView Raw
1# decode-uri-component
2
3![CI](https://github.com/SamVerschueren/decode-uri-component/workflows/CI/badge.svg) [![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- 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) `�`.
11- Does not throw with invalid encoded input.
12- Decodes as much of the string as possible.
13
14
15## Install
16
17```
18$ npm install --save decode-uri-component
19```
20
21
22## Usage
23
24```js
25import decodeUriComponent from 'decode-uri-component';
26
27decodeUriComponent('%25');
28//=> '%'
29
30decodeUriComponent('%');
31//=> '%'
32
33decodeUriComponent('st%C3%A5le');
34//=> 'ståle'
35
36decodeUriComponent('%st%C3%A5le%');
37//=> '%ståle%'
38
39decodeUriComponent('%%7Bst%C3%A5le%7D%');
40//=> '%{ståle}%'
41
42decodeUriComponent('%7B%ab%%7C%de%%7D');
43//=> '{%ab%|%de%}'
44
45decodeUriComponent('%FE%FF');
46//=> '\uFFFD\uFFFD'
47
48decodeUriComponent('%C2');
49//=> '\uFFFD'
50
51decodeUriComponent('%C2%B5');
52//=> 'µ'
53```
54
55
56## API
57
58### decodeUriComponent(encodedURI)
59
60#### encodedURI
61
62Type: `string`
63
64An encoded component of a Uniform Resource Identifier.
65
66
67## License
68
69MIT © [Sam Verschueren](https://github.com/SamVerschueren)
70
71
72---
73
74<div align="center">
75 <b>
76 <a href="https://tidelift.com/subscription/pkg/npm-decode-uri-component?utm_source=npm-decode-uri-component&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
77 </b>
78 <br>
79 <sub>
80 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
81 </sub>
82</div>