@kaspernj/api-maker 1.0.365 → 1.0.366
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/url-encode.mjs +6 -7
package/package.json
CHANGED
package/src/url-encode.mjs
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
import escapeStringRegexp from "escape-string-regexp"
|
|
2
|
+
|
|
1
3
|
const replaces = {
|
|
2
4
|
" ": "+",
|
|
3
5
|
"&": "%26",
|
|
4
6
|
"#": "%23",
|
|
7
|
+
"+": "%2B",
|
|
5
8
|
"/": "%2F",
|
|
6
9
|
"?": "%3F"
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
const
|
|
10
|
-
return `${string}`.replaceAll(/( |&|#|\/|\?)/g, (character) => {
|
|
11
|
-
if (!(character in replaces)) {
|
|
12
|
-
throw new Error(`Didn't exist in replaces: "${character}"`)
|
|
13
|
-
}
|
|
12
|
+
const regexp = new RegExp(`(${Object.keys(replaces).map(escapeStringRegexp).join("|")})`, "g")
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const urlEncode = (string) => {
|
|
15
|
+
return String(string).replaceAll(regexp, (character) => replaces[character])
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export default urlEncode
|