Skip to content

Commit 5fdbcc0

Browse files
example and umd
1 parent 22a6c81 commit 5fdbcc0

7 files changed

+29
-12
lines changed

index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {stringify} from "./src/json2qs.js";
2+
import {parse} from "./src/qs2json.js";
3+
4+
export {
5+
stringify,
6+
parse
7+
}

lib/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"example": "example"
88
},
99
"scripts": {
10-
"test": "echo \"Error: no test specified\" && exit 1"
10+
"test": "echo \"Error: no test specified\" && exit 1",
11+
"build":"webpack --mode production"
1112
},
1213
"keywords": [],
1314
"author": "",

src/json2qs.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let obj={ a: [ '1', '2' ], b: '2', c: '3',d:123,e:true };
2-
function stringify(obj){
2+
export function stringify(obj){
33
let result="";
44
for(let key in obj){
55
if( typeof obj[key] !='object'){ //非对象值都转化为字符串
@@ -13,4 +13,5 @@ function stringify(obj){
1313
}
1414
return result.slice(0,-1);
1515
}
16-
console.log(stringify(obj));
16+
// console.log(stringify(obj));
17+
// export stringify;

src/package.json

-6
This file was deleted.

src/qs2json.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* querystring to json
33
* "a=1&a=2&b=2&c=3&d=123&e=true" to { a: [ '1', '2' ], b: '2', c: '3', d: '123', e: 'true' }
44
*/
5-
let str="a=1&a=2&b=2&c=3&d=123&e=true"
6-
function parse(str){
5+
// let str="a=1&a=2&b=2&c=3&d=123&e=true"
6+
export function parse(str){
77
let result={};
88
let s1=str.split("&");
99

@@ -19,4 +19,5 @@ function parse(str){
1919
})
2020
return result;
2121
}
22-
console.log(parse(str));
22+
// console.log(parse(str));
23+
// export default parse;

webpack.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var path = require('path');
2+
3+
module.exports = {
4+
entry: './index.js',
5+
output: {
6+
path: path.resolve(__dirname, 'lib'),
7+
filename: 'index.js',
8+
library: 'qs',
9+
globalObject: "this", //需要配置为 "this", 默认为 "window" 兼容window环境和node环境
10+
libraryTarget: 'umd'
11+
}
12+
};

0 commit comments

Comments
 (0)