main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
641 bytes
|
Line | |
---|
1 | import { pipe, replace } from 'ramda';
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * decodeURIComponent can throw URIError in certain cases like 'c%d'.
|
---|
5 | * safeDecodeURIComponent is a safe variant of decodeURIComponent that never trows.
|
---|
6 | *
|
---|
7 | * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI|More info about URIError}
|
---|
8 | */
|
---|
9 | const safeDecodeURIComponent = encodedURIComponent => {
|
---|
10 | try {
|
---|
11 | return decodeURIComponent(encodedURIComponent);
|
---|
12 | } catch {
|
---|
13 | return encodedURIComponent;
|
---|
14 | }
|
---|
15 | };
|
---|
16 |
|
---|
17 | // unescape :: String -> String
|
---|
18 | const unescape = pipe(replace(/~1/g, '/'), replace(/~0/g, '~'), safeDecodeURIComponent);
|
---|
19 | export default unescape; |
---|
Note:
See
TracBrowser
for help on using the repository browser.