Thanks to visit codestin.com
Credit goes to github.com

Skip to content

motss/tyqs

Repository files navigation

tyqs

Tiny and type-safe querystring library for the web


Buy me a coffee Follow me

npm-latest MIT License

Downloads Total downloads

Dependencies ci publish codecov

Code of Conduct

Querystring decoder and encoder using URLSearchParams.

Table of contents

Pre-requisite

Install

# Install via NPM
$ npm i tyqs

Usage

TypeScript or ES Modules

import { parse } from 'tyqs';

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.

stringify(value)

  • value <unknown> Any value of unknown type. It accepts any JavaScript primitives and objects.
  • returns: <string> A string of encoded URL search params from a given input.

This method encodes/ stringifies an input into a string.

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)

About

Tiny and type-safe querystring library for the web

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 2

  •  
  •