浏览代码

Add some documentation

Matt Coles 9 年之前
父节点
当前提交
37342aea83
共有 1 个文件被更改,包括 34 次插入1 次删除
  1. 34 1
      README.md

+ 34 - 1
README.md

@@ -1,3 +1,36 @@
1 1
 # 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)
2 2
 
3
-Documentation to follow.
3
+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.
4
+
5
+Can be installed very simply with:
6
+
7
+```
8
+npm install js-query-string
9
+```
10
+
11
+Example usage:
12
+
13
+```javascript
14
+var jsq = require('js-query-string');
15
+
16
+var qs_object = {
17
+    str: "mystr",
18
+    second_str: "myotherstr"
19
+};
20
+
21
+var qs_object2 = {
22
+    obj1: {
23
+      a: 1,
24
+      b: "string"
25
+    },
26
+    obj2: {
27
+      c: true,
28
+      b: [1,2]
29
+    }
30
+};
31
+
32
+console.log(jsq.convert(qs_object)); // ?str=mystr&second_str=myotherstr
33
+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
34
+```
35
+
36
+Parameters are also encoded for URLs. The following datatypes are supported: RegExp, Object, Array, Number, String, Boolean.