| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,12 @@ const isHexTable = new Int8Array([ | |||
| 30 | 30 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // ... 256 | |
| 31 | 31 | ]); | |
| 32 | 32 | ||
| 33 | + /** | ||
| 34 | + * @param {string} str | ||
| 35 | + * @param {Int8Array} noEscapeTable | ||
| 36 | + * @param {string[]} hexTable | ||
| 37 | + * @returns {string} | ||
| 38 | + */ | ||
| 33 | 39 | function encodeStr(str, noEscapeTable, hexTable) { | |
| 34 | 40 | const len = str.length; | |
| 35 | 41 | if (len === 0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,12 @@ const unhexTable = new Int8Array([ | |||
| 72 | 72 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 73 | 73 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // ... 255 | |
| 74 | 74 | ]); | |
| 75 | - // A safe fast alternative to decodeURIComponent | ||
| 75 | + /** | ||
| 76 | + * A safe fast alternative to decodeURIComponent | ||
| 77 | + * @param {string} s | ||
| 78 | + * @param {boolean} decodeSpaces | ||
| 79 | + * @returns {string} | ||
| 80 | + */ | ||
| 76 | 81 | function unescapeBuffer(s, decodeSpaces) { | |
| 77 | 82 | const out = Buffer.allocUnsafe(s.length); | |
| 78 | 83 | let index = 0; | |
@@ -115,7 +120,11 @@ function unescapeBuffer(s, decodeSpaces) { | |||
| 115 | 120 | return hasHex ? out.slice(0, outIndex) : out; | |
| 116 | 121 | } | |
| 117 | 122 | ||
| 118 | - | ||
| 123 | + /** | ||
| 124 | + * @param {string} s | ||
| 125 | + * @param {boolean} decodeSpaces | ||
| 126 | + * @returns {string} | ||
| 127 | + */ | ||
| 119 | 128 | function qsUnescape(s, decodeSpaces) { | |
| 120 | 129 | try { | |
| 121 | 130 | return decodeURIComponent(s); | |
@@ -141,8 +150,13 @@ const noEscape = new Int8Array([ | |||
| 141 | 150 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111 | |
| 142 | 151 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 112 - 127 | |
| 143 | 152 | ]); | |
| 144 | - // QueryString.escape() replaces encodeURIComponent() | ||
| 145 | - // https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * QueryString.escape() replaces encodeURIComponent() | ||
| 156 | + * @see https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 | ||
| 157 | + * @param {any} str | ||
| 158 | + * @returns {string} | ||
| 159 | + */ | ||
| 146 | 160 | function qsEscape(str) { | |
| 147 | 161 | if (typeof str !== 'string') { | |
| 148 | 162 | if (typeof str === 'object') | |
@@ -154,6 +168,10 @@ function qsEscape(str) { | |||
| 154 | 168 | return encodeStr(str, noEscape, hexTable); | |
| 155 | 169 | } | |
| 156 | 170 | ||
| 171 | + /** | ||
| 172 | + * @param {string | number | bigint | boolean | symbol | undefined | null} v | ||
| 173 | + * @returns {string} | ||
| 174 | + */ | ||
| 157 | 175 | function stringifyPrimitive(v) { | |
| 158 | 176 | if (typeof v === 'string') | |
| 159 | 177 | return v; | |
@@ -166,7 +184,11 @@ function stringifyPrimitive(v) { | |||
| 166 | 184 | return ''; | |
| 167 | 185 | } | |
| 168 | 186 | ||
| 169 | - | ||
| 187 | + /** | ||
| 188 | + * @param {string | number | bigint | boolean} v | ||
| 189 | + * @param {(v: string) => string} encode | ||
| 190 | + * @returns | ||
| 191 | + */ | ||
| 170 | 192 | function encodeStringified(v, encode) { | |
| 171 | 193 | if (typeof v === 'string') | |
| 172 | 194 | return (v.length ? encode(v) : ''); | |
@@ -182,12 +204,23 @@ function encodeStringified(v, encode) { | |||
| 182 | 204 | return ''; | |
| 183 | 205 | } | |
| 184 | 206 | ||
| 185 | - | ||
| 207 | + /** | ||
| 208 | + * @param {string | number | boolean | null} v | ||
| 209 | + * @param {(v: string) => string} encode | ||
| 210 | + * @returns {string} | ||
| 211 | + */ | ||
| 186 | 212 | function encodeStringifiedCustom(v, encode) { | |
| 187 | 213 | return encode(stringifyPrimitive(v)); | |
| 188 | 214 | } | |
| 189 | 215 | ||
| 190 | - | ||
| 216 | + /** | ||
| 217 | + * @param {Record<string, string | number | boolean | ||
| 218 | + * | ReadonlyArray<string | number | boolean> | null>} obj | ||
| 219 | + * @param {string} [sep] | ||
| 220 | + * @param {string} [eq] | ||
| 221 | + * @param {{ encodeURIComponent?: (v: string) => string }} [options] | ||
| 222 | + * @returns {string} | ||
| 223 | + */ | ||
| 191 | 224 | function stringify(obj, sep, eq, options) { | |
| 192 | 225 | sep = sep || '&'; | |
| 193 | 226 | eq = eq || '='; | |
@@ -232,6 +265,10 @@ function stringify(obj, sep, eq, options) { | |||
| 232 | 265 | return ''; | |
| 233 | 266 | } | |
| 234 | 267 | ||
| 268 | + /** | ||
| 269 | + * @param {string} str | ||
| 270 | + * @returns {number[]} | ||
| 271 | + */ | ||
| 235 | 272 | function charCodes(str) { | |
| 236 | 273 | if (str.length === 0) return []; | |
| 237 | 274 | if (str.length === 1) return [str.charCodeAt(0)]; | |
@@ -263,7 +300,17 @@ function addKeyVal(obj, key, value, keyEncoded, valEncoded, decode) { | |||
| 263 | 300 | } | |
| 264 | 301 | } | |
| 265 | 302 | ||
| 266 | - // Parse a key/val string. | ||
| 303 | + /** | ||
| 304 | + * Parse a key/val string. | ||
| 305 | + * @param {string} qs | ||
| 306 | + * @param {string} sep | ||
| 307 | + * @param {string} eq | ||
| 308 | + * @param {{ | ||
| 309 | + * maxKeys?: number; | ||
| 310 | + * decodeURIComponent?(v: string): string; | ||
| 311 | + * }} [options] | ||
| 312 | + * @returns {Record<string, string | string[]>} | ||
| 313 | + */ | ||
| 267 | 314 | function parse(qs, sep, eq, options) { | |
| 268 | 315 | const obj = ObjectCreate(null); | |
| 269 | 316 | ||
@@ -417,9 +464,14 @@ function parse(qs, sep, eq, options) { | |||
| 417 | 464 | } | |
| 418 | 465 | ||
| 419 | 466 | ||
| 420 | - // v8 does not optimize functions with try-catch blocks, so we isolate them here | ||
| 421 | - // to minimize the damage (Note: no longer true as of V8 5.4 -- but still will | ||
| 422 | - // not be inlined). | ||
| 467 | + /** | ||
| 468 | + * V8 does not optimize functions with try-catch blocks, so we isolate them here | ||
| 469 | + * to minimize the damage (Note: no longer true as of V8 5.4 -- but still will | ||
| 470 | + * not be inlined). | ||
| 471 | + * @param {string} s | ||
| 472 | + * @param {(v: string) => string} decoder | ||
| 473 | + * @returns {string} | ||
| 474 | + */ | ||
| 423 | 475 | function decodeStr(s, decoder) { | |
| 424 | 476 | try { | |
| 425 | 477 | return decoder(s); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments