Skip to content

Instantly share code, notes, and snippets.

View chjlsch's full-sized avatar

Christoph Schneider chjlsch

  • Switzerland
  • 21:47 (UTC +02:00)
View GitHub Profile
@chjlsch
chjlsch / decode.ts
Created January 6, 2022 21:35
recursively encode and decode querystrings (encode = object to querystring, decode = querystring to object)
export function decode(querystring: string): object {
function parseValue(value: string): any {
if (value === 'TRUE') return true;
if (value === 'FALSE') return false;
return isNaN(Number(value)) ? value : Number(value);
}
function dec(list: any[], isArray = false): object {
let obj: any = isArray ? [] : {};