Skip to content

Commit e2d3420

Browse files
committed
标准模块学习
1. url 2. querystring
1 parent 7000900 commit e2d3420

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

nodejs/标准模块/queryString.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Created by chenhao on 15/5/24.
3+
*/
4+
5+
var queryString = require('querystring');
6+
console.log(queryString);
7+
8+
var urlQueryJson = {
9+
name: 'abc',
10+
course: ['a', 'b'],
11+
form: ''
12+
};
13+
console.log(queryString.stringify(urlQueryJson)); //转换成url传参
14+
console.log(queryString.stringify(urlQueryJson, '&&')); //用&&串联键值
15+
console.log(queryString.stringify(urlQueryJson, null, '==')); //用==来连接键值
16+
17+
var urlQuery = queryString.stringify(urlQueryJson, null, '==');
18+
console.log(queryString.parse(urlQuery, null, '==')); //传参与stringify对应
19+
20+
console.log(queryString.escape('哈哈')); //编译
21+
console.log(queryString.unescape('%E5%93%88%E5%93%88')); //反编译

nodejs/标准模块/url.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Created by chenhao on 15/5/24.
3+
*/
4+
5+
var url=require('url');
6+
console.log(url);
7+
8+
console.log(url.parse('http://www.imooc.com/video/6710?a=1&b=2#abc')); //打印url的各项信息
9+
console.log(url.parse('http://www.imooc.com/video/6710?a=1&b=2#abc',true)); //参数query转成json对象输出
10+
console.log(url.parse('//www.imooc.com/video/6710?a=1&b=2#abc',true,true)); //在不确定url协议是http还是https还是其他多时候用

0 commit comments

Comments
 (0)