Back to Type Challenges

README

questions/00151-extreme-query-string-parser/README.md

latest1.7 KB
Original Source
<!--info-header-start--><h1>Query String Parser </h1><blockquote><p>by Pig Fang <a href="https://github.com/g-plane" target="_blank">@g-plane</a></p></blockquote><p><a href="https://tsch.js.org/151/play" target="_blank"></a> </p><!--info-header-end-->

You're required to implement a type-level parser to parse URL query string into a object literal type.

Some detailed requirements:

  • Value of a key in query string can be ignored but still be parsed to true. For example, 'key' is without value, so the parser result is { key: true }.
  • Duplicated keys must be merged into one. If there are different values with the same key, values must be merged into a tuple type.
  • When a key has only one value, that value can't be wrapped into a tuple type.
  • If values with the same key appear more than once, it must be treated as once. For example, key=value&key=value must be treated as key=value only.
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/151/answer" target="_blank"></a> <a href="https://tsch.js.org/151/solutions" target="_blank"></a> <!--info-footer-end-->