| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,12 @@ const isHexTable = new Int8Array([ | |||
| 36 | 36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ... 256 | |
| 37 | 37 | ]); | |
| 38 | 38 | ||
| 39 | + /** | ||
| 40 | + * @param {string} str | ||
| 41 | + * @param {Int8Array} noEscapeTable | ||
| 42 | + * @param {string[]} hexTable | ||
| 43 | + * @returns {string} | ||
| 44 | + */ | ||
| 39 | 45 | function encodeStr(str, noEscapeTable, hexTable) { | |
| 40 | 46 | const len = str.length; | |
| 41 | 47 | if (len === 0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,12 @@ const unhexTable = new Int8Array([ | |||
| 76 | 76 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 77 | 77 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 255 | |
| 78 | 78 | ]); | |
| 79 | - // A safe fast alternative to decodeURIComponent | ||
| 79 | + /** | ||
| 80 | + * A safe fast alternative to decodeURIComponent | ||
| 81 | + * @param {string} s | ||
| 82 | + * @param {boolean} decodeSpaces | ||
| 83 | + * @returns {string} | ||
| 84 | + */ | ||
| 80 | 85 | function unescapeBuffer(s, decodeSpaces) { | |
| 81 | 86 | const out = Buffer.allocUnsafe(s.length); | |
| 82 | 87 | let index = 0; | |
@@ -119,7 +124,11 @@ function unescapeBuffer(s, decodeSpaces) { | |||
| 119 | 124 | return hasHex ? out.slice(0, outIndex) : out; | |
| 120 | 125 | } | |
| 121 | 126 | ||
| 122 | - | ||
| 127 | + /** | ||
| 128 | + * @param {string} s | ||
| 129 | + * @param {boolean} decodeSpaces | ||
| 130 | + * @returns {string} | ||
| 131 | + */ | ||
| 123 | 132 | function qsUnescape(s, decodeSpaces) { | |
| 124 | 133 | try { | |
| 125 | 134 | return decodeURIComponent(s); | |
@@ -145,8 +154,13 @@ const noEscape = new Int8Array([ | |||
| 145 | 154 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111 | |
| 146 | 155 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, // 112 - 127 | |
| 147 | 156 | ]); | |
| 148 | - // QueryString.escape() replaces encodeURIComponent() | ||
| 149 | - // https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * QueryString.escape() replaces encodeURIComponent() | ||
| 160 | + * @see https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 | ||
| 161 | + * @param {any} str | ||
| 162 | + * @returns {string} | ||
| 163 | + */ | ||
| 150 | 164 | function qsEscape(str) { | |
| 151 | 165 | if (typeof str !== 'string') { | |
| 152 | 166 | if (typeof str === 'object') | |
@@ -158,6 +172,10 @@ function qsEscape(str) { | |||
| 158 | 172 | return encodeStr(str, noEscape, hexTable); | |
| 159 | 173 | } | |
| 160 | 174 | ||
| 175 | + /** | ||
| 176 | + * @param {string | number | bigint | boolean | symbol | undefined | null} v | ||
| 177 | + * @returns {string} | ||
| 178 | + */ | ||
| 161 | 179 | function stringifyPrimitive(v) { | |
| 162 | 180 | if (typeof v === 'string') | |
| 163 | 181 | return v; | |
@@ -170,7 +188,11 @@ function stringifyPrimitive(v) { | |||
| 170 | 188 | return ''; | |
| 171 | 189 | } | |
| 172 | 190 | ||
| 173 | - | ||
| 191 | + /** | ||
| 192 | + * @param {string | number | bigint | boolean} v | ||
| 193 | + * @param {(v: string) => string} encode | ||
| 194 | + * @returns | ||
| 195 | + */ | ||
| 174 | 196 | function encodeStringified(v, encode) { | |
| 175 | 197 | if (typeof v === 'string') | |
| 176 | 198 | return (v.length ? encode(v) : ''); | |
@@ -186,12 +208,23 @@ function encodeStringified(v, encode) { | |||
| 186 | 208 | return ''; | |
| 187 | 209 | } | |
| 188 | 210 | ||
| 189 | - | ||
| 211 | + /** | ||
| 212 | + * @param {string | number | boolean | null} v | ||
| 213 | + * @param {(v: string) => string} encode | ||
| 214 | + * @returns {string} | ||
| 215 | + */ | ||
| 190 | 216 | function encodeStringifiedCustom(v, encode) { | |
| 191 | 217 | return encode(stringifyPrimitive(v)); | |
| 192 | 218 | } | |
| 193 | 219 | ||
| 194 | - | ||
| 220 | + /** | ||
| 221 | + * @param {Record<string, string | number | boolean | ||
| 222 | + * | ReadonlyArray<string | number | boolean> | null>} obj | ||
| 223 | + * @param {string} [sep] | ||
| 224 | + * @param {string} [eq] | ||
| 225 | + * @param {{ encodeURIComponent?: (v: string) => string }} [options] | ||
| 226 | + * @returns {string} | ||
| 227 | + */ | ||
| 195 | 228 | function stringify(obj, sep, eq, options) { | |
| 196 | 229 | sep = sep || '&'; | |
| 197 | 230 | eq = eq || '='; | |
@@ -236,6 +269,10 @@ function stringify(obj, sep, eq, options) { | |||
| 236 | 269 | return ''; | |
| 237 | 270 | } | |
| 238 | 271 | ||
| 272 | + /** | ||
| 273 | + * @param {string} str | ||
| 274 | + * @returns {number[]} | ||
| 275 | + */ | ||
| 239 | 276 | function charCodes(str) { | |
| 240 | 277 | if (str.length === 0) return []; | |
| 241 | 278 | if (str.length === 1) return [StringPrototypeCharCodeAt(str, 0)]; | |
@@ -267,7 +304,17 @@ function addKeyVal(obj, key, value, keyEncoded, valEncoded, decode) { | |||
| 267 | 304 | } | |
| 268 | 305 | } | |
| 269 | 306 | ||
| 270 | - // Parse a key/val string. | ||
| 307 | + /** | ||
| 308 | + * Parse a key/val string. | ||
| 309 | + * @param {string} qs | ||
| 310 | + * @param {string} sep | ||
| 311 | + * @param {string} eq | ||
| 312 | + * @param {{ | ||
| 313 | + * maxKeys?: number; | ||
| 314 | + * decodeURIComponent?(v: string): string; | ||
| 315 | + * }} [options] | ||
| 316 | + * @returns {Record<string, string | string[]>} | ||
| 317 | + */ | ||
| 271 | 318 | function parse(qs, sep, eq, options) { | |
| 272 | 319 | const obj = ObjectCreate(null); | |
| 273 | 320 | ||
@@ -421,9 +468,14 @@ function parse(qs, sep, eq, options) { | |||
| 421 | 468 | } | |
| 422 | 469 | ||
| 423 | 470 | ||
| 424 | - // v8 does not optimize functions with try-catch blocks, so we isolate them here | ||
| 425 | - // to minimize the damage (Note: no longer true as of V8 5.4 -- but still will | ||
| 426 | - // not be inlined). | ||
| 471 | + /** | ||
| 472 | + * V8 does not optimize functions with try-catch blocks, so we isolate them here | ||
| 473 | + * to minimize the damage (Note: no longer true as of V8 5.4 -- but still will | ||
| 474 | + * not be inlined). | ||
| 475 | + * @param {string} s | ||
| 476 | + * @param {(v: string) => string} decoder | ||
| 477 | + * @returns {string} | ||
| 478 | + */ | ||
| 427 | 479 | function decodeStr(s, decoder) { | |
| 428 | 480 | try { | |
| 429 | 481 | return decoder(s); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments