awesome-querystring

Awesome and robust querystring


Keywords
querystring, stringify, parse, typescript, awesome, html, url, nodejs, typescript-users
License
MIT
Install
npm install awesome-querystring@1.2.0

Documentation

logo

@favware/querystring

Querystring that is robust in its working yet remains awesome to TypeScript users

LicenseBuild StatusTest Coverage

NPM bundle size (minified)NPM bundle size (minified + gzip)NPM VersionNPM Weekly DownloadsNPM Total Downloads

Follow me on TwitterDonate with PayPalBecome a Patron

Join Discord Server


NodeJS' Querystring, but then with far stronger safety net.

Key Features

  • Useable in the browser through jsDelivr, unpkg and bundle.run
  • Useable in NodeJS through package manager of choice
  • Typesafe
  • Bundled with Rollup for maximum size reduction (only 1kB minified + gzipped!) and ES module support
  • Generated TypeScript declarations
  • Treeshakeable in Webpack

Install

Install with yarn or npm:

yarn add @favware/querystring

# npm install @favware/querystring

Usage

Stringify

Create a querystring from a JS object

const { stringify } = require('@favware/querystring');
// or with ES Modules:
// import { stringify } from '@favware/querystring';
// you can also use a default import for stringify!

console.log(stringify({prop: 'value', prop2: 'value2'}));
//=> '?prop=value&prop2=value2'

// supply options
console.log(stringify({prop: 'value', prop2: 'value2'}, {separator: '&', equals: '=', includeQuestion: true}));
//=> '?prop=value&prop2=value2'

// customize options
console.log(stringify({prop: 'value', prop2: 'value2'}, {separator: '&&', equals: '=', includeQuestion: false}));
//=> 'prop=value&&prop2=value2'

Parse

Create a JS object from a querystring

const { parse } = require('@favware/querystring');
// or with ES Modules:
// import { parse } from '@favware/querystring';

console.log(parse('?prop=value&prop2=value2'));
//=> {prop: 'value', prop2: 'value2'}

// supply options
console.log(parse('?prop=value&prop2=value2', {separator: '&', equals: '='}));
//=> {prop: 'value', prop2: 'value2'}

// customize options
console.log(parse('prop=value&&prop2=value2', {separator: '&&', equals: '='}));
//=> {prop: 'value', prop2: 'value2'}

Documentation

Functions

stringify(obj, [options])string

Stringifies an object

parse(qs, [options])QuerystringObject

Parses a querystring back to an object

stringify(obj, [options]) ⇒ string

Stringifies an object

Kind: global function

Param Type Description
obj QuerystringObject Object to stringify
[options] StringifyOptions Options for the stringify, see IStringifyOptions

parse(qs, [options]) ⇒ QuerystringObject

Parses a querystring back to an object

Kind: global function

Param Type Description
qs string Querystring to parse
[options] ParseOptions Options for the parse, see IParseOptions

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

License

Copyright © 2019, Favware. Released under the MIT License.

Buy me a donut

This project is open source and always will be, even if I don't get donations. That said, I know there are people out there that may still want to donate just to show their appreciation so this is for you guys. Thanks in advance!

I accept donations through PayPal, BitCoin, Ethereum and LiteCoin. You can use the buttons below to donate through your method of choice

Donate With QR Address
Donate with PayPal
1E643TNif2MTh75rugepmXuq35Tck4TnE5
0xF653F666903cd8739030D2721bF01095896F5D6E
LZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6