Comparing version 1.0.0 to 1.0.1-beta1
@@ -5,3 +5,3 @@ { | ||
"description": "生成随机数据 & 拦截 Ajax 请求", | ||
"version": "1.0.0", | ||
"version": "1.0.1-beta1", | ||
"homepage": "http://mockjs.com/", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
@@ -32,3 +32,3 @@ /* global require, module, window */ | ||
Mock.version = '1.0.0' | ||
Mock.version = '1.0.1-beta1' | ||
@@ -35,0 +35,0 @@ // 避免循环依赖 |
/* | ||
## Helpers | ||
*/ | ||
var Util = require('../util') | ||
module.exports = { | ||
@@ -19,13 +22,33 @@ // 把字符串的第一个字母转换为大写。 | ||
pick: function pick(arr, min, max) { | ||
arr = arr || [] | ||
switch (arguments.length) { | ||
case 1: | ||
return arr[this.natural(0, arr.length - 1)] | ||
case 2: | ||
max = min | ||
/* falls through */ | ||
case 3: | ||
return this.shuffle(arr, min, max) | ||
// pick( item1, item2 ... ) | ||
if (!Util.isArray(arr)) { | ||
arr = [].slice.call(arguments) | ||
min = 1 | ||
max = 1 | ||
} else { | ||
// pick( [ item1, item2 ... ] ) | ||
if (min === undefined) min = 1 | ||
// pick( [ item1, item2 ... ], count ) | ||
if (max === undefined) max = min | ||
} | ||
if (min === 1 && max === 1) return arr[this.natural(0, arr.length - 1)] | ||
// pick( [ item1, item2 ... ], min, max ) | ||
return this.shuffle(arr, min, max) | ||
// 通过参数个数判断方法签名,扩展性太差!#90 | ||
// switch (arguments.length) { | ||
// case 1: | ||
// // pick( [ item1, item2 ... ] ) | ||
// return arr[this.natural(0, arr.length - 1)] | ||
// case 2: | ||
// // pick( [ item1, item2 ... ], count ) | ||
// max = min | ||
// /* falls through */ | ||
// case 3: | ||
// // pick( [ item1, item2 ... ], min, max ) | ||
// return this.shuffle(arr, min, max) | ||
// } | ||
}, | ||
@@ -32,0 +55,0 @@ /* |
@@ -426,2 +426,5 @@ /* global require, chai, describe, before, it */ | ||
}) | ||
doit('Random.pick("a", "e", "i", "o", "u")', function(data) { | ||
expect(["a", "e", "i", "o", "u"]).to.include(data) | ||
}) | ||
doit('Random.pick(["a", "e", "i", "o", "u"])', function(data) { | ||
@@ -428,0 +431,0 @@ expect(["a", "e", "i", "o", "u"]).to.include(data) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1848522
18930
1