Skip to content

Commit 1c41704

Browse files
committed
Merge branch 'develop'
2 parents 149bfca + aaa2810 commit 1c41704

13 files changed

Lines changed: 368 additions & 166 deletions

.npmignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.*
2-
bower.json
3-
compile.js
2+
rollup.config.js
3+
src
44
test

README.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,78 @@
11
# jquery-param
2+
23
[![Circle CI](https://circleci.com/gh/knowledgecode/jquery-param.svg?style=shield)](https://circleci.com/gh/knowledgecode/jquery-param)
34

45
## Features
6+
57
- Equivalent to jQuery.param (based on jQuery 3.x)
68
- No dependencies
79
- Universal (Isomorphic)
8-
- ES5
10+
- ES Modules Support
911

1012
## Installation
13+
1114
Node.js:
15+
1216
```shell
13-
$ npm install jquery-param --save
14-
```
15-
Bower (DEPRECATED):
16-
```shell
17-
$ bower install jquery-param
17+
npm install jquery-param --save
1818
```
19+
1920
the browser:
21+
2022
```html
21-
<script src="jquery-param.min.js"></script>
23+
<script src="/path/to/jquery-param.min.js"></script>
2224
```
2325

2426
## Usage
25-
Node.js:
27+
28+
CommonJS:
29+
2630
```javascript
2731
const param = require('jquery-param');
2832

29-
let obj = { key1: 'value1', key2: [10, 20, 30] };
30-
let str = param(obj);
31-
// => "key1=value1&key2[]=10&key2[]=20&key2[]=30"
33+
const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
34+
const str = param(obj);
35+
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
3236
```
33-
AMD:
37+
38+
TypeScript:
39+
3440
```javascript
35-
require(['jquery-param'], function (param) {
36-
var obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
37-
var str = param(obj);
38-
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
39-
});
41+
import param from 'jquery-param';
42+
43+
const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
44+
const str = param(obj);
45+
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
4046
```
41-
directly:
47+
48+
*You will need to add `"esModuleInterop": true` to the `"compilerOptions"` directive in `tsconfig.json`.*
49+
50+
ES Modules:
51+
52+
```html
53+
<script type="module">
54+
import { param } from './esm/jquery-param.es.js';
55+
56+
const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
57+
const str = param(obj);
58+
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
59+
</script>
60+
```
61+
62+
Older browser:
63+
4264
```javascript
65+
<script>
4366
var obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
4467
var str = window.param(obj); // global object
4568
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
69+
</script>
4670
```
4771

4872
## Browser Support
73+
4974
Chrome, Firefox, Safari, Edge, and IE9+.
5075

5176
## License
77+
5278
MIT

bower.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

compile.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

esm/jquery-param.es.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @preserve jquery-param (c) KNOWLEDGECODE | MIT
3+
*/
4+
5+
/**
6+
* serialize any object
7+
* @param {Object} a - any object to serialize
8+
* @returns {string} a serialized string
9+
*/
10+
var param = function (a) {
11+
var s = [];
12+
var add = function (k, v) {
13+
v = typeof v === 'function' ? v() : v;
14+
v = v === null ? '' : v === undefined ? '' : v;
15+
s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v);
16+
};
17+
var buildParams = function (prefix, obj) {
18+
var i, len, key;
19+
20+
if (prefix) {
21+
if (Array.isArray(obj)) {
22+
for (i = 0, len = obj.length; i < len; i++) {
23+
buildParams(
24+
prefix + '[' + (typeof obj[i] === 'object' && obj[i] ? i : '') + ']',
25+
obj[i]
26+
);
27+
}
28+
} else if (String(obj) === '[object Object]') {
29+
for (key in obj) {
30+
buildParams(prefix + '[' + key + ']', obj[key]);
31+
}
32+
} else {
33+
add(prefix, obj);
34+
}
35+
} else if (Array.isArray(obj)) {
36+
for (i = 0, len = obj.length; i < len; i++) {
37+
add(obj[i].name, obj[i].value);
38+
}
39+
} else {
40+
for (key in obj) {
41+
buildParams(key, obj[key]);
42+
}
43+
}
44+
return s;
45+
};
46+
47+
return buildParams('', a).join('&');
48+
};
49+
50+
export { param };

esm/jquery-param.es.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery-param.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
/**
2-
* @preserve jquery-param (c) 2015 KNOWLEDGECODE | MIT
3-
*/
4-
(function (global) {
5-
'use strict';
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3+
typeof define === 'function' && define.amd ? define(factory) :
4+
(global = global || self, global.param = factory());
5+
}(this, (function () { 'use strict';
66

7+
/**
8+
* @preserve jquery-param (c) KNOWLEDGECODE | MIT
9+
*/
10+
11+
/**
12+
* serialize any object
13+
* @param {Object} a - any object to serialize
14+
* @returns {string} a serialized string
15+
*/
716
var param = function (a) {
817
var s = [];
918
var add = function (k, v) {
@@ -44,14 +53,6 @@
4453
return buildParams('', a).join('&');
4554
};
4655

47-
if (typeof module === 'object' && typeof module.exports === 'object') {
48-
module.exports = param;
49-
} else if (typeof define === 'function' && define.amd) {
50-
define([], function () {
51-
return param;
52-
});
53-
} else {
54-
global.param = param;
55-
}
56+
return param;
5657

57-
}(this));
58+
})));

jquery-param.min.js

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)