mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-07 14:57:12 -04:00
18 lines
550 B
TypeScript
18 lines
550 B
TypeScript
export type HashMap = Record<string, string[]>;
|
|
|
|
export function toHashString(obj: HashMap): string {
|
|
const params = new URLSearchParams();
|
|
Object.entries(obj).forEach(([key, stringArr]) => {
|
|
stringArr.forEach((value) => {
|
|
params.append(key, value);
|
|
});
|
|
});
|
|
return `#${params.toString()}`;
|
|
}
|
|
|
|
export function getHashMap(hash: string): HashMap {
|
|
const existingParams = new URLSearchParams(hash.replace('#', ''));
|
|
return Object.fromEntries(
|
|
[...existingParams.keys()].map(key => [key, existingParams.getAll(key)]),
|
|
);
|
|
}
|