Skip to content

Commit

Permalink
添加二维码 URL
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Jun 22, 2016
1 parent 775477e commit 8e65b47
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "blear.utils.url",
"version": "1.0.7",
"version": "1.0.8",
"description": "url utils",
"scripts": {
"live": "browser-sync start --config bs-config.js",
Expand Down
39 changes: 39 additions & 0 deletions src/index.js
Expand Up @@ -17,6 +17,30 @@ var reSep = /\//g;
var reColon = /:(\w+\b)/g;
var reStar = /\*/g;
var reIgnoreMatch = /^[.?#]/;
// @see http://www.topscan.com/pingtai/
var QR_CODE_URL = 'http://qr.topscan.com/api.php?';
var qrcodeDefaults = {
// 背景色
bg: 'ffffff',
// 前景色
fg: '000000',
// 渐变
gc: '000000',
// 定位点外框颜色
pt: '000000',
// 定位点内容颜色
ipt: '000000',
// 纠错等级:h/q/m/l
el: 'm',
// 内容尺寸
w: 300,
// 边框尺寸
m: 0,
// logo
logo: '',
// 文本
text: ''
};


/**
Expand Down Expand Up @@ -279,3 +303,18 @@ var buildExports = function (method) {
exports.resolve = buildExports(RESOLVE);
exports.join = buildExports(JOIN);


/**
* 二维码地址
* @param options {Object|String} 配置
* @returns {string}
*/
exports.qrcode = function (options) {
if (typeis.String(options)) {
options = {text: options};
}

options = object.assign({}, qrcodeDefaults, options);
return QR_CODE_URL + querystring.stringify(options);
};

7 changes: 7 additions & 0 deletions test/test.index.js
Expand Up @@ -140,4 +140,11 @@ describe('index.js', function () {
expect(url.join('http://a.b.com/a/b/c', '../?x=1')).toEqual('http://a.b.com/a/b/?x=1');
expect(url.join('http://a.b.com/a/b/c', './d?x=1')).toEqual('http://a.b.com/a/b/c/d?x=1');
});

it('qrcode', function () {
console.log(url.qrcode('1'));
console.log(url.qrcode({
text: '1'
}));
});
});

0 comments on commit 8e65b47

Please sign in to comment.