1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00

docs(std/node/querystring): add missing JSDoc (#8242)

This commit is contained in:
ayntee 2020-11-04 21:03:59 +04:00 committed by GitHub
parent f12b0dfcea
commit dc232d8489
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,14 +1,24 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
interface ParseOptions {
/** The function to use when decoding percent-encoded characters in the query string. */
decodeURIComponent?: (string: string) => string;
/** Specifies the maximum number of keys to parse. */
maxKeys?: number;
}
export const hexTable = new Array(256);
for (let i = 0; i < 256; ++i) {
hexTable[i] = "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase();
}
/**
* Parses a URL query string into a collection of key and value pairs.
* @param str The URL query string to parse
* @param sep The substring used to delimit key and value pairs in the query string. Default: '&'.
* @param eq The substring used to delimit keys and values in the query string. Default: '='.
* @param options The parse options
*/
export function parse(
str: string,
sep = "&",
@ -44,6 +54,7 @@ export function parse(
}
interface StringifyOptions {
/** The function to use when converting URL-unsafe characters to percent-encoding in the query string. */
encodeURIComponent?: (string: string) => string;
}
@ -106,6 +117,13 @@ export function encodeStr(
return out;
}
/**
* Produces a URL query string from a given obj by iterating through the object's "own properties".
* @param obj The object to serialize into a URL query string.
* @param sep The substring used to delimit key and value pairs in the query string. Default: '&'.
* @param eq The substring used to delimit keys and values in the query string. Default: '='.
* @param options The stringify options
*/
export function stringify(
// deno-lint-ignore no-explicit-any
obj: Record<string, any>,
@ -130,7 +148,9 @@ export function stringify(
return final.join(sep);
}
/** Alias of querystring.parse() */
export const decode = parse;
/** Alias of querystring.stringify() */
export const encode = stringify;
export const unescape = decodeURIComponent;
export const escape = encodeURIComponent;