aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/History.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-03-10 16:13:04 -0400
committerbobzel <zzzman@gmail.com>2025-03-10 16:13:04 -0400
commitb7989dded8bb001876de6cbca59bf77935f0daf7 (patch)
tree0dba0665674db7bb84770833df0a4100d0520701 /src/client/util/History.ts
parent4979415d4604d280e81a162bf9a9d39c731d3738 (diff)
parent5bf944035c0ba94ad15245416f51ca0329a51bde (diff)
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/client/util/History.ts')
-rw-r--r--src/client/util/History.ts28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/client/util/History.ts b/src/client/util/History.ts
index 0d0c056a4..9728e3177 100644
--- a/src/client/util/History.ts
+++ b/src/client/util/History.ts
@@ -1,10 +1,6 @@
/* eslint-disable no-use-before-define */
/* eslint-disable no-empty */
-/* eslint-disable no-continue */
-/* eslint-disable guard-for-in */
-/* eslint-disable no-restricted-syntax */
/* eslint-disable no-param-reassign */
-import * as qs from 'query-string';
import { Doc } from '../../fields/Doc';
import { OmitKeys, ClientUtils } from '../../ClientUtils';
import { DocServer } from '../DocServer';
@@ -82,7 +78,7 @@ export namespace HistoryUtil {
// }
// }
- const parsers: { [type: string]: (pathname: string[], opts: qs.ParsedQuery) => ParsedUrl | undefined } = {};
+ const parsers: { [type: string]: (pathname: string[], opts: URLSearchParams) => ParsedUrl | undefined } = {};
const stringifiers: { [type: string]: (state: ParsedUrl) => string } = {};
type ParserValue = true | 'none' | 'json' | ((value: string) => string | null | (string | null)[]);
@@ -91,8 +87,8 @@ export namespace HistoryUtil {
[key: string]: ParserValue;
};
- function addParser(type: string, requiredFields: Parser, optionalFields: Parser, customParser?: (pathname: string[], opts: qs.ParsedQuery, current: ParsedUrl) => ParsedUrl | null | undefined) {
- function parse(parser: ParserValue, value: string | (string | null)[] | null | undefined) {
+ function addParser(type: string, requiredFields: Parser, optionalFields: Parser, customParser?: (pathname: string[], opts: URLSearchParams, current: ParsedUrl) => ParsedUrl | null | undefined) {
+ function parseValue(parser: ParserValue, value: string | (string | null)[] | null | undefined) {
if (value === undefined || value === null) {
return value;
}
@@ -108,21 +104,21 @@ export namespace HistoryUtil {
parsers[type] = (pathname, opts) => {
const current: DocUrl & { [key: string]: null | (string | null)[] | string } = { type: 'doc', docId: '' };
for (const required in requiredFields) {
- if (!(required in opts)) {
+ if (!opts.has(required)) {
return undefined;
}
const parser = requiredFields[required];
- const value = parse(parser, opts[required]);
+ const value = parseValue(parser, opts.get(required));
if (value !== null && value !== undefined) {
current[required] = value;
}
}
for (const opt in optionalFields) {
- if (!(opt in opts)) {
+ if (!opts.has(opt)) {
continue;
}
const parser = optionalFields[opt];
- const value = parse(parser, opts[opt]);
+ const value = parseValue(parser, opts.get(opt));
if (value !== undefined) {
current[opt] = value;
}
@@ -148,12 +144,12 @@ export namespace HistoryUtil {
path = customStringifier(state, path);
}
const queryObj = OmitKeys(state, keys).extract;
- const query: { [key: string]: string | null } = {};
+ const query = new URLSearchParams();
Object.keys(queryObj).forEach(key => {
- query[key] = queryObj[key] === null ? null : JSON.stringify(queryObj[key]);
+ query.set(key, queryObj[key] === null ? '' : JSON.stringify(queryObj[key]));
});
- const queryString = qs.stringify(query);
- return path + (queryString ? `?${queryString}` : '');
+ const qstr = query.toString();
+ return path + (qstr ? `?${qstr}` : '');
};
}
@@ -170,7 +166,7 @@ export namespace HistoryUtil {
export function parseUrl(location: Location | URL): ParsedUrl | undefined {
const pathname = location.pathname.substring(1);
const { search } = location;
- const opts = search.length ? qs.parse(search, { sort: false }) : {};
+ const opts = new URLSearchParams(search);
const pathnameSplit = pathname.split('/');
const type = pathnameSplit[0];