npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

x-query-string

v2.1.0

Published

A query string encoder and decoder. Can be used to encode arrays and objects.

Downloads

224

Readme

querystring.js

npm version Build Status install size npm downloads

A query string encoder and decoder. It works like the $.param(...) function of jQuery and has the ability to decode the query string. Can be used in Node.js and browser side.

Features:

  • Encode & Decode array (nested)
  • Encode & Decode object (nested)

API:

Install

If you are using npm, just install x-query-string as a dependency.

npm i x-query-string

Otherwise, you can import the bundle file with script tag directly.

<script scr="path/to/querystring.min.js"></script>

The bundle file also can be used as an AMD module, which means it can be loaded by require.js.

Example

var QS = require('x-query-string');

// a=1&b=2
QS.encode({ a: 1, b: 2 });

// a%5B%5D=1&a%5B%5D=2&a%5B%5D=3 (a[]=1&a[]=2&a[]=3)
QS.encode({ a: [1, 2, 3] });

// a%5Bb%5D%5Bc%5D=3 (a[b][c]=3)
QS.encode({ a: { b: { c: 3 } } });

For npm users, if you just want to include only the encode or decode function, you can do this as the following example.

// include encode only
var encode = require('x-query-string/encode');

Or

// include decode only
var decode = require('x-query-string/decode');

This is helpful when you want to reduce the bundle size of your application when you just use encode or decode.

API

QS.encode(object, [keepArrayIndex])

  • object {Object} The data to be encoded to query string
  • boolean {keepArrayIndex} Whether to always keep array index in the query string. If the array to be encoded just has one dimension, the index can be omitted. The default value is false.
  • Returns: {string} Returns the URI component encoded query string

Encode the data to query string.

var QS = require('x-query-string');

// a%5B%5D=1&a%5B%5D=2 (a[]=1&a[]=2)
QS.encode({ a: [1, 2] });

// a%5B0%5D=1&a%5B1%5D=2 (a[0]=1&a[1]=2)
QS.encode({ a: [1, 2] }, true);

QS.decode(string)

  • string {string} The query string to be decoded
  • Returns {Object} Returns the decoded data

Decode the query string to a data object. The values in the result data object is string or null. This method will NOT try to parse number or boolean values.

var QS = require('x-query-string');

QS.decode('a[]=1&a[]=2&b=false&c[d]=1&e=&f');
// or (The query string below is url-encoded)
QS.decode('a%5B%5D=1&a%5B%5D=2&b=false&c%5Bd%5D=1&e=&f');

result:

{
    "a": [
        "1",
        "2"
    ],
    "b": "false",
    "c": {
        "d": "1"
    },
    "e": "",
    "f": null
}

License

MIT