Skip to content

Commit

Permalink
+ chineseName, #50, #51,
Browse files Browse the repository at this point in the history
  • Loading branch information
nuysoft committed Mar 5, 2015
1 parent dc519b3 commit bb73681
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 98 deletions.
6 changes: 3 additions & 3 deletions dist/mock-min.js

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions dist/mock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! mockjs 24-12-2014 11:39:10 */
/*! mockjs 05-03-2015 14:55:44 */
/*! src/mock-prefix.js */
/*!
Mock - 模拟请求 & 模拟数据
Expand Down Expand Up @@ -607,15 +607,26 @@
first: function() {
var names = [ "James", "John", "Robert", "Michael", "William", "David", "Richard", "Charles", "Joseph", "Thomas", "Christopher", "Daniel", "Paul", "Mark", "Donald", "George", "Kenneth", "Steven", "Edward", "Brian", "Ronald", "Anthony", "Kevin", "Jason", "Matthew", "Gary", "Timothy", "Jose", "Larry", "Jeffrey", "Frank", "Scott", "Eric" ].concat([ "Mary", "Patricia", "Linda", "Barbara", "Elizabeth", "Jennifer", "Maria", "Susan", "Margaret", "Dorothy", "Lisa", "Nancy", "Karen", "Betty", "Helen", "Sandra", "Donna", "Carol", "Ruth", "Sharon", "Michelle", "Laura", "Sarah", "Kimberly", "Deborah", "Jessica", "Shirley", "Cynthia", "Angela", "Melissa", "Brenda", "Amy", "Anna" ]);
return this.pick(names);
return this.capitalize(this.word());
},
last: function() {
var names = [ "Smith", "Johnson", "Williams", "Brown", "Jones", "Miller", "Davis", "Garcia", "Rodriguez", "Wilson", "Martinez", "Anderson", "Taylor", "Thomas", "Hernandez", "Moore", "Martin", "Jackson", "Thompson", "White", "Lopez", "Lee", "Gonzalez", "Harris", "Clark", "Lewis", "Robinson", "Walker", "Perez", "Hall", "Young", "Allen" ];
return this.pick(names);
return this.capitalize(this.word());
},
name: function(middle) {
return this.first() + " " + (middle ? this.first() + " " : "") + this.last();
},
chineseName: function(count) {
var familyNames = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐".split("");
var names = "贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏月莺媛艳瑞凡佳嘉琼勤珍贞莉桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓".split("");
if (typeof count !== "number") {
count = Math.random() > .66 ? 2 : 3;
}
var familyName = this.pick(familyNames);
var name = "";
for (var i = 0; i < count; i++) {
name += this.pick(names);
}
return familyName + name;
}
});
Random.extend({
Expand All @@ -627,7 +638,6 @@
},
email: function(domain) {
return this.character("lower") + "." + this.last().toLowerCase() + "@" + this.last().toLowerCase() + "." + this.tld();
return this.word() + "@" + (domain || this.domain());
},
ip: function() {
return this.natural(0, 255) + "." + this.natural(0, 255) + "." + this.natural(0, 255) + "." + this.natural(0, 255);
Expand Down Expand Up @@ -883,14 +893,6 @@
if (placeholders.length === 1 && ph === result && typeof phed !== typeof result) {
result = phed;
break;
if (Util.isNumeric(phed)) {
result = parseFloat(phed, 10);
break;
}
if (/^(true|false)$/.test(phed)) {
result = phed === "true" ? true : phed === "false" ? false : phed;
break;
}
}
result = result.replace(ph, phed);
}
Expand Down
19 changes: 19 additions & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,24 @@ TODO 统计 -->
Random.name(true)
// => "Helen Carol Martinez"

#### Random.chineseName()

* Random.chineseName()
* Random.chineseName(count)

随机生成一个常见的英文姓名。

**参数的含义和默认值**如下所示:

* 参数 count:可选。数字。指示姓名的字数,默认为 2 到 3 的随机姓名。

**使用示例**如下所示:

Random.chineseName()
// => "林则徐"
Random.chineseName(2)
// => "马云"

### Web

#### Random.url()
Expand Down Expand Up @@ -1358,6 +1376,7 @@ TODO 统计 -->
Random.increment(1000)
// => 1101


---

## 感谢
Expand Down
Loading

0 comments on commit bb73681

Please sign in to comment.