{"version":3,"file":"_httpQueryParseURLSearchParams.mjs","names":[],"sources":["../../src/internal/_httpQueryParseURLSearchParams.ts"],"sourcesContent":["import { IReadableURLSearchParams } from \"@typia/interface\";\n\n/**\n * Parse a query input into URLSearchParams.\n *\n * A string may be a bare query, a query with a leading `?`, or a URL; a prefix\n * before the first `?` is dropped when it looks like a URL prefix (a scheme, a\n * slash or dot path, or text without `=` or `&`), and a fragment is removed\n * from a URL. An object that already reads like URLSearchParams is returned as\n * it is.\n *\n * @evidence contracts/common.md#principled-implementation A string input is reduced to its query: a leading `?` is dropped, text before a `?` is dropped when it looks like a URL prefix (a scheme, a leading slash or dot path, or text without `=` or `&`), and a fragment is removed for URL inputs; an object that already reads like URLSearchParams is returned as is. The URL-prefix test is a heuristic, so a bare query string whose first key contains no `=` or `&` is read as a prefix.\n * @evidence contracts/common.md#clear-and-simple-design One function and two private prefix predicates.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The heuristic is stated and has a defined boundary instead of a list of known URLs.\n * @evidence contracts/common.md#meaningful-documentation The doc states the accepted inputs and the heuristic.\n */\nexport const _httpQueryParseURLSearchParams = (\n  input: string | IReadableURLSearchParams,\n): IReadableURLSearchParams => {\n  if (typeof input === \"string\") {\n    let url: boolean = false;\n    if (input.startsWith(\"?\")) {\n      input = input.substring(1);\n      url = true;\n    } else {\n      const index: number = input.indexOf(\"?\");\n      if (index !== -1 && isUrlPrefix(input.substring(0, index))) {\n        input = input.substring(index + 1);\n        url = true;\n      } else if (index === -1 && isExplicitUrlPrefix(input)) {\n        input = \"\";\n        url = true;\n      }\n    }\n    if (url) {\n      const fragment: number = input.indexOf(\"#\");\n      if (fragment !== -1) input = input.substring(0, fragment);\n    }\n    return new URLSearchParams(input);\n  }\n  return input;\n};\n\nconst isUrlPrefix = (prefix: string): boolean =>\n  isExplicitUrlPrefix(prefix) || (prefix.length !== 0 && !/[=&]/.test(prefix));\n\nconst isExplicitUrlPrefix = (prefix: string): boolean =>\n  /^[a-z][a-z\\d+.-]*:/i.test(prefix) || /^(?:\\/\\/|\\/|\\.{1,2}\\/)/.test(prefix);\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,kCACX,UAC6B;CAC7B,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,MAAe;EACnB,IAAI,MAAM,WAAW,GAAG,GAAG;GACzB,QAAQ,MAAM,UAAU,CAAC;GACzB,MAAM;EACR,OAAO;GACL,MAAM,QAAgB,MAAM,QAAQ,GAAG;GACvC,IAAI,UAAU,MAAM,YAAY,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG;IAC1D,QAAQ,MAAM,UAAU,QAAQ,CAAC;IACjC,MAAM;GACR,OAAO,IAAI,UAAU,MAAM,oBAAoB,KAAK,GAAG;IACrD,QAAQ;IACR,MAAM;GACR;EACF;EACA,IAAI,KAAK;GACP,MAAM,WAAmB,MAAM,QAAQ,GAAG;GAC1C,IAAI,aAAa,IAAI,QAAQ,MAAM,UAAU,GAAG,QAAQ;EAC1D;EACA,OAAO,IAAI,gBAAgB,KAAK;CAClC;CACA,OAAO;AACT;AAEA,MAAM,eAAe,WACnB,oBAAoB,MAAM,KAAM,OAAO,WAAW,KAAK,CAAC,OAAO,KAAK,MAAM;AAE5E,MAAM,uBAAuB,WAC3B,sBAAsB,KAAK,MAAM,KAAK,yBAAyB,KAAK,MAAM"}