Skip to content

Commit 321af5c

Browse files
lavyunmocobk
andauthored
release: 0.2.8
* chore: add contrubute guide * chore: add 'dev' script * feat: change image service source * feat: optimize Random.pick function * doc: translate CONTRUBUTING.md * feat: support random.extend * feat: Random.emoji * test: Random.emoji unit test * docs: Random.emoji * chore: ignore some unit test * release: 0.2.8 Co-authored-by: mocobk <[email protected]>
1 parent c0cc237 commit 321af5c

27 files changed

+1270
-618
lines changed

Diff for: .github/CONTRIBUTING.md

+9-25
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
1-
# Contributing to Better-Mock
2-
3-
The following is a set of guidelines for contributing to `better-mock`. Please spend several minutes in reading these guidelines before you create an issue or pull request.
4-
5-
Anyway, these are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request.
6-
7-
## Opening an Issue
8-
9-
If you think you have found a bug, or have a new feature idea, please start by making sure it hasn't already been reported or fixed. You can search through existing issues and PRs to see if someone has reported one similar to yours.
10-
11-
Next, create a new issue that briefly explains the problem, and provides a bit of background as to the circumstances that triggered it, and steps to reproduce it.
12-
131
## Submitting a Pull Request
142

15-
It's welcomed to pull request, And there are some tips about that:
16-
17-
- Before working on a large change, it is best to open an issue first to discuss it with the maintainers.
18-
19-
- When in doubt, keep your pull requests small. To give a PR the best chance of getting accepted, don't bundle more than one feature or bug fix per pull request. It's always best to create two smaller PRs than one big one.
3+
非常感谢您为 `better-mock` 做出贡献,在提交 pull request 前请花几分钟时间阅读一下这篇指南:
204

21-
- When adding new features or modifying existing, please attempt to include tests to confirm the new behaviour.
5+
- 在进行巨大更改之前,先开一个 issue,与维护人员讨论。
226

23-
- Rebase before creating a PR to keep commit history clear.
7+
- 请保持你的 pr 尽可能的小,不要将多个特性或者多个 bug 修复写到一个 pr 里。
248

25-
- Add some descriptions and refer relative issues for you PR.
9+
- 尽可能多的为你的 pr 填写描述信息。
2610

2711
## Getting started
2812

29-
1. Fork `better-mock`, then clone the repository to your local.
13+
1. Fork `better-mock`, 然后克隆仓库到本地。
3014

31-
2. Install dependencies.
15+
2. 基于 `develop` 分支拉取新的分支,在做完更改之后,可以执行 `npm run dev` 进行调试。
3216

33-
3. Execute `npm run build` after you make changes.
17+
3. 请确保你的更改都通过了 `test/browser/*.js` 下的单元测试。
3418

35-
4. Please complete the unit test to ensure that your changes are covered.
19+
4. 提交代码,注意不要将 `dist` 目录下的更改提交上去。
3620

37-
5. Submit a Pull-Request to `better-mock`.
21+
4. 提交 pr 到 `better-mock``develop` 分支。

Diff for: dist/mock.browser.esm.js

+186-83
Large diffs are not rendered by default.

Diff for: dist/mock.browser.js

+186-83
Large diffs are not rendered by default.

Diff for: dist/mock.browser.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/mock.mp.esm.js

+185-82
Large diffs are not rendered by default.

Diff for: dist/mock.mp.js

+185-82
Large diffs are not rendered by default.

Diff for: dist/mock.node.js

+185-82
Large diffs are not rendered by default.

Diff for: doc/.vuepress/config.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module.exports = {
2929
['/document/random/web', 'web'],
3030
['/document/random/address', 'address'],
3131
['/document/random/helper', 'helper'],
32-
['/document/random/miscellaneous', 'miscellaneous']
32+
['/document/random/miscellaneous', 'miscellaneous'],
33+
['/document/random/extend', '自定义扩展']
3334
]
3435
},
3536
['/document/valid/', 'Mock.valid()'],
@@ -48,4 +49,4 @@ module.exports = {
4849
}))
4950
}
5051
}
51-
}
52+
}

Diff for: doc/document/random/README.md

-90
This file was deleted.

Diff for: doc/document/random/extend.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Random.extend
2+
3+
* Random.extend( source )
4+
5+
Mock.Random 中的方法与数据模板的 `@占位符` 一一对应,在需要时还可以为 Mock.Random 扩展方法,然后在数据模板中通过 `@扩展方法` 引用。例如:
6+
7+
8+
```js
9+
Random.extend({
10+
constellation: function(date) {
11+
const constellations = ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座']
12+
return this.pick(constellations)
13+
}
14+
})
15+
Random.constellation()
16+
// => "水瓶座"
17+
Mock.mock('@CONSTELLATION')
18+
// => "天蝎座"
19+
Mock.mock({
20+
constellation: '@CONSTELLATION'
21+
})
22+
// => { constellation: "射手座" }
23+
```

Diff for: doc/document/random/helper.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Random.shuffle(['a', 'e', 'i', 'o', 'u'])
6767
// => ["o", "u", "e", "i", "a"]
6868

6969
Random.shuffle(['a', 'e', 'i', 'o', 'u'], 3)
70-
// => ["o", "u", "i"
70+
// => ["o", "u", "i"]
7171

7272
Random.shuffle(['a', 'e', 'i', 'o', 'u'], 2, 4)
7373
// => ["o", "u"]

Diff for: doc/document/random/image.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* Random.image()
44
* Random.image( size )
5-
* Random.image( size, background )
5+
* Random.image( size, text )
66
* Random.image( size, background, text )
77
* Random.image( size, background, foreground, text )
88
* Random.image( size, background, foreground, format, text )
@@ -27,33 +27,33 @@
2727

2828
### background <Badge text="可选"/>
2929

30-
指示图片的背景色。默认值为 `'#000000'`
30+
指示图片的背景色。。
3131

3232
### foreground <Badge text="可选"/>
3333

34-
指示图片的前景色(文字)。默认值为 `'#FFFFFF'`
34+
指示图片的前景色(文字)。。
3535

3636
### format <Badge text="可选"/>
3737

38-
指示图片的格式。默认值为 `'png'`可选值包括:`'png'``'gif'``'jpg'`
38+
指示图片的格式。可选值包括:`'png'``'gif'``'jpg'`
3939

4040
### text <Badge text="可选"/>
4141

4242
指示图片上的文字。默认值为参数 size。
4343

4444
```js
4545
Random.image()
46-
// => "http://dummyimage.com/125x125"
47-
Random.image('200x100')
48-
// => "http://dummyimage.com/200x100"
49-
Random.image('200x100', '#fb0a2a')
50-
// => "http://dummyimage.com/200x100/fb0a2a"
51-
Random.image('200x100', '#02adea', 'Hello')
52-
// => "http://dummyimage.com/200x100/02adea&text=Hello"
53-
Random.image('200x100', '#00405d', '#FFF', 'Mock')
54-
// => "http://dummyimage.com/200x100/00405d/FFF&text=Mock"
55-
Random.image('200x100', '#ffcc33', '#FFF', 'png', '!')
56-
// => "http://dummyimage.com/200x100/ffcc33/FFF.png&text=!"
46+
// => "https://iph.href.lu/450x600?bg=&fg=&text="
47+
Random.image('300x400')
48+
// => "https://iph.href.lu/300x400?bg=&fg=&text="
49+
Random.image('300x400', 'HelloWorld')
50+
// => "https://iph.href.lu/300x400?bg=&fg=&text=HelloWorld"
51+
Random.image('300x400', '#234567', 'HelloWorld')
52+
// => "https://iph.href.lu/300x400?bg=234567&fg=&text=HelloWorld"
53+
Random.image('300x400', '#234567', '#FFFFFF', 'HelloWorld')
54+
// => "https://iph.href.lu/300x400?bg=234567&fg=FFFFFF&text=HelloWorld"
55+
Random.image('300x400', '#234567', '#FFFFFF', 'png', 'HelloWorld')
56+
// => "http://dummyimage.com/300x400/234567/FFFFFF.png&text=HelloWorld"
5757
```
5858

5959
## Random.dataImage

Diff for: doc/document/random/text.md

+38
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,44 @@ Random.cword('零一二三四五六七八九十', 5, 7)
168168
// => "九七七零四"
169169
```
170170

171+
## Random.emoji
172+
173+
* Random.emoji()
174+
* Random.emoji( pool )
175+
* Random.emoji( length )
176+
* Random.emoji( pool, length )
177+
* Random.emoji( min, max )
178+
* Random.emoji( pool, min, max )
179+
180+
随机生成一个或多个 emoji 表情字符。
181+
182+
### pool <Badge text="可选"/>
183+
184+
可以是任意字符串,如常用字符、特使字符、emoji等,将从中选择一个或多个字符返回。
185+
186+
### min <Badge text="可选"/>
187+
188+
随机 emoji 字符串的最小长度。默认值为 1。
189+
190+
### max <Badge text="可选"/>
191+
192+
随机 emoji 字符串的最大长度。默认值为 1。
193+
194+
```js
195+
Random.emoji()
196+
// => "😷"
197+
Random.emoji('😀😁😂😃😄')
198+
// => "😁"
199+
Random.emoji(3)
200+
// => "😂😃😄"
201+
Random.emoji('😀😁😂😃😄', 2)
202+
// => ""😃😀""
203+
Random.emoji(3, 6)
204+
// => "🐥🐄🍪🌘😷🙊"
205+
Random.emoji('123🌘😷🙊★♠♫', 3, 6)
206+
// => "★2🌘😷"
207+
```
208+
171209
## Random.title
172210

173211
* Random.title()

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "better-mock",
33
"description": "Forked from Mockjs. Generate random data & Intercept ajax request. Support miniprogram.",
44
"author": "[email protected]",
5-
"version": "0.2.7",
5+
"version": "0.2.8",
66
"main": "./dist/mock.node.js",
77
"module": "./dist/mock.browser.esm.js",
88
"browser": "./dist/mock.browser.js",

Diff for: src/core/regexp/handler.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ const handler = {
8686
}
8787
return handler[node.type] ? handler[node.type](node, result, cache) : handler.token(node)
8888
},
89-
90-
token: function (node) {
89+
token: /* istanbul ignore next */ function (node) {
9190
switch (node.type) {
9291
case 'start':
9392
case 'end':

Diff for: src/core/regexp/parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function ControlCharacter (n) {
6161
Token.call(this, 'control-character'), this.code = n.toUpperCase()
6262
}
6363

64+
/* istanbul ignore next */
6465
var parser = function () {
6566
function n (n, l) {
6667
function u () {
@@ -516,7 +517,6 @@ var parser = function () {
516517
null !== t ? (Lt = l, u = bu(t), null === u ? (qt = l, l = u) : l = u) : (qt = l,
517518
l = il)) : (qt = l, l = il), l
518519
}
519-
520520
var rl, el = arguments.length > 1 ? arguments[1] : {}, ol = {
521521
regexp: c
522522
}, cl = c, il = null, al = '', fl = '|', sl = '"|"', hl = function (n, l) {

Diff for: src/platform/browser/fetch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if (window.Proxy) {
3939
return extendRequest(request, input, init)
4040
}
4141
})
42-
} else {
42+
} /* istanbul ignore next */ else {
4343
MockRequest = function MockRequest (input: RequestInfo, init?: RequestInit | undefined): Request {
4444
const request = new _nativeRequest(input, init)
4545
return extendRequest(request, input, init)

Diff for: src/random/address.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const county = function (prefix: boolean = false): string {
3535
const specialCity = ['460400', '441900', '442000', '620200']
3636
const province = helper.pickMap(areas)
3737
const city = helper.pickMap(province.cities)
38+
/* istanbul ignore next */
3839
if (specialCity.indexOf(city.code) !== -1) {
3940
return county(prefix)
4041
}

0 commit comments

Comments
 (0)