Skip to content

Commit 801e9e0

Browse files
authored
refactor(string): rename params (#1551)
1 parent 66ccca3 commit 801e9e0

7 files changed

Lines changed: 132 additions & 128 deletions

File tree

src/modules/finance/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class FinanceModule {
238238
address += this.faker.string.alphanumeric({
239239
length: addressLength,
240240
casing: 'mixed',
241-
bannedChars: '0OIl',
241+
exclude: '0OIl',
242242
});
243243

244244
return address;

src/modules/random/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ export class RandomModule {
211211
if (typeof options === 'number') {
212212
return this.faker.string.alpha(options);
213213
}
214-
return this.faker.string.alpha({ ...options, length: options.count });
214+
return this.faker.string.alpha({
215+
length: options.count,
216+
casing: options.casing,
217+
exclude: options.bannedChars,
218+
});
215219
}
216220

217221
/**
@@ -248,7 +252,7 @@ export class RandomModule {
248252
});
249253
return this.faker.string.alphanumeric({
250254
length: count,
251-
bannedChars: options.bannedChars,
255+
exclude: options.bannedChars,
252256
casing: options.casing,
253257
});
254258
}
@@ -290,7 +294,7 @@ export class RandomModule {
290294
return this.faker.string.numeric({
291295
length,
292296
allowLeadingZeros: options.allowLeadingZeros,
293-
bannedDigits: options.bannedDigits,
297+
exclude: options.bannedDigits,
294298
});
295299
}
296300
}

src/modules/string/index.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ export class StringModule {
9898
/**
9999
* Generating a string consisting of letters in the English alphabet.
100100
*
101-
* @param options Either the number of characters or an options instance. Defaults to `{ length: 1, casing: 'mixed', bannedChars: [] }`.
101+
* @param options Either the number of characters or an options instance. Defaults to `{ length: 1, casing: 'mixed', exclude: [] }`.
102102
* @param options.length The number of characters to generate. Defaults to `1`.
103103
* @param options.casing The casing of the characters. Defaults to `'mixed'`.
104-
* @param options.bannedChars An array with characters to exclude. Defaults to `[]`.
104+
* @param options.exclude An array with characters which should be excluded in the generated string. Defaults to `[]`.
105105
*
106106
* @example
107107
* faker.string.alpha() // 'b'
108108
* faker.string.alpha(10) // 'fEcAaCVbaR'
109109
* faker.string.alpha({ casing: 'lower' }) // 'r'
110-
* faker.string.alpha({ bannedChars: ['W'] }) // 'Z'
111-
* faker.string.alpha({ length: 5, casing: 'upper', bannedChars: ['A'] }) // 'DTCIC'
110+
* faker.string.alpha({ exclude: ['W'] }) // 'Z'
111+
* faker.string.alpha({ length: 5, casing: 'upper', exclude: ['A'] }) // 'DTCIC'
112112
*
113113
* @since 8.0.0
114114
*/
@@ -118,7 +118,7 @@ export class StringModule {
118118
| {
119119
length?: number;
120120
casing?: Casing;
121-
bannedChars?: readonly LiteralUnion<AlphaChar>[] | string;
121+
exclude?: readonly LiteralUnion<AlphaChar>[] | string;
122122
} = {}
123123
): string {
124124
if (typeof options === 'number') {
@@ -128,10 +128,10 @@ export class StringModule {
128128
}
129129

130130
const { length = 1, casing = 'mixed' } = options;
131-
let { bannedChars = [] } = options;
131+
let { exclude = [] } = options;
132132

133-
if (typeof bannedChars === 'string') {
134-
bannedChars = bannedChars.split('');
133+
if (typeof exclude === 'string') {
134+
exclude = exclude.split('');
135135
}
136136

137137
if (length <= 0) {
@@ -152,11 +152,11 @@ export class StringModule {
152152
break;
153153
}
154154

155-
charsArray = charsArray.filter((elem) => !bannedChars.includes(elem));
155+
charsArray = charsArray.filter((elem) => !exclude.includes(elem));
156156

157157
if (charsArray.length === 0) {
158158
throw new FakerError(
159-
'Unable to generate string, because all possible characters are banned.'
159+
'Unable to generate string, because all possible characters are excluded.'
160160
);
161161
}
162162

@@ -168,17 +168,17 @@ export class StringModule {
168168
/**
169169
* Generating a string consisting of alpha characters and digits.
170170
*
171-
* @param options Either the number of characters or an options instance. Defaults to `{ length: 1, casing: 'mixed', bannedChars: [] }`.
171+
* @param options Either the number of characters or an options instance. Defaults to `{ length: 1, casing: 'mixed', exclude: [] }`.
172172
* @param options.length The number of characters and digits to generate. Defaults to `1`.
173173
* @param options.casing The casing of the characters. Defaults to `'mixed'`.
174-
* @param options.bannedChars An array of characters and digits which should be banned in the generated string. Defaults to `[]`.
174+
* @param options.exclude An array of characters and digits which should be excluded in the generated string. Defaults to `[]`.
175175
*
176176
* @example
177177
* faker.string.alphanumeric() // '2'
178178
* faker.string.alphanumeric(5) // '3e5V7'
179179
* faker.string.alphanumeric({ casing: 'upper' }) // 'A'
180-
* faker.string.alphanumeric({ bannedChars: ['W'] }) // 'r'
181-
* faker.string.alphanumeric({ length: 5, bannedChars: ["a"] }) // 'x1Z7f'
180+
* faker.string.alphanumeric({ exclude: ['W'] }) // 'r'
181+
* faker.string.alphanumeric({ length: 5, exclude: ["a"] }) // 'x1Z7f'
182182
*
183183
* @since 8.0.0
184184
*/
@@ -188,7 +188,7 @@ export class StringModule {
188188
| {
189189
length?: number;
190190
casing?: Casing;
191-
bannedChars?: readonly LiteralUnion<AlphaNumericChar>[] | string;
191+
exclude?: readonly LiteralUnion<AlphaNumericChar>[] | string;
192192
} = {}
193193
): string {
194194
if (typeof options === 'number') {
@@ -203,10 +203,10 @@ export class StringModule {
203203
return '';
204204
}
205205

206-
let { bannedChars = [] } = options;
206+
let { exclude = [] } = options;
207207

208-
if (typeof bannedChars === 'string') {
209-
bannedChars = bannedChars.split('');
208+
if (typeof exclude === 'string') {
209+
exclude = exclude.split('');
210210
}
211211

212212
let charsArray = [...DIGIT_CHARS];
@@ -224,11 +224,11 @@ export class StringModule {
224224
break;
225225
}
226226

227-
charsArray = charsArray.filter((elem) => !bannedChars.includes(elem));
227+
charsArray = charsArray.filter((elem) => !exclude.includes(elem));
228228

229229
if (charsArray.length === 0) {
230230
throw new FakerError(
231-
'Unable to generate string, because all possible characters are banned.'
231+
'Unable to generate string, because all possible characters are excluded.'
232232
);
233233
}
234234

@@ -307,17 +307,17 @@ export class StringModule {
307307
/**
308308
* Generates a given length string of digits.
309309
*
310-
* @param options Either the number of characters or the options to use. Defaults to `{ length: 1, allowLeadingZeros = false, bannedDigits = [] }`.
310+
* @param options Either the number of characters or the options to use. Defaults to `{ length: 1, allowLeadingZeros = false, exclude = [] }`.
311311
* @param options.length The number of digits to generate. Defaults to `1`.
312312
* @param options.allowLeadingZeros If true, leading zeros will be allowed. Defaults to `false`.
313-
* @param options.bannedDigits An array of digits which should be banned in the generated string. Defaults to `[]`.
313+
* @param options.exclude An array of digits which should be excluded in the generated string. Defaults to `[]`.
314314
*
315315
* @example
316316
* faker.string.numeric() // '2'
317317
* faker.string.numeric(5) // '31507'
318318
* faker.string.numeric(42) // '56434563150765416546479875435481513188548'
319319
* faker.string.numeric({ length: 42, allowLeadingZeros: true }) // '00564846278453876543517840713421451546115'
320-
* faker.string.numeric({ length: 6, bannedDigits: ['0'] }) // '943228'
320+
* faker.string.numeric({ length: 6, exclude: ['0'] }) // '943228'
321321
*
322322
* @since 8.0.0
323323
*/
@@ -327,7 +327,7 @@ export class StringModule {
327327
| {
328328
length?: number;
329329
allowLeadingZeros?: boolean;
330-
bannedDigits?: readonly LiteralUnion<NumericChar>[] | string;
330+
exclude?: readonly LiteralUnion<NumericChar>[] | string;
331331
} = {}
332332
): string {
333333
if (typeof options === 'number') {
@@ -341,14 +341,14 @@ export class StringModule {
341341
return '';
342342
}
343343

344-
let { bannedDigits = [] } = options;
344+
let { exclude = [] } = options;
345345

346-
if (typeof bannedDigits === 'string') {
347-
bannedDigits = bannedDigits.split('');
346+
if (typeof exclude === 'string') {
347+
exclude = exclude.split('');
348348
}
349349

350350
const allowedDigits = DIGIT_CHARS.filter(
351-
(digit) => !bannedDigits.includes(digit)
351+
(digit) => !exclude.includes(digit)
352352
);
353353

354354
if (
@@ -358,13 +358,13 @@ export class StringModule {
358358
allowedDigits[0] === '0')
359359
) {
360360
throw new FakerError(
361-
'Unable to generate numeric string, because all possible digits are banned.'
361+
'Unable to generate numeric string, because all possible digits are excluded.'
362362
);
363363
}
364364

365365
let result = '';
366366

367-
if (!allowLeadingZeros && !bannedDigits.includes('0')) {
367+
if (!allowLeadingZeros && !exclude.includes('0')) {
368368
result += this.faker.helpers.arrayElement(
369369
allowedDigits.filter((digit) => digit !== '0')
370370
);

src/modules/vehicle/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ export class VehicleModule {
8787
* @since 5.0.0
8888
*/
8989
vin(): string {
90-
const bannedChars = ['o', 'i', 'q', 'O', 'I', 'Q'];
90+
const exclude = ['o', 'i', 'q', 'O', 'I', 'Q'];
9191
return `${this.faker.string.alphanumeric({
9292
length: 10,
9393
casing: 'upper',
94-
bannedChars,
94+
exclude,
9595
})}${this.faker.string.alpha({
9696
length: 1,
9797
casing: 'upper',
98-
bannedChars,
98+
exclude,
9999
})}${this.faker.string.alphanumeric({
100100
length: 1,
101101
casing: 'upper',
102-
bannedChars,
102+
exclude,
103103
})}${this.faker.datatype.number({ min: 10000, max: 99999 })}` // return five digit #
104104
.toUpperCase();
105105
}

0 commit comments

Comments
 (0)