-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Coles
authored and
Matt Coles
committed
Apr 30, 2016
1 parent
90da33f
commit 37342ae
Showing
1 changed file
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,36 @@ | ||
# js-query-string [![Travis branch](https://img.shields.io/travis/Alpha-Atom/js-query-string/master.svg)](https://travis-ci.org/Alpha-Atom/js-query-string) [![Coverage Status](https://coveralls.io/repos/github/Alpha-Atom/js-query-string/badge.svg?branch=master)](https://coveralls.io/github/Alpha-Atom/js-query-string?branch=master) | ||
|
||
Documentation to follow. | ||
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: | ||
|
||
```javascript | ||
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. |