Skip to content

Commit b95a72d

Browse files
authored
Merge branch 'next' into add-dhivehi-locale
2 parents 1437476 + 1452a59 commit b95a72d

File tree

12 files changed

+187
-105
lines changed

12 files changed

+187
-105
lines changed

docs/.vitepress/config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ const config = defineConfig({
7272
content: description,
7373
},
7474
],
75-
[
76-
'meta',
77-
{
78-
name: 'description',
79-
content: description,
80-
},
81-
],
8275
[
8376
'meta',
8477
{

netlify.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[build.environment]
22
NODE_VERSION = "18"
3-
NPM_FLAGS = "--version" # prevent Netlify npm install
43

54
# Documentation
65
[build]
76
publish = "docs/.vitepress/dist"
8-
command = "npx pnpm i --store=node_modules/.pnpm-store && npm run docs:build:ci"
7+
command = "pnpm docs:build:ci"
98

109
# Redirect to Discord server
1110
[[redirects]]

src/modules/datatype/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,37 @@ export class DatatypeModule {
192192
/**
193193
* Returns the boolean value true or false.
194194
*
195+
* **Note:**
196+
* A probability of `0.75` results in `true` being returned `75%` of the calls; likewise `0.3` => `30%`.
197+
* If the probability is `<= 0.0`, it will always return `false`.
198+
* If the probability is `>= 1.0`, it will always return `true`.
199+
* The probability is limited to two decimal places.
200+
*
201+
* @param options The optional options object or the probability (`[0.00, 1.00]`) of returning `true`. Defaults to `0.5`.
202+
* @param options.probability The probability (`[0.00, 1.00]`) of returning `true`. Defaults to `0.5`.
203+
*
195204
* @example
196205
* faker.datatype.boolean() // false
206+
* faker.datatype.boolean(0.9) // true
207+
* faker.datatype.boolean({ probability: 0.1 }) // false
197208
*
198209
* @since 5.5.0
199210
*/
200-
boolean(): boolean {
201-
return !!this.number(1);
211+
boolean(options: number | { probability?: number } = {}): boolean {
212+
if (typeof options === 'number') {
213+
options = {
214+
probability: options,
215+
};
216+
}
217+
const { probability = 0.5 } = options;
218+
if (probability <= 0) {
219+
return false;
220+
}
221+
if (probability >= 1) {
222+
// This check is required to avoid returning false when float() returns 1
223+
return true;
224+
}
225+
return this.float({ min: 0, max: 1 }) < probability;
202226
}
203227

204228
/**

src/modules/finance/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,13 @@ export class FinanceModule {
393393
if (bban.type === 'a') {
394394
s += this.faker.helpers.arrayElement(iban.alpha);
395395
} else if (bban.type === 'c') {
396-
if (this.faker.datatype.number(100) < 80) {
396+
if (this.faker.datatype.boolean(0.8)) {
397397
s += this.faker.datatype.number(9);
398398
} else {
399399
s += this.faker.helpers.arrayElement(iban.alpha);
400400
}
401401
} else {
402-
if (c >= 3 && this.faker.datatype.number(100) < 30) {
402+
if (c >= 3 && this.faker.datatype.boolean(0.3)) {
403403
if (this.faker.datatype.boolean()) {
404404
s += this.faker.helpers.arrayElement(iban.pattern100);
405405
c -= 2;

src/modules/helpers/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ export class HelpersModule {
354354
callback: () => T,
355355
options: { probability?: number } = {}
356356
): T | undefined {
357-
const { probability = 0.5 } = options;
358-
if (this.faker.datatype.float({ min: 0, max: 1 }) < probability) {
357+
if (this.faker.datatype.boolean(options)) {
359358
return callback();
360359
}
361360
return undefined;

test/__snapshots__/datatype.spec.ts.snap

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,45 @@
22

33
exports[`datatype > 42 > array > noArgs 1`] = `
44
[
5-
79654,
6-
"2eiXX/J/*&",
7-
86617,
8-
60111,
9-
70807,
10-
"\\"&{dnx4!1}",
11-
61748,
12-
61165,
13-
"!I#<QYF-%<",
14-
"C6K)jZ3DP|",
5+
"ky2eiXX/J/",
6+
7+
72199,
8+
93855,
9+
"!1}2Z=YQ!I",
10+
"<QYF-%<{C6",
11+
")jZ3DP|XL%",
12+
60754,
13+
17052,
14+
"'\\"yxzUlD=\\"",
1515
]
1616
`;
1717
1818
exports[`datatype > 42 > array > with length 1`] = `
1919
[
20-
79654,
21-
"2eiXX/J/*&",
22-
86617,
23-
60111,
20+
"ky2eiXX/J/",
21+
22+
72199,
23+
93855,
2424
]
2525
`;
2626
2727
exports[`datatype > 42 > bigInt > noArgs 1`] = `379177551410048n`;
2828
2929
exports[`datatype > 42 > bigInt > with value 1`] = `37n`;
3030
31-
exports[`datatype > 42 > boolean 1`] = `false`;
31+
exports[`datatype > 42 > boolean > noArgs 1`] = `true`;
3232
33-
exports[`datatype > 42 > boolean 2`] = `true`;
33+
exports[`datatype > 42 > boolean > noArgs 2`] = `false`;
3434
35-
exports[`datatype > 42 > boolean 3`] = `true`;
35+
exports[`datatype > 42 > boolean > noArgs 3`] = `false`;
3636
37-
exports[`datatype > 42 > boolean 4`] = `false`;
37+
exports[`datatype > 42 > boolean > noArgs 4`] = `true`;
3838
39-
exports[`datatype > 42 > boolean 5`] = `true`;
39+
exports[`datatype > 42 > boolean > noArgs 5`] = `false`;
40+
41+
exports[`datatype > 42 > boolean > with probability 1`] = `true`;
42+
43+
exports[`datatype > 42 > boolean > with probability option 1`] = `false`;
4044
4145
exports[`datatype > 42 > datetime > noArgs 1`] = `2031-03-14T21:33:22.114Z`;
4246
@@ -80,7 +84,7 @@ exports[`datatype > 42 > hexadecimal > with length, prefix, and casing 1`] = `"0
8084
8185
exports[`datatype > 42 > hexadecimal > with prefix 1`] = `"0x8"`;
8286
83-
exports[`datatype > 42 > json 1`] = `"{\\"foo\\":79654,\\"bar\\":\\"2eiXX/J/*&\\",\\"bike\\":86617,\\"a\\":60111,\\"b\\":70807,\\"name\\":\\"\\\\\\"&{dnx4!1}\\",\\"prop\\":61748}"`;
87+
exports[`datatype > 42 > json 1`] = `"{\\"foo\\":\\"ky2eiXX/J/\\",\\"bar\\":\\"&Kq@X.b]\\\\\\"&\\",\\"bike\\":72199,\\"a\\":93855,\\"b\\":\\"!1}2Z=YQ!I\\",\\"name\\":\\"<QYF-%<{C6\\",\\"prop\\":\\")jZ3DP|XL%\\"}"`;
8488

8589
exports[`datatype > 42 > number > noArgs 1`] = `37454`;
8690

@@ -118,41 +122,45 @@ exports[`datatype > 42 > uuid 5`] = `"d95f4984-24c2-410f-ac63-400d3bbbcc91"`;
118122

119123
exports[`datatype > 1211 > array > noArgs 1`] = `
120124
[
121-
"Kti5-}$_/\`",
122-
76408,
123-
35403,
124-
69406,
125-
"l\\"h^]dnwI<",
126-
"|p|5KWu3/C",
127-
"|Jh!E=x\\"RH",
128-
"/5V<1bEQuA",
129-
"p=DW9F=V1(",
130-
"7a6.$boN\\\\7",
125+
45901,
126+
77826,
127+
"-}$_/\`4hHA",
128+
"afl\\"h^]dnw",
129+
"<q|p|5KWu3",
130+
"CZ|Jh!E=x\\"",
131+
42131,
132+
15894,
133+
"V<1bEQuA|p",
134+
"DW9F=V1(U7",
131135
]
132136
`;
133137

134138
exports[`datatype > 1211 > array > with length 1`] = `
135139
[
136-
"Kti5-}$_/\`",
137-
76408,
138-
35403,
139-
69406,
140+
45901,
141+
77826,
142+
"-}$_/\`4hHA",
143+
"afl\\"h^]dnw",
140144
]
141145
`;
142146

143147
exports[`datatype > 1211 > bigInt > noArgs 1`] = `948721906162743n`;
144148

145149
exports[`datatype > 1211 > bigInt > with value 1`] = `8n`;
146150

147-
exports[`datatype > 1211 > boolean 1`] = `true`;
151+
exports[`datatype > 1211 > boolean > noArgs 1`] = `false`;
152+
153+
exports[`datatype > 1211 > boolean > noArgs 2`] = `true`;
148154

149-
exports[`datatype > 1211 > boolean 2`] = `false`;
155+
exports[`datatype > 1211 > boolean > noArgs 3`] = `false`;
150156

151-
exports[`datatype > 1211 > boolean 3`] = `true`;
157+
exports[`datatype > 1211 > boolean > noArgs 4`] = `false`;
152158

153-
exports[`datatype > 1211 > boolean 4`] = `true`;
159+
exports[`datatype > 1211 > boolean > noArgs 5`] = `true`;
154160

155-
exports[`datatype > 1211 > boolean 5`] = `false`;
161+
exports[`datatype > 1211 > boolean > with probability 1`] = `false`;
162+
163+
exports[`datatype > 1211 > boolean > with probability option 1`] = `false`;
156164

157165
exports[`datatype > 1211 > datetime > noArgs 1`] = `2092-02-20T03:42:04.341Z`;
158166

@@ -196,7 +204,7 @@ exports[`datatype > 1211 > hexadecimal > with length, prefix, and casing 1`] = `
196204

197205
exports[`datatype > 1211 > hexadecimal > with prefix 1`] = `"0xE"`;
198206

199-
exports[`datatype > 1211 > json 1`] = `"{\\"foo\\":\\"Kti5-}$_/\`\\",\\"bar\\":76408,\\"bike\\":35403,\\"a\\":69406,\\"b\\":\\"l\\\\\\"h^]dnwI<\\",\\"name\\":\\"|p|5KWu3/C\\",\\"prop\\":\\"|Jh!E=x\\\\\\"RH\\"}"`;
207+
exports[`datatype > 1211 > json 1`] = `"{\\"foo\\":45901,\\"bar\\":77826,\\"bike\\":\\"-}$_/\`4hHA\\",\\"a\\":\\"afl\\\\\\"h^]dnw\\",\\"b\\":\\"<q|p|5KWu3\\",\\"name\\":\\"CZ|Jh!E=x\\\\\\"\\",\\"prop\\":42131}"`;
200208

201209
exports[`datatype > 1211 > number > noArgs 1`] = `92852`;
202210

@@ -234,41 +242,45 @@ exports[`datatype > 1211 > uuid 5`] = `"7b91ce88-effb-4d1d-93bb-ad759e00b86c"`;
234242

235243
exports[`datatype > 1337 > array > noArgs 1`] = `
236244
[
237-
56052,
238-
21258,
239-
54308,
240-
3397,
241-
23538,
242-
"X9@{:e=+kD",
243-
62850,
244-
12505,
245-
"|/Jqjjj!BL",
246-
38106,
245+
"U/4:SK$>6Q",
246+
26194,
247+
"{:e=+kD)[B",
248+
"e|/Jqjjj!B",
249+
"GDWQgC2M;q",
250+
40502,
251+
44050,
252+
".Gm3tRwnZ2",
253+
95735,
254+
42541,
247255
]
248256
`;
249257
250258
exports[`datatype > 1337 > array > with length 1`] = `
251259
[
252-
56052,
253-
21258,
254-
54308,
255-
3397,
260+
"U/4:SK$>6Q",
261+
26194,
262+
"{:e=+kD)[B",
263+
"e|/Jqjjj!B",
256264
]
257265
`;
258266
259267
exports[`datatype > 1337 > bigInt > noArgs 1`] = `251225403255239n`;
260268
261269
exports[`datatype > 1337 > bigInt > with value 1`] = `25n`;
262270
263-
exports[`datatype > 1337 > boolean 1`] = `false`;
271+
exports[`datatype > 1337 > boolean > noArgs 1`] = `true`;
272+
273+
exports[`datatype > 1337 > boolean > noArgs 2`] = `false`;
274+
275+
exports[`datatype > 1337 > boolean > noArgs 3`] = `true`;
264276
265-
exports[`datatype > 1337 > boolean 2`] = `true`;
277+
exports[`datatype > 1337 > boolean > noArgs 4`] = `true`;
266278
267-
exports[`datatype > 1337 > boolean 3`] = `false`;
279+
exports[`datatype > 1337 > boolean > noArgs 5`] = `true`;
268280
269-
exports[`datatype > 1337 > boolean 4`] = `false`;
281+
exports[`datatype > 1337 > boolean > with probability 1`] = `true`;
270282
271-
exports[`datatype > 1337 > boolean 5`] = `false`;
283+
exports[`datatype > 1337 > boolean > with probability option 1`] = `false`;
272284
273285
exports[`datatype > 1337 > datetime > noArgs 1`] = `2018-10-28T08:46:11.896Z`;
274286
@@ -312,7 +324,7 @@ exports[`datatype > 1337 > hexadecimal > with length, prefix, and casing 1`] = `
312324
313325
exports[`datatype > 1337 > hexadecimal > with prefix 1`] = `"0x5"`;
314326
315-
exports[`datatype > 1337 > json 1`] = `"{\\"foo\\":56052,\\"bar\\":21258,\\"bike\\":54308,\\"a\\":3397,\\"b\\":23538,\\"name\\":\\"X9@{:e=+kD\\",\\"prop\\":62850}"`;
327+
exports[`datatype > 1337 > json 1`] = `"{\\"foo\\":\\"U/4:SK$>6Q\\",\\"bar\\":26194,\\"bike\\":\\"{:e=+kD)[B\\",\\"a\\":\\"e|/Jqjjj!B\\",\\"b\\":\\"GDWQgC2M;q\\",\\"name\\":40502,\\"prop\\":44050}"`;
316328
317329
exports[`datatype > 1337 > number > noArgs 1`] = `26202`;
318330

test/__snapshots__/finance.spec.ts.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ exports[`finance > 42 > amount > with min 1`] = `"380.79"`;
1616

1717
exports[`finance > 42 > amount > with min and max and dec and symbol 1`] = `"$24.98160"`;
1818

19-
exports[`finance > 42 > bic > noArgs 1`] = `"UYETSCLL"`;
19+
exports[`finance > 42 > bic > noArgs 1`] = `"UYETSCLLG53"`;
2020

21-
exports[`finance > 42 > bic > with branch code 1`] = `"JUYEPSSL5G5"`;
21+
exports[`finance > 42 > bic > with branch code 1`] = `"JUYEPSSLXXX"`;
2222

2323
exports[`finance > 42 > bitcoinAddress 1`] = `"3XbJMAAara64sSkA9HD24YHQWd1bZbB"`;
2424

@@ -42,7 +42,7 @@ exports[`finance > 42 > iban > noArgs 1`] = `"GT30Y75110867098F1E3542612J4"`;
4242

4343
exports[`finance > 42 > iban > with formatted 1`] = `"GT30 Y751 1086 7098 F1E3 5426 12J4"`;
4444

45-
exports[`finance > 42 > iban > with formatted and countryCode 1`] = `"DE05 7175 0200 8600 6098 92"`;
45+
exports[`finance > 42 > iban > with formatted and countryCode 1`] = `"DE47 7175 0020 0086 0600 97"`;
4646

4747
exports[`finance > 42 > litecoinAddress 1`] = `"3XbJMAAara64sSkA9HD24YHQWd1b"`;
4848

@@ -82,9 +82,9 @@ exports[`finance > 1211 > amount > with min 1`] = `"929.24"`;
8282

8383
exports[`finance > 1211 > amount > with min and max and dec and symbol 1`] = `"$47.14081"`;
8484

85-
exports[`finance > 1211 > bic > noArgs 1`] = `"LXUFBTZ15O7"`;
85+
exports[`finance > 1211 > bic > noArgs 1`] = `"LXUFBTZ1"`;
8686

87-
exports[`finance > 1211 > bic > with branch code 1`] = `"YLXUDE4ZXXX"`;
87+
exports[`finance > 1211 > bic > with branch code 1`] = `"YLXUDE4ZO5O"`;
8888

8989
exports[`finance > 1211 > bitcoinAddress 1`] = `"1TMe8Z3EaFdLqmaGKP1LEEJQVriSZRZdsAUc9nC"`;
9090

@@ -104,11 +104,11 @@ exports[`finance > 1211 > currencySymbol 1`] = `"₭"`;
104104

105105
exports[`finance > 1211 > ethereumAddress 1`] = `"0xeadb42f0e3f4a973fab0aeefce96dfcf49cd438d"`;
106106

107-
exports[`finance > 1211 > iban > noArgs 1`] = `"TN0382001124170679299069"`;
107+
exports[`finance > 1211 > iban > noArgs 1`] = `"TN4282016024170679299006"`;
108108

109-
exports[`finance > 1211 > iban > with formatted 1`] = `"TN03 8200 1124 1706 7929 9069"`;
109+
exports[`finance > 1211 > iban > with formatted 1`] = `"TN42 8201 6024 1706 7929 9006"`;
110110

111-
exports[`finance > 1211 > iban > with formatted and countryCode 1`] = `"DE63 4709 0026 0041 7067 89"`;
111+
exports[`finance > 1211 > iban > with formatted and countryCode 1`] = `"DE41 4700 9026 0417 0679 42"`;
112112

113113
exports[`finance > 1211 > litecoinAddress 1`] = `"MTMe8Z3EaFdLqmaGKP1LEEJQVriSZRZds"`;
114114

@@ -148,9 +148,9 @@ exports[`finance > 1337 > amount > with min 1`] = `"269.40"`;
148148

149149
exports[`finance > 1337 > amount > with min and max and dec and symbol 1`] = `"$20.48098"`;
150150

151-
exports[`finance > 1337 > bic > noArgs 1`] = `"OEFHLYG1"`;
151+
exports[`finance > 1337 > bic > noArgs 1`] = `"OEFHLYG18IL"`;
152152

153-
exports[`finance > 1337 > bic > with branch code 1`] = `"GOEFFIJGXXX"`;
153+
exports[`finance > 1337 > bic > with branch code 1`] = `"GOEFFIJGB8I"`;
154154

155155
exports[`finance > 1337 > bitcoinAddress 1`] = `"3adhxs2jewAgkYgJi7No6Cn8JZarS"`;
156156

@@ -170,11 +170,11 @@ exports[`finance > 1337 > currencySymbol 1`] = `"$"`;
170170

171171
exports[`finance > 1337 > ethereumAddress 1`] = `"0x5c346ba075bd57f5a62b82d72af39cbbb07a98cb"`;
172172

173-
exports[`finance > 1337 > iban > noArgs 1`] = `"FO7710540350900318"`;
173+
exports[`finance > 1337 > iban > noArgs 1`] = `"FO5610050250090318"`;
174174

175-
exports[`finance > 1337 > iban > with formatted 1`] = `"FO77 1054 0350 9003 18"`;
175+
exports[`finance > 1337 > iban > with formatted 1`] = `"FO56 1005 0250 0903 18"`;
176176

177-
exports[`finance > 1337 > iban > with formatted and countryCode 1`] = `"DE61 0020 5032 5090 0300 40"`;
177+
exports[`finance > 1337 > iban > with formatted and countryCode 1`] = `"DE04 0200 5032 5009 0304 06"`;
178178

179179
exports[`finance > 1337 > litecoinAddress 1`] = `"Madhxs2jewAgkYgJi7No6Cn8JZar"`;
180180

0 commit comments

Comments
 (0)