@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaspernj/api-maker",
3
- "version": "1.0.365",
3
+ "version": "1.0.366",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -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 urlEncode = (string) => {
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
- return replaces[character]
16
- })
14
+ const urlEncode = (string) => {
15
+ return String(string).replaceAll(regexp, (character) => replaces[character])
17
16
  }
18
17
 
19
18
  export default urlEncode