tqs2
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-rc.1 • Public • Published

tqs

Tiny and type-safe querystring library for the web


Follow me

Version MIT License

Downloads Total downloads Packagephobia Bundlephobia

ci codecov

Code of Conduct

Querystring decoder and encoder using URLSearchParams.

Table of contents

Pre-requisite

Install

# Install via NPM
$ npm i tqs

Usage

TypeScript or ES Modules

import { parse } from 'tqs';

parse('a=a'); // { a: 'a' }
parse('a=a&a=b'); // { a: ['a', 'b'] }
parse('a=a,b'); // { a: ['a', 'b'] }
parse('a.a=a'); // { a: { a: 'a' } }
parse('a[a]=a'); // { a: { a: 'a' } }
parse('a[a].b=a'); // { a: { a: { b: 'a' } } }
parse('a[a].b=a,b'); // { a: { a: { b: ['a', 'b'] } } }

API Reference

parse(searchParams[, options])

  • searchParams <string | URLSearchParams> URL search parameters.
  • options <?object> Optional parsing options.
    • singles <?Array<string>> A list of keys that need to be decoded as single string value instead of an array of values.
    • smart <?boolean> Defaults to true. The decoder will assume all URL search params to be an array of values. With smart mode enabled, it will not force a single-value search param into an array.
  • returns: <object> An object of decoded URL search params from a given string.

This method decodes/ parses a string value into an object.

Contributing

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

MIT License © Rong Sen Ng (motss)

Package Sidebar

Install

npm i tqs2

Weekly Downloads

1

Version

0.0.1-rc.1

License

MIT

Unpacked Size

8.27 kB

Total Files

3

Last publish

Collaborators

  • motss