You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # decode-uri-component
  2. [![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)
  3. > A better [decodeURIComponent](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
  4. ## Why?
  5. - Decodes `+` to a space.
  6. - 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) `�`.
  7. - Does not throw with invalid encoded input.
  8. - Decodes as much of the string as possible.
  9. ## Install
  10. ```
  11. $ npm install --save decode-uri-component
  12. ```
  13. ## Usage
  14. ```js
  15. const decodeUriComponent = require('decode-uri-component');
  16. decodeUriComponent('%25');
  17. //=> '%'
  18. decodeUriComponent('%');
  19. //=> '%'
  20. decodeUriComponent('st%C3%A5le');
  21. //=> 'ståle'
  22. decodeUriComponent('%st%C3%A5le%');
  23. //=> '%ståle%'
  24. decodeUriComponent('%%7Bst%C3%A5le%7D%');
  25. //=> '%{ståle}%'
  26. decodeUriComponent('%7B%ab%%7C%de%%7D');
  27. //=> '{%ab%|%de%}'
  28. decodeUriComponent('%FE%FF');
  29. //=> '\uFFFD\uFFFD'
  30. decodeUriComponent('%C2');
  31. //=> '\uFFFD'
  32. decodeUriComponent('%C2%B5');
  33. //=> 'µ'
  34. ```
  35. ## API
  36. ### decodeUriComponent(encodedURI)
  37. #### encodedURI
  38. Type: `string`
  39. An encoded component of a Uniform Resource Identifier.
  40. ## License
  41. MIT © [Sam Verschueren](https://github.com/SamVerschueren)