jquery-param 1.1.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -19
- package/dist/esm/jquery-param.js +4 -0
- package/dist/esm/jquery-param.mjs +4 -0
- package/dist/umd/jquery-param.js +4 -0
- package/package.json +11 -13
- package/rollup.config.mjs +13 -0
- package/esm/jquery-param.es.js +0 -50
- package/esm/jquery-param.es.min.js +0 -5
- package/jquery-param.js +0 -58
- package/jquery-param.min.js +0 -5
package/README.md
CHANGED
|
@@ -11,47 +11,37 @@
|
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
via npm:
|
|
15
15
|
|
|
16
16
|
```shell
|
|
17
|
-
npm
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
the browser:
|
|
21
|
-
|
|
22
|
-
```html
|
|
23
|
-
<script src="/path/to/jquery-param.min.js"></script>
|
|
17
|
+
npm i jquery-param
|
|
24
18
|
```
|
|
25
19
|
|
|
26
20
|
## Usage
|
|
27
21
|
|
|
28
|
-
CommonJS:
|
|
29
|
-
|
|
30
22
|
```javascript
|
|
31
|
-
|
|
23
|
+
import param from 'jquery-param';
|
|
32
24
|
|
|
33
25
|
const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
|
|
34
26
|
const str = param(obj);
|
|
35
27
|
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
|
|
36
28
|
```
|
|
37
29
|
|
|
38
|
-
|
|
30
|
+
CommonJS:
|
|
39
31
|
|
|
40
32
|
```javascript
|
|
41
|
-
|
|
33
|
+
const param = require('jquery-param');
|
|
42
34
|
|
|
43
35
|
const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
|
|
44
36
|
const str = param(obj);
|
|
45
37
|
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
|
|
46
38
|
```
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
ES Modules:
|
|
40
|
+
ES Modules (Browser):
|
|
51
41
|
|
|
52
42
|
```html
|
|
53
43
|
<script type="module">
|
|
54
|
-
import param from '
|
|
44
|
+
import param from '/path/to/jquery-param.js';
|
|
55
45
|
|
|
56
46
|
const obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
|
|
57
47
|
const str = param(obj);
|
|
@@ -59,12 +49,13 @@ const str = param(obj);
|
|
|
59
49
|
</script>
|
|
60
50
|
```
|
|
61
51
|
|
|
62
|
-
|
|
52
|
+
Traditional (Browser):
|
|
63
53
|
|
|
64
54
|
```html
|
|
55
|
+
<script src="/path/to/jquery-param.js">
|
|
65
56
|
<script>
|
|
66
57
|
var obj = { key1: { value1: [10, 20, 30] }, key2: '?a=b&c=d' };
|
|
67
|
-
var str = window.param(obj);
|
|
58
|
+
var str = window.param(obj);
|
|
68
59
|
// => "key1[value1][]=10&key1[value1][]=20&key1[value1][]=30&key2=?a=b&c=d"
|
|
69
60
|
</script>
|
|
70
61
|
```
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @preserve jquery-param (c) KNOWLEDGECODE | MIT
|
|
3
|
+
*/
|
|
4
|
+
var e=function(e){var n=[],o=function(e,o){o=null==(o="function"==typeof o?o():o)?"":o,n[n.length]=encodeURIComponent(e)+"="+encodeURIComponent(o)},t=function(e,r){var f,i,l;if(e)if(Array.isArray(r))for(f=0,i=r.length;f<i;f++)t(e+"["+("object"==typeof r[f]&&r[f]?f:"")+"]",r[f]);else if("[object Object]"===Object.prototype.toString.call(r))for(l in r)t(e+"["+l+"]",r[l]);else o(e,r);else if(Array.isArray(r))for(f=0,i=r.length;f<i;f++)o(r[f].name,r[f].value);else for(l in r)t(l,r[l]);return n};return t("",e).join("&")};export{e as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @preserve jquery-param (c) KNOWLEDGECODE | MIT
|
|
3
|
+
*/
|
|
4
|
+
var e=function(e){var n=[],o=function(e,o){o=null==(o="function"==typeof o?o():o)?"":o,n[n.length]=encodeURIComponent(e)+"="+encodeURIComponent(o)},t=function(e,r){var f,i,l;if(e)if(Array.isArray(r))for(f=0,i=r.length;f<i;f++)t(e+"["+("object"==typeof r[f]&&r[f]?f:"")+"]",r[f]);else if("[object Object]"===Object.prototype.toString.call(r))for(l in r)t(e+"["+l+"]",r[l]);else o(e,r);else if(Array.isArray(r))for(f=0,i=r.length;f<i;f++)o(r[f].name,r[f].value);else for(l in r)t(l,r[l]);return n};return t("",e).join("&")};export{e as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).param=n()}(this,(function(){"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @preserve jquery-param (c) KNOWLEDGECODE | MIT
|
|
4
|
+
*/return function(e){var n=[],o=function(e,o){o=null==(o="function"==typeof o?o():o)?"":o,n[n.length]=encodeURIComponent(e)+"="+encodeURIComponent(o)},t=function(e,f){var i,r,l;if(e)if(Array.isArray(f))for(i=0,r=f.length;i<r;i++)t(e+"["+("object"==typeof f[i]&&f[i]?i:"")+"]",f[i]);else if("[object Object]"===Object.prototype.toString.call(f))for(l in f)t(e+"["+l+"]",f[l]);else o(e,f);else if(Array.isArray(f))for(i=0,r=f.length;i<r;i++)o(f[i].name,f[i].value);else for(l in f)t(l,f[l]);return n};return t("",e).join("&")}}));
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jquery-param",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "equivalent function to jQuery.param",
|
|
5
|
-
"main": "jquery-param.js",
|
|
6
|
-
"module": "esm/jquery-param.
|
|
5
|
+
"main": "dist/umd/jquery-param.js",
|
|
6
|
+
"module": "dist/esm/jquery-param.mjs",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "rollup
|
|
9
|
-
"test": "
|
|
8
|
+
"build": "rollup -c",
|
|
9
|
+
"test": "npm run build && mocha test/test.mjs"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -27,13 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/knowledgecode/jquery-param",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"jquery": "^3.6.
|
|
33
|
-
"jsdom": "^
|
|
34
|
-
"mocha": "^
|
|
35
|
-
"
|
|
36
|
-
"phantomjs-prebuilt": "^2.1.16",
|
|
37
|
-
"rollup": "^2.50.6"
|
|
30
|
+
"@rollup/plugin-terser": "^0.2.1",
|
|
31
|
+
"chai": "^4.3.7",
|
|
32
|
+
"jquery": "^3.6.3",
|
|
33
|
+
"jsdom": "^20.0.3",
|
|
34
|
+
"mocha": "^10.2.0",
|
|
35
|
+
"rollup": "^3.9.1"
|
|
38
36
|
}
|
|
39
37
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import terser from '@rollup/plugin-terser';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
{
|
|
5
|
+
input: 'src/index.js',
|
|
6
|
+
output: [
|
|
7
|
+
{ file: 'dist/esm/jquery-param.js', format: 'es' },
|
|
8
|
+
{ file: 'dist/esm/jquery-param.mjs', format: 'es' },
|
|
9
|
+
{ file: 'dist/umd/jquery-param.js', format: 'umd', name: 'param' }
|
|
10
|
+
],
|
|
11
|
+
plugins: [terser()]
|
|
12
|
+
}
|
|
13
|
+
];
|
package/esm/jquery-param.es.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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 (Object.prototype.toString.call(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 default param;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
jquery-param (c) KNOWLEDGECODE | MIT
|
|
3
|
-
*/
|
|
4
|
-
export default function(h){function d(c,a){var e;if(c)if(Array.isArray(a)){var b=0;for(e=a.length;b<e;b++)d(c+"["+("object"===typeof a[b]&&a[b]?b:"")+"]",a[b])}else if("[object Object]"===Object.prototype.toString.call(a))for(b in a)d(c+"["+b+"]",a[b]);else g(c,a);else if(Array.isArray(a))for(b=0,e=a.length;b<e;b++)g(a[b].name,a[b].value);else for(b in a)d(b,a[b]);return f}function g(c,a){a="function"===typeof a?a():a;a=null===a?"":void 0===a?"":a;f[f.length]=encodeURIComponent(c)+"="+
|
|
5
|
-
encodeURIComponent(a)}var f=[];return d("",h).join("&")}
|
package/jquery-param.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.param = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
6
|
-
|
|
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
|
-
*/
|
|
16
|
-
var param = function (a) {
|
|
17
|
-
var s = [];
|
|
18
|
-
var add = function (k, v) {
|
|
19
|
-
v = typeof v === 'function' ? v() : v;
|
|
20
|
-
v = v === null ? '' : v === undefined ? '' : v;
|
|
21
|
-
s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v);
|
|
22
|
-
};
|
|
23
|
-
var buildParams = function (prefix, obj) {
|
|
24
|
-
var i, len, key;
|
|
25
|
-
|
|
26
|
-
if (prefix) {
|
|
27
|
-
if (Array.isArray(obj)) {
|
|
28
|
-
for (i = 0, len = obj.length; i < len; i++) {
|
|
29
|
-
buildParams(
|
|
30
|
-
prefix + '[' + (typeof obj[i] === 'object' && obj[i] ? i : '') + ']',
|
|
31
|
-
obj[i]
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
} else if (Object.prototype.toString.call(obj) === '[object Object]') {
|
|
35
|
-
for (key in obj) {
|
|
36
|
-
buildParams(prefix + '[' + key + ']', obj[key]);
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
add(prefix, obj);
|
|
40
|
-
}
|
|
41
|
-
} else if (Array.isArray(obj)) {
|
|
42
|
-
for (i = 0, len = obj.length; i < len; i++) {
|
|
43
|
-
add(obj[i].name, obj[i].value);
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
for (key in obj) {
|
|
47
|
-
buildParams(key, obj[key]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return s;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return buildParams('', a).join('&');
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return param;
|
|
57
|
-
|
|
58
|
-
})));
|
package/jquery-param.min.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
jquery-param (c) KNOWLEDGECODE | MIT
|
|
3
|
-
*/
|
|
4
|
-
'use strict';(function(c,d){"object"===typeof exports&&"undefined"!==typeof module?module.exports=d():"function"===typeof define&&define.amd?define(d):(c="undefined"!==typeof globalThis?globalThis:c||self,c.param=d())})(this,function(){return function(c){var d=[],g=function(e,a){a="function"===typeof a?a():a;a=null===a?"":void 0===a?"":a;d[d.length]=encodeURIComponent(e)+"="+encodeURIComponent(a)},f=function(e,a){var c;if(e)if(Array.isArray(a)){var b=0;for(c=a.length;b<c;b++)f(e+"["+("object"===typeof a[b]&&
|
|
5
|
-
a[b]?b:"")+"]",a[b])}else if("[object Object]"===Object.prototype.toString.call(a))for(b in a)f(e+"["+b+"]",a[b]);else g(e,a);else if(Array.isArray(a))for(b=0,c=a.length;b<c;b++)g(a[b].name,a[b].value);else for(b in a)f(b,a[b]);return d};return f("",c).join("&")}})
|