Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #264

Open
wants to merge 25 commits into
base: refactoring
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ build
*.TODO
PLAN.md
xhr.js
bak
MockHttpRequest.js
coverage
10 changes: 4 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ module.exports = function(grunt) {
jshint: {
files: ['Gruntfile.js', 'package.json', 'src/**/*.js', 'test/**/*.js',
'!src/xhr.js', '!src/MockHttpRequest.js',
'!**/*-prefix.js', '!**/*-suffix.js'
'!**/*-prefix.js', '!**/*-suffix.js',
'!**/node_modules/**/*.js', '!**/bower_components/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
qunit: {
files: [
'test/**/*.html',
'!test/mock4xtpl.html',
'!test/**/noop.*',
'!test/xhr.html'
'test/mock.html'
]
},
nodeunit: {
Expand Down Expand Up @@ -124,7 +122,7 @@ module.exports = function(grunt) {
},
release: {
options: {
sourceMap: 'dist/mock-min.map'
sourceMap: './mock-min.map'
},
files: [{
expand: true,
Expand Down
11 changes: 7 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"name": "Mock.js",
"version": "0.0.0",
"homepage": "https://github.com/nuysoft/MockService",
"name": "mockjs",
"title": "Mock.js",
"version": "0.1.10",
"homepage": "http://mockjs.com/",
"authors": [
"nuysoft <nuysoft@gmail.com>"
],
"main": [
"dist/mock.js"
],
"license": "MIT",
"ignore": [
"**/.*",
Expand All @@ -18,7 +22,6 @@
"bootstrap": "",
"codemirror": "~3.20.0",
"highlightjs": "~8.0.0",
"kissy": "~1.4.3",
"seajs": "*",
"js-beautify": "~1.5.1"
}
Expand Down
7 changes: 4 additions & 3 deletions dist/mock-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock-min.map

Large diffs are not rendered by default.

43 changes: 26 additions & 17 deletions dist/mock.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*! mockjs 23-06-2014 15:57:37 */
/*! mockjs 14-12-2015 16:19:19 */
/*! src/mock-prefix.js */
/*!
Mock - 模拟请求 & 模拟数据
https://github.com/nuysoft/Mock
墨智 mozhi.gyy@taobao.com nuysoft@gmail.com
墨智 nuysoft@gmail.com
*/
(function(undefined) {
var Mock = {
version: "0.1.5",
version: "0.1.11",
_mocked: {}
};
/*! src/util.js */
Expand Down Expand Up @@ -607,15 +607,30 @@
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 surnames = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐".split("");
var forenames = "贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏月莺媛艳瑞凡佳嘉琼勤珍贞莉桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓".split("");
if (typeof count !== "number") {
count = Math.random() > .66 ? 2 : 3;
}
var surname = this.pick(surnames);
var forename = "";
count = count - 1;
for (var i = 0; i < count; i++) {
forename += this.pick(forenames);
}
return surname + forename;
},
cname: function(count) {
return this.chineseName(count);
}
});
Random.extend({
Expand All @@ -627,7 +642,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 +897,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 Expand Up @@ -1010,7 +1016,7 @@
Zepto.ajax = function(options) {
var item = find(options);
if (item) {
var data = Mock.mock(item.template);
var data = convert(item, options);
if (options.success) options.success(data, xhr, options);
if (options.complete) options.complete(xhr.status, xhr, options);
return xhr;
Expand Down Expand Up @@ -1054,7 +1060,10 @@
if (typeof module === "object" && module.exports) {
module.exports = Mock;
} else if (typeof define === "function" && define.amd) {
define(function() {
define("mock", [], function() {
return Mock;
});
define("mockjs", [], function() {
return Mock;
});
} else if (typeof define === "function" && define.cmd) {
Expand All @@ -1065,7 +1074,7 @@
this.Mock = Mock;
this.Random = Random;
if (typeof KISSY != "undefined") {
Util.each([ "mock", "components/mock/", "mock/dist/mock", "gallery/Mock/0.1.1/", "gallery/Mock/0.1.2/", "gallery/Mock/0.1.3/" ], function register(name) {
Util.each([ "mock", "components/mock/", "mock/dist/mock", "gallery/Mock/0.1.9/" ], function register(name) {
KISSY.add(name, function(S) {
Mock.mockjax(S);
return Mock;
Expand Down
8 changes: 4 additions & 4 deletions doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ Mock.js 是一款<!-- 有用且好用的 -->模拟数据生成器,旨在帮

<p>
<a href="./dist/mock.js" class="btn btn-success w250">
Development Version (0.1.5)
</a> - <i>71kB, Uncompressed</i>
Development Version (0.1.10)
</a> - <i>73kB, Uncompressed</i>
</p>
<p>
<a href="./dist/mock-min.js" class="btn btn-primary w250">
Production Version (0.1.5)
</a> - <i>31kB, Minified</i>
Production Version (0.1.10)
</a> - <i>32kB, Minified</i>
</p>
<p>
<a href="https://github.com/nuysoft/Mock" class="btn btn-default w250">
Expand Down
29 changes: 25 additions & 4 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ Mock.js 是一款<!-- 有用且好用的 -->模拟数据生成器,旨在帮

<p>
<a href="./dist/mock.js" class="btn btn-success w250">
Development Version (0.1.5)
</a> - <i>71kB, Uncompressed</i>
Development Version (0.1.10)
</a> - <i>73kB, Uncompressed</i>
</p>
<p>
<a href="./dist/mock-min.js" class="btn btn-primary w250">
Production Version (0.1.5)
</a> - <i>31kB, Minified</i>
Production Version (0.1.10)
</a> - <i>32kB, Minified</i>
</p>
<p>
<a href="https://github.com/nuysoft/Mock" class="btn btn-default w250">
Expand Down Expand Up @@ -1234,6 +1234,26 @@ TODO 统计 -->
Random.name(true)
// => "Helen Carol Martinez"

#### Random.chineseName()

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

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

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

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

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

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

> `Random.chineseName()` 可以简写为 `Random.cname()`。从 Mock 0.2 开始,将只保留 `Random.cname()`。

### Web

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


---

## 感谢
Expand Down
2 changes: 1 addition & 1 deletion doc/lanlan.html
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ <h1 id="-span-class-label-label-success-mr10-mb10-span-span-class-label-label-su
</style></p>
<p><link rel="stylesheet" href="../bower_components/highlightjs/styles/rainbow.css"></p>
<script src="../bower_components/highlightjs/highlight.pack.js"></script>
<script src="../bower_components/jquery/jquery.js"></script>
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../dist/mock.js"></script>
<script>hljs.initHighlightingOnLoad();</script></section>
<section class="slide"><div class="author">
Expand Down
2 changes: 1 addition & 1 deletion doc/lanlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,6 @@ th {
</style>
<link rel="stylesheet" href="../bower_components/highlightjs/styles/rainbow.css">
<script src="../bower_components/highlightjs/highlight.pack.js"></script>
<script src="../bower_components/jquery/jquery.js"></script>
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../dist/mock.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
22 changes: 21 additions & 1 deletion doc/random.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,26 @@ TODO 统计 -->
Random.name(true)
// => "Helen Carol Martinez"

#### Random.chineseName()

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

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

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

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

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

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

> `Random.chineseName()` 可以简写为 `Random.cname()`。从 Mock 0.2 开始,将只保留 `Random.cname()`。

### Web

#### Random.url()
Expand Down Expand Up @@ -852,4 +872,4 @@ TODO 统计 -->
Random.increment(100)
// => 101
Random.increment(1000)
// => 1101
// => 1101
2 changes: 1 addition & 1 deletion doc/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<body>
<div id="sidebar" class="interface"></div>

<script src="./bower_components/jquery/jquery.js"></script>
<script src="./bower_components/jquery/dist/jquery.js"></script>
<script src="./dist/mock.js"></script>


Expand Down
2 changes: 1 addition & 1 deletion editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Mock.js Service</title>

<link href="/bower_components/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
<script src="/bower_components/jquery/jquery.js"></script>
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/dist/mock.js"></script>
<link href="/bower_components/codemirror/lib/codemirror.css" rel="stylesheet">
<link href="/bower_components/codemirror/theme/neat.css" rel="stylesheet">
Expand Down
8 changes: 5 additions & 3 deletions editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@
lineNumbers: true,
lineWrapping: true,
autofocus: true,
mode: 'javascript',
theme: 'neat'
mode: 'application/json',
theme: 'neat',
autoCloseBrackets: true
})
tplEditor.on('change', function(instance) {
render(instance.getValue())
Expand All @@ -156,7 +157,8 @@
lineNumbers: true,
autofocus: false,
mode: 'javascript',
theme: 'neat'
theme: 'neat',
autoCloseBrackets: true
})

// Syntax Demo
Expand Down