Skip to content

Commit 8303de9

Browse files
committed
ES Mosules support
1 parent daebaf2 commit 8303de9

9 files changed

Lines changed: 164 additions & 53 deletions

File tree

.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

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.

rollup.config.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { terser } from 'rollup-plugin-terser';
2+
3+
export default [
4+
{
5+
input: 'src/index.js',
6+
output: [
7+
{
8+
file: 'jquery-param.js',
9+
format: 'umd',
10+
name: 'param',
11+
esModule: false
12+
},
13+
{
14+
file: 'jquery-param.min.js',
15+
format: 'umd',
16+
name: 'param',
17+
esModule: false,
18+
plugins: [terser()]
19+
}
20+
]
21+
},
22+
{
23+
input: 'src/esm.js',
24+
output: [
25+
{
26+
file: 'esm/jquery-param.es.js',
27+
format: 'es'
28+
},
29+
{
30+
file: 'esm/jquery-param.es.min.js',
31+
format: 'es',
32+
plugins: [terser()]
33+
}
34+
]
35+
}
36+
];

src/esm.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import param from './index.js';
2+
export { param };

src/index.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 default param;

0 commit comments

Comments
 (0)