/\?(.*)/
&
и потом каждую пару разбить на ключ и значение по знаку =
.const url = new URL('https://mydomen.ru/category/search?area=32&city=31');
console.log('host', url.host);
console.log('search', url.search);
const city = url.searchParams.get('city');
console.log('city', city);
type Char = "A" | "B" | "C" | "D";
type ConcatMap<T> = T extends unknown
? {} extends T[keyof T]
? `${string & keyof T}`
: `${string & keyof T}${ConcatMap<T[keyof T]>}`
: never;
type MapChars<C extends Char> = {
[K in C]: MapChars<Exclude<C, K>>
};
type Split<S extends string> = S extends `${infer H}${infer Tail}`
? [H, ...Split<Tail>]
: [];
type T1 = Split<T2>;
type T2 = ConcatMap<MapChars<Char>>;
type ValueOf<T> = T[keyof T];
const enum BlockType {
Paragpraph = 'PARAGRAPH',
Image = 'IMAGE',
List = 'LIST',
}
interface BodyTypes {
[BlockType.Paragpraph]: string;
[BlockType.Image]: File;
[BlockType.List]: string[];
}
interface IBlock<T extends BlockType> {
type: T;
body: BodyTypes[T];
}
type TBlock = ValueOf<{ [P in BlockType]: IBlock<P> }>;
// type TBlock = IBlock<BlockType.Paragpraph> | IBlock<BlockType.Image> | IBlock<BlockType.List>;
function x(b: TBlock) {
if (b.type === BlockType.Paragpraph) {
// b.body is string
} else if (b.type === BlockType.Image) {
// b.body is File
}
}
type Split<S extends string, D extends string = ''> = S extends ''
? []
: S extends `${infer H0}${D}${infer H1}${D}${infer H2}${D}${infer H3}${D}${infer H4}${D}${infer H5}${D}${infer Tail}`
? [H0, H1, H2, H3, H4, H5, ...Split<Tail, D>]
: S extends `${infer H0}${D}${infer H1}${D}${infer H2}${D}${infer H3}${D}${infer Tail}`
? [H0, H1, H2, H3, ...Split<Tail, D>]
: S extends `${infer H0}${D}${infer Tail}`
? [H0, ...Split<Tail, D>]
: never;
let a1 = {
channelID: {
RegExp: ["\\d+", true],
description: "d1"
},
content: {
RegExp: [".+", true],
description: "d2"
}
};
type T1 = {[K in keyof typeof a1]: string}
type Args = {
[key: string]: {
RegExp: [string, boolean],
description: string
}
}
function createArgs<T extends Args>(args: T): T {
return args;
}
type TStringKeys<T extends Args> = {[K in keyof T]: string};
let a1 = createArgs({
channelID: {
RegExp: ["\\d+", true],
description: "d1"
},
content: {
RegExp: [".+", true],
description: "d2"
}
});
type T1 = TStringKeys<typeof a1>
К сожалению на текущий момент(ts4.2.3) избавиться от функции-обёртки не получится.