1.2.0 • Published 5 years ago

awesome-querystring v1.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Created out of a frustration with the node default querystring as well as for TypeScript based projects that do not require @types/node

Install

Install with yarn:

$ yarn add awesome-querystring

Usage

Stringify

Create a querystring from a JS object

const { stringify } = require('awesome-querystring');
// or for TypeScript:
// import { stringify } from 'awesome-querystring';

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('awesome-querystring');
// or for TypeScript:
// import { parse } from 'awesome-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

Typedefs

stringify(obj, options) ⇒ string

Kind: global function

ParamTypeDescription
objIAwesomeQuerystringObjectObject to stringify
optionsIStringifyOptionsOptions for the stringify, see IStringifyOptions

parse(qs, options) ⇒ IAwesomeQuerystringObject

Kind: global function

ParamTypeDescription
qsstringQuerystring to parse
optionsIParseOptionsOptions for the parse, see IParseOptions

IStringifyOptions : IStringifyOptions

Kind: global typedef
Properties

NameTypeDescription
separatorstringseparator the querystring should get
equalsstringequals sign the querystring should use
includeQuestionbooleanwhether the querystring should be prefixed with a ?

IParseOptions : IParseOptions

Kind: global typedef
Properties

NameTypeDescription
separatorstringseparator the querystring has
equalsstringequals sign the querystring has

About

Contributing

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

License

Copyright © 2018-2019, Favna. 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 WithQRAddress
Donate with PayPal
1E643TNif2MTh75rugepmXuq35Tck4TnE5
0xF653F666903cd8739030D2721bF01095896F5D6E
LZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6
1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago