0.0.1-rc.1 • Published 1 year ago

tqs2 v0.0.1-rc.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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)