Small utility for serialising JS objects to query strings for use in URLs

Matt Coles 3f05be7987 Merge branch 'master' of github.com:Alpha-Atom/js-query-string пре 9 година
lib 5ebb3af60c Add unit tests and fix bugs пре 9 година
spec 5ebb3af60c Add unit tests and fix bugs пре 9 година
src 5ebb3af60c Add unit tests and fix bugs пре 9 година
.babelrc 3dda3d2e7b Add functionality пре 9 година
.gitignore d0278ebf7a Last .gitignore maybe [ci skip] пре 9 година
.jshintrc 3dda3d2e7b Add functionality пре 9 година
.travis.yml 5ebb3af60c Add unit tests and fix bugs пре 9 година
LICENSE 6cd6cbf9d4 Create LICENSE пре 9 година
README.md ff9d700647 Update README.md пре 9 година
jasmine-runner.js 5ebb3af60c Add unit tests and fix bugs пре 9 година
npm-debug.log 2a48a086dd Add keywords to package [ci skip] пре 9 година
package.json bc50096528 1.0.2 пре 9 година

README.md

js-query-string

Travis branch Coverage Status GitHub issues [David]() [David]() npm GitHub license npm

Simple Javascript module, with no dependencies, to serialise native JS objects to be used in URL parameters. Objects and arrays are seralised as JSON strings to allow for easy representation of nested objects.

Can be installed very simply with:

npm install js-query-string

Example usage:

var jsq = require('js-query-string');

var qs_object = {
    str: "mystr",
    second_str: "myotherstr"
};

var qs_object2 = {
    obj1: {
      a: 1,
      b: "string"
    },
    obj2: {
      c: true,
      b: [1,2]
    }
};

console.log(jsq.convert(qs_object)); // ?str=mystr&second_str=myotherstr
console.log(jsq.convert(qs_object2)); // ?obj1=%7B%22a%22%3A1%2C%22b%22%3A%22string%22%7D&obj2=%7B%22c%22%3Atrue%2C%22b%22%3A%5B1%2C2%5D%7D

Parameters are also encoded for URLs. The following datatypes are supported: RegExp, Object, Array, Number, String, Boolean.