|
1 | | -import { isNumeric } from "./helpers.js" |
2 | | -const reserved = ["false", "true", "null", "undefined"] |
3 | | -const delimiters = ['"', "{", "["] |
| 1 | +import { isNumeric } from './helpers.js' |
| 2 | +const reserved = ['false', 'true', 'null', 'undefined'] |
| 3 | +const delimiters = ['"', '{', '['] |
4 | 4 | function encode(rawObject) { |
5 | 5 | const params = [] |
6 | 6 | for (const [key, value] of Object.entries(rawObject)) { |
7 | | - if ( |
8 | | - typeof value == "string" && |
9 | | - !isNumeric(value) && |
10 | | - !reserved.includes(value) && |
11 | | - !delimiters.includes(value[0]) |
12 | | - ) { |
| 7 | + if (typeof value == 'string' && !isNumeric(value) && !reserved.includes(value) && !delimiters.includes(value[0])) { |
13 | 8 | params.push(`${key}=${encodeURIComponent(value)}`) |
14 | 9 | } else if (value !== void 0) { |
15 | 10 | params.push(`${key}=${encodeURIComponent(JSON.stringify(value))}`) |
16 | 11 | } |
17 | 12 | } |
18 | | - return params.join("&") |
| 13 | + return params.join('&') |
19 | 14 | } |
20 | 15 | function decode(query) { |
21 | 16 | const encoding = query.encoding |
22 | 17 | for (const [key, value] of Object.entries(query)) { |
23 | 18 | if ( |
24 | | - encoding == "json" || |
25 | | - value == "null" || // not new, always been |
26 | | - value == "true" || // NEED TO FIND-REPLACE CODE THAT USES value == 'true' |
27 | | - value == "false" || // NEED TO FIND-REPLACE CODE THAT USES value == 'false' |
| 19 | + encoding == 'json' || |
| 20 | + value == 'null' || // not new, always been |
| 21 | + value == 'true' || // NEED TO FIND-REPLACE CODE THAT USES value == 'true' |
| 22 | + value == 'false' || // NEED TO FIND-REPLACE CODE THAT USES value == 'false' |
28 | 23 | isNumeric(value) || // NEED TO check |
29 | | - (typeof value == "string" && |
30 | | - value.startsWith('"') && |
31 | | - value.endsWith('"')) || |
32 | | - (typeof value == "string" && |
33 | | - value.startsWith("{") && |
34 | | - value.endsWith("}")) || |
35 | | - (value.startsWith("[") && value.endsWith("]")) |
| 24 | + (typeof value == 'string' && value.startsWith('"') && value.endsWith('"')) || |
| 25 | + (typeof value == 'string' && value.startsWith('{') && value.endsWith('}')) || |
| 26 | + (value.startsWith('[') && value.endsWith(']')) |
36 | 27 | ) |
37 | 28 | query[key] = JSON.parse(value) |
38 | 29 | } |
|
0 commit comments