diff options
| author | Eric Cheng <[email protected]> | 2022-11-14 17:56:49 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-14 22:56:49 +0000 |
| commit | 801e9e0a6afa2bd472652eb7aaee5581ef458342 (patch) | |
| tree | e33cf4d8682583164606e62d49876806664eb9d2 | |
| parent | 66ccca3e11721647c4c13179eb1e23f13d43ef03 (diff) | |
| download | faker-801e9e0a6afa2bd472652eb7aaee5581ef458342.tar.xz faker-801e9e0a6afa2bd472652eb7aaee5581ef458342.zip | |
refactor(string): rename params (#1551)
| -rw-r--r-- | src/modules/finance/index.ts | 2 | ||||
| -rw-r--r-- | src/modules/random/index.ts | 10 | ||||
| -rw-r--r-- | src/modules/string/index.ts | 60 | ||||
| -rw-r--r-- | src/modules/vehicle/index.ts | 8 | ||||
| -rw-r--r-- | test/__snapshots__/string.spec.ts.snap | 48 | ||||
| -rw-r--r-- | test/random.spec.ts | 8 | ||||
| -rw-r--r-- | test/string.spec.ts | 124 |
7 files changed, 132 insertions, 128 deletions
diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 89b655bd..e739d920 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -238,7 +238,7 @@ export class FinanceModule { address += this.faker.string.alphanumeric({ length: addressLength, casing: 'mixed', - bannedChars: '0OIl', + exclude: '0OIl', }); return address; diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts index 0505744d..cb81935b 100644 --- a/src/modules/random/index.ts +++ b/src/modules/random/index.ts @@ -211,7 +211,11 @@ export class RandomModule { if (typeof options === 'number') { return this.faker.string.alpha(options); } - return this.faker.string.alpha({ ...options, length: options.count }); + return this.faker.string.alpha({ + length: options.count, + casing: options.casing, + exclude: options.bannedChars, + }); } /** @@ -248,7 +252,7 @@ export class RandomModule { }); return this.faker.string.alphanumeric({ length: count, - bannedChars: options.bannedChars, + exclude: options.bannedChars, casing: options.casing, }); } @@ -290,7 +294,7 @@ export class RandomModule { return this.faker.string.numeric({ length, allowLeadingZeros: options.allowLeadingZeros, - bannedDigits: options.bannedDigits, + exclude: options.bannedDigits, }); } } diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index 171c0cf6..22cb39d5 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -98,17 +98,17 @@ export class StringModule { /** * Generating a string consisting of letters in the English alphabet. * - * @param options Either the number of characters or an options instance. Defaults to `{ length: 1, casing: 'mixed', bannedChars: [] }`. + * @param options Either the number of characters or an options instance. Defaults to `{ length: 1, casing: 'mixed', exclude: [] }`. * @param options.length The number of characters to generate. Defaults to `1`. * @param options.casing The casing of the characters. Defaults to `'mixed'`. - * @param options.bannedChars An array with characters to exclude. Defaults to `[]`. + * @param options.exclude An array with characters which should be excluded in the generated string. Defaults to `[]`. * * @example * faker.string.alpha() // 'b' * faker.string.alpha(10) // 'fEcAaCVbaR' * faker.string.alpha({ casing: 'lower' }) // 'r' - * faker.string.alpha({ bannedChars: ['W'] }) // 'Z' - * faker.string.alpha({ length: 5, casing: 'upper', bannedChars: ['A'] }) // 'DTCIC' + * faker.string.alpha({ exclude: ['W'] }) // 'Z' + * faker.string.alpha({ length: 5, casing: 'upper', exclude: ['A'] }) // 'DTCIC' * * @since 8.0.0 */ @@ -118,7 +118,7 @@ export class StringModule { | { length?: number; casing?: Casing; - bannedChars?: readonly LiteralUnion<AlphaChar>[] | string; + exclude?: readonly LiteralUnion<AlphaChar>[] | string; } = {} ): string { if (typeof options === 'number') { @@ -128,10 +128,10 @@ export class StringModule { } const { length = 1, casing = 'mixed' } = options; - let { bannedChars = [] } = options; + let { exclude = [] } = options; - if (typeof bannedChars === 'string') { - bannedChars = bannedChars.split(''); + if (typeof exclude === 'string') { + exclude = exclude.split(''); } if (length <= 0) { @@ -152,11 +152,11 @@ export class StringModule { break; } - charsArray = charsArray.filter((elem) => !bannedChars.includes(elem)); + charsArray = charsArray.filter((elem) => !exclude.includes(elem)); if (charsArray.length === 0) { throw new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ); } @@ -168,17 +168,17 @@ export class StringModule { /** * Generating a string consisting of alpha characters and digits. * - * @param options Either the number of characters or an options instance. Defaults to `{ length: 1, casing: 'mixed', bannedChars: [] }`. + * @param options Either the number of characters or an options instance. Defaults to `{ length: 1, casing: 'mixed', exclude: [] }`. * @param options.length The number of characters and digits to generate. Defaults to `1`. * @param options.casing The casing of the characters. Defaults to `'mixed'`. - * @param options.bannedChars An array of characters and digits which should be banned in the generated string. Defaults to `[]`. + * @param options.exclude An array of characters and digits which should be excluded in the generated string. Defaults to `[]`. * * @example * faker.string.alphanumeric() // '2' * faker.string.alphanumeric(5) // '3e5V7' * faker.string.alphanumeric({ casing: 'upper' }) // 'A' - * faker.string.alphanumeric({ bannedChars: ['W'] }) // 'r' - * faker.string.alphanumeric({ length: 5, bannedChars: ["a"] }) // 'x1Z7f' + * faker.string.alphanumeric({ exclude: ['W'] }) // 'r' + * faker.string.alphanumeric({ length: 5, exclude: ["a"] }) // 'x1Z7f' * * @since 8.0.0 */ @@ -188,7 +188,7 @@ export class StringModule { | { length?: number; casing?: Casing; - bannedChars?: readonly LiteralUnion<AlphaNumericChar>[] | string; + exclude?: readonly LiteralUnion<AlphaNumericChar>[] | string; } = {} ): string { if (typeof options === 'number') { @@ -203,10 +203,10 @@ export class StringModule { return ''; } - let { bannedChars = [] } = options; + let { exclude = [] } = options; - if (typeof bannedChars === 'string') { - bannedChars = bannedChars.split(''); + if (typeof exclude === 'string') { + exclude = exclude.split(''); } let charsArray = [...DIGIT_CHARS]; @@ -224,11 +224,11 @@ export class StringModule { break; } - charsArray = charsArray.filter((elem) => !bannedChars.includes(elem)); + charsArray = charsArray.filter((elem) => !exclude.includes(elem)); if (charsArray.length === 0) { throw new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ); } @@ -307,17 +307,17 @@ export class StringModule { /** * Generates a given length string of digits. * - * @param options Either the number of characters or the options to use. Defaults to `{ length: 1, allowLeadingZeros = false, bannedDigits = [] }`. + * @param options Either the number of characters or the options to use. Defaults to `{ length: 1, allowLeadingZeros = false, exclude = [] }`. * @param options.length The number of digits to generate. Defaults to `1`. * @param options.allowLeadingZeros If true, leading zeros will be allowed. Defaults to `false`. - * @param options.bannedDigits An array of digits which should be banned in the generated string. Defaults to `[]`. + * @param options.exclude An array of digits which should be excluded in the generated string. Defaults to `[]`. * * @example * faker.string.numeric() // '2' * faker.string.numeric(5) // '31507' * faker.string.numeric(42) // '56434563150765416546479875435481513188548' * faker.string.numeric({ length: 42, allowLeadingZeros: true }) // '00564846278453876543517840713421451546115' - * faker.string.numeric({ length: 6, bannedDigits: ['0'] }) // '943228' + * faker.string.numeric({ length: 6, exclude: ['0'] }) // '943228' * * @since 8.0.0 */ @@ -327,7 +327,7 @@ export class StringModule { | { length?: number; allowLeadingZeros?: boolean; - bannedDigits?: readonly LiteralUnion<NumericChar>[] | string; + exclude?: readonly LiteralUnion<NumericChar>[] | string; } = {} ): string { if (typeof options === 'number') { @@ -341,14 +341,14 @@ export class StringModule { return ''; } - let { bannedDigits = [] } = options; + let { exclude = [] } = options; - if (typeof bannedDigits === 'string') { - bannedDigits = bannedDigits.split(''); + if (typeof exclude === 'string') { + exclude = exclude.split(''); } const allowedDigits = DIGIT_CHARS.filter( - (digit) => !bannedDigits.includes(digit) + (digit) => !exclude.includes(digit) ); if ( @@ -358,13 +358,13 @@ export class StringModule { allowedDigits[0] === '0') ) { throw new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ); } let result = ''; - if (!allowLeadingZeros && !bannedDigits.includes('0')) { + if (!allowLeadingZeros && !exclude.includes('0')) { result += this.faker.helpers.arrayElement( allowedDigits.filter((digit) => digit !== '0') ); diff --git a/src/modules/vehicle/index.ts b/src/modules/vehicle/index.ts index 3ef8f748..e6bdaeb3 100644 --- a/src/modules/vehicle/index.ts +++ b/src/modules/vehicle/index.ts @@ -87,19 +87,19 @@ export class VehicleModule { * @since 5.0.0 */ vin(): string { - const bannedChars = ['o', 'i', 'q', 'O', 'I', 'Q']; + const exclude = ['o', 'i', 'q', 'O', 'I', 'Q']; return `${this.faker.string.alphanumeric({ length: 10, casing: 'upper', - bannedChars, + exclude, })}${this.faker.string.alpha({ length: 1, casing: 'upper', - bannedChars, + exclude, })}${this.faker.string.alphanumeric({ length: 1, casing: 'upper', - bannedChars, + exclude, })}${this.faker.datatype.number({ min: 10000, max: 99999 })}` // return five digit # .toUpperCase(); } diff --git a/test/__snapshots__/string.spec.ts.snap b/test/__snapshots__/string.spec.ts.snap index f4a607b4..bcac1178 100644 --- a/test/__snapshots__/string.spec.ts.snap +++ b/test/__snapshots__/string.spec.ts.snap @@ -2,14 +2,14 @@ exports[`string > 42 > alpha > noArgs 1`] = `"t"`; -exports[`string > 42 > alpha > with bannedChars 1`] = `"A"`; - exports[`string > 42 > alpha > with casing = lower 1`] = `"j"`; exports[`string > 42 > alpha > with casing = mixed 1`] = `"t"`; exports[`string > 42 > alpha > with casing = upper 1`] = `"J"`; +exports[`string > 42 > alpha > with exclude 1`] = `"A"`; + exports[`string > 42 > alpha > with length 1`] = `"tPXjMO"`; exports[`string > 42 > alpha > with length parameter 1`] = `"tPXjM"`; @@ -22,18 +22,18 @@ exports[`string > 42 > alpha > with length parameter 4`] = `"rFhKH"`; exports[`string > 42 > alpha > with length parameter 5`] = `"bcYLR"`; -exports[`string > 42 > alpha > with length, casing and bannedChars 1`] = `"fwzcvwj"`; +exports[`string > 42 > alpha > with length, casing and exclude 1`] = `"fwzcvwj"`; exports[`string > 42 > alphanumeric > noArgs 1`] = `"n"`; -exports[`string > 42 > alphanumeric > with bannedChars 1`] = `"x"`; - exports[`string > 42 > alphanumeric > with casing = lower 1`] = `"d"`; exports[`string > 42 > alphanumeric > with casing = mixed 1`] = `"n"`; exports[`string > 42 > alphanumeric > with casing = upper 1`] = `"D"`; +exports[`string > 42 > alphanumeric > with exclude 1`] = `"x"`; + exports[`string > 42 > alphanumeric > with length 1`] = `"nNWbJM"`; exports[`string > 42 > alphanumeric > with length parameter 1`] = `"nNWbJ"`; @@ -46,7 +46,7 @@ exports[`string > 42 > alphanumeric > with length parameter 4`] = `"kB8HE"`; exports[`string > 42 > alphanumeric > with length parameter 5`] = `"13YIP"`; -exports[`string > 42 > alphanumeric > with length, casing and bannedChars 1`] = `"cvy4kvh"`; +exports[`string > 42 > alphanumeric > with length, casing and exclude 1`] = `"cvy4kvh"`; exports[`string > 42 > hexadecimal > noArgs 1`] = `"0x8"`; @@ -66,7 +66,7 @@ exports[`string > 42 > numeric > noArgs 1`] = `"4"`; exports[`string > 42 > numeric > with allowLeadingZeros 1`] = `"3"`; -exports[`string > 42 > numeric > with bannedDigits 1`] = `"7"`; +exports[`string > 42 > numeric > with exclude 1`] = `"7"`; exports[`string > 42 > numeric > with length 1`] = `"479177"`; @@ -80,7 +80,7 @@ exports[`string > 42 > numeric > with length parameter 4`] = `"46176"`; exports[`string > 42 > numeric > with length parameter 5`] = `"10978"`; -exports[`string > 42 > numeric > with length, allowLeadingZeros and bannedDigits 1`] = `"6890887"`; +exports[`string > 42 > numeric > with length, allowLeadingZeros and exclude 1`] = `"6890887"`; exports[`string > 42 > sample > noArgs 1`] = `"Cky2eiXX/J"`; @@ -106,14 +106,14 @@ exports[`string > 42 > uuid 5`] = `"d95f4984-24c2-410f-ac63-400d3bbbcc91"`; exports[`string > 1211 > alpha > noArgs 1`] = `"W"`; -exports[`string > 1211 > alpha > with bannedChars 1`] = `"X"`; - exports[`string > 1211 > alpha > with casing = lower 1`] = `"y"`; exports[`string > 1211 > alpha > with casing = mixed 1`] = `"W"`; exports[`string > 1211 > alpha > with casing = upper 1`] = `"Y"`; +exports[`string > 1211 > alpha > with exclude 1`] = `"X"`; + exports[`string > 1211 > alpha > with length 1`] = `"WxUOlg"`; exports[`string > 1211 > alpha > with length parameter 1`] = `"WxUOl"`; @@ -126,18 +126,18 @@ exports[`string > 1211 > alpha > with length parameter 4`] = `"iKMQa"`; exports[`string > 1211 > alpha > with length parameter 5`] = `"NIILR"`; -exports[`string > 1211 > alpha > with length, casing and bannedChars 1`] = `"yhywdcz"`; +exports[`string > 1211 > alpha > with length, casing and exclude 1`] = `"yhywdcz"`; exports[`string > 1211 > alphanumeric > noArgs 1`] = `"V"`; -exports[`string > 1211 > alphanumeric > with bannedChars 1`] = `"W"`; - exports[`string > 1211 > alphanumeric > with casing = lower 1`] = `"x"`; exports[`string > 1211 > alphanumeric > with casing = mixed 1`] = `"V"`; exports[`string > 1211 > alphanumeric > with casing = upper 1`] = `"X"`; +exports[`string > 1211 > alphanumeric > with exclude 1`] = `"W"`; + exports[`string > 1211 > alphanumeric > with length 1`] = `"VsTMd8"`; exports[`string > 1211 > alphanumeric > with length parameter 1`] = `"VsTMd"`; @@ -150,7 +150,7 @@ exports[`string > 1211 > alphanumeric > with length parameter 4`] = `"aHKO0"`; exports[`string > 1211 > alphanumeric > with length parameter 5`] = `"LFEJP"`; -exports[`string > 1211 > alphanumeric > with length, casing and bannedChars 1`] = `"yexv53z"`; +exports[`string > 1211 > alphanumeric > with length, casing and exclude 1`] = `"yexv53z"`; exports[`string > 1211 > hexadecimal > noArgs 1`] = `"0xE"`; @@ -170,7 +170,7 @@ exports[`string > 1211 > numeric > noArgs 1`] = `"9"`; exports[`string > 1211 > numeric > with allowLeadingZeros 1`] = `"9"`; -exports[`string > 1211 > numeric > with bannedDigits 1`] = `"9"`; +exports[`string > 1211 > numeric > with exclude 1`] = `"9"`; exports[`string > 1211 > numeric > with length 1`] = `"948721"`; @@ -184,7 +184,7 @@ exports[`string > 1211 > numeric > with length parameter 4`] = `"26780"`; exports[`string > 1211 > numeric > with length parameter 5`] = `"76678"`; -exports[`string > 1211 > numeric > with length, allowLeadingZeros and bannedDigits 1`] = `"9798609"`; +exports[`string > 1211 > numeric > with length, allowLeadingZeros and exclude 1`] = `"9798609"`; exports[`string > 1211 > sample > noArgs 1`] = `"wKti5-}$_/"`; @@ -210,14 +210,14 @@ exports[`string > 1211 > uuid 5`] = `"7b91ce88-effb-4d1d-93bb-ad759e00b86c"`; exports[`string > 1337 > alpha > noArgs 1`] = `"n"`; -exports[`string > 1337 > alpha > with bannedChars 1`] = `"v"`; - exports[`string > 1337 > alpha > with casing = lower 1`] = `"g"`; exports[`string > 1337 > alpha > with casing = mixed 1`] = `"n"`; exports[`string > 1337 > alpha > with casing = upper 1`] = `"G"`; +exports[`string > 1337 > alpha > with exclude 1`] = `"v"`; + exports[`string > 1337 > alpha > with length 1`] = `"nDiloC"`; exports[`string > 1337 > alpha > with length parameter 1`] = `"nDilo"`; @@ -230,18 +230,18 @@ exports[`string > 1337 > alpha > with length parameter 4`] = `"oMpfP"`; exports[`string > 1337 > alpha > with length parameter 5`] = `"ueGsg"`; -exports[`string > 1337 > alpha > with length, casing and bannedChars 1`] = `"eicdeih"`; +exports[`string > 1337 > alpha > with length, casing and exclude 1`] = `"eicdeih"`; exports[`string > 1337 > alphanumeric > noArgs 1`] = `"g"`; -exports[`string > 1337 > alphanumeric > with bannedChars 1`] = `"s"`; - exports[`string > 1337 > alphanumeric > with casing = lower 1`] = `"9"`; exports[`string > 1337 > alphanumeric > with casing = mixed 1`] = `"g"`; exports[`string > 1337 > alphanumeric > with casing = upper 1`] = `"9"`; +exports[`string > 1337 > alphanumeric > with exclude 1`] = `"s"`; + exports[`string > 1337 > alphanumeric > with length 1`] = `"gy9dhx"`; exports[`string > 1337 > alphanumeric > with length parameter 1`] = `"gy9dh"`; @@ -254,7 +254,7 @@ exports[`string > 1337 > alphanumeric > with length parameter 4`] = `"gJj7N"`; exports[`string > 1337 > alphanumeric > with length parameter 5`] = `"n5Cm7"`; -exports[`string > 1337 > alphanumeric > with length, casing and bannedChars 1`] = `"ag45age"`; +exports[`string > 1337 > alphanumeric > with length, casing and exclude 1`] = `"ag45age"`; exports[`string > 1337 > hexadecimal > noArgs 1`] = `"0x5"`; @@ -274,7 +274,7 @@ exports[`string > 1337 > numeric > noArgs 1`] = `"3"`; exports[`string > 1337 > numeric > with allowLeadingZeros 1`] = `"2"`; -exports[`string > 1337 > numeric > with bannedDigits 1`] = `"7"`; +exports[`string > 1337 > numeric > with exclude 1`] = `"7"`; exports[`string > 1337 > numeric > with length 1`] = `"351225"`; @@ -288,7 +288,7 @@ exports[`string > 1337 > numeric > with length parameter 4`] = `"37318"`; exports[`string > 1337 > numeric > with length parameter 5`] = `"40631"`; -exports[`string > 1337 > numeric > with length, allowLeadingZeros and bannedDigits 1`] = `"6706677"`; +exports[`string > 1337 > numeric > with length, allowLeadingZeros and exclude 1`] = `"6706677"`; exports[`string > 1337 > sample > noArgs 1`] = `"9U/4:SK$>6"`; diff --git a/test/random.spec.ts b/test/random.spec.ts index 2cdfd2c0..2e84a713 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -197,7 +197,7 @@ describe('random', () => { }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); @@ -316,7 +316,7 @@ describe('random', () => { }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); @@ -413,7 +413,7 @@ describe('random', () => { }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); @@ -426,7 +426,7 @@ describe('random', () => { }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); diff --git a/test/string.spec.ts b/test/string.spec.ts index 66c6bc59..6d34f098 100644 --- a/test/string.spec.ts +++ b/test/string.spec.ts @@ -14,11 +14,11 @@ describe('string', () => { .it('with casing = lower', { casing: 'lower' }) .it('with casing = upper', { casing: 'upper' }) .it('with casing = mixed', { casing: 'mixed' }) - .it('with bannedChars', { bannedChars: 'abcdefghijk' }) - .it('with length, casing and bannedChars', { + .it('with exclude', { exclude: 'abcdefghijk' }) + .it('with length, casing and exclude', { length: 7, casing: 'lower', - bannedChars: 'lmnopqrstu', + exclude: 'lmnopqrstu', }); }); @@ -29,11 +29,11 @@ describe('string', () => { .it('with casing = lower', { casing: 'lower' }) .it('with casing = upper', { casing: 'upper' }) .it('with casing = mixed', { casing: 'mixed' }) - .it('with bannedChars', { bannedChars: 'abcdefghijk12345' }) - .it('with length, casing and bannedChars', { + .it('with exclude', { exclude: 'abcdefghijk12345' }) + .it('with length, casing and exclude', { length: 7, casing: 'lower', - bannedChars: 'lmnopqrstu67890', + exclude: 'lmnopqrstu67890', }); }); @@ -56,11 +56,11 @@ describe('string', () => { .itRepeated('with length parameter', 5, 5) .it('with length', { length: 6 }) .it('with allowLeadingZeros', { allowLeadingZeros: true }) - .it('with bannedDigits', { bannedDigits: '12345' }) - .it('with length, allowLeadingZeros and bannedDigits', { + .it('with exclude', { exclude: '12345' }) + .it('with length, allowLeadingZeros and exclude', { length: 7, allowLeadingZeros: true, - bannedDigits: '12345', + exclude: '12345', }); }); @@ -114,7 +114,7 @@ describe('string', () => { const actual = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: ['a', 'p'], + exclude: ['a', 'p'], }); expect(actual).toHaveLength(5); @@ -125,35 +125,35 @@ describe('string', () => { const actual = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: 'ap', + exclude: 'ap', }); expect(actual).toHaveLength(5); expect(actual).toMatch(/^[b-oq-z]{5}$/); }); - it('should be able handle mistake in banned characters array', () => { + it('should be able handle mistake in excluded characters array', () => { const alphaText = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: ['a', 'a', 'p'], + exclude: ['a', 'a', 'p'], }); expect(alphaText).toHaveLength(5); expect(alphaText).toMatch(/^[b-oq-z]{5}$/); }); - it('should throw if all possible characters being banned', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); + it('should throw if all possible characters being excluded', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz'.split(''); expect(() => faker.string.alpha({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); @@ -162,15 +162,15 @@ describe('string', () => { const input: { length: number; casing: 'mixed'; - bannedChars: string[]; + exclude: string[]; } = Object.freeze({ length: 5, casing: 'mixed', - bannedChars: ['a', '%'], + exclude: ['a', '%'], }); expect(() => faker.string.alpha(input)).not.toThrow(); - expect(input.bannedChars).toEqual(['a', '%']); + expect(input.exclude).toEqual(['a', '%']); }); }); @@ -206,92 +206,92 @@ describe('string', () => { ); it('should be able to ban all alphabetic characters', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); + const exclude = 'abcdefghijklmnopqrstuvwxyz'.split(''); const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all alphabetic characters via string', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'; + const exclude = 'abcdefghijklmnopqrstuvwxyz'; const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all numeric characters', () => { - const bannedChars = '0123456789'.split(''); + const exclude = '0123456789'.split(''); const alphaText = faker.string.alphanumeric({ length: 5, - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all numeric characters via string', () => { - const bannedChars = '0123456789'; + const exclude = '0123456789'; const alphaText = faker.string.alphanumeric({ length: 5, - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); - it('should be able to handle mistake in banned characters array', () => { + it('should be able to handle mistake in excluded characters array', () => { const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars: ['a', 'p', 'a'], + exclude: ['a', 'p', 'a'], }); expect(alphaText).toHaveLength(5); expect(alphaText).toMatch(/^[0-9b-oq-z]{5}$/); }); - it('should throw if all possible characters being banned', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); + it('should throw if all possible characters being excluded', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); expect(() => faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); - it('should throw if all possible characters being banned via string', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'; + it('should throw if all possible characters being excluded via string', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz0123456789'; expect(() => faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError(); }); @@ -299,14 +299,14 @@ describe('string', () => { it('should not mutate the input object', () => { const input: { length: number; - bannedChars: string[]; + exclude: string[]; } = Object.freeze({ length: 5, - bannedChars: ['a', '0', '%'], + exclude: ['a', '0', '%'], }); expect(() => faker.string.alphanumeric(input)).not.toThrow(); - expect(input.bannedChars).toEqual(['a', '0', '%']); + expect(input.exclude).toEqual(['a', '0', '%']); }); }); @@ -374,68 +374,68 @@ describe('string', () => { expect(actual).toMatch(/^[0-9]+$/); }); - it('should allow leading zeros via option and all other digits banned', () => { + it('should allow leading zeros via option and all other digits excluded', () => { const actual = faker.string.numeric({ length: 4, allowLeadingZeros: true, - bannedDigits: '123456789'.split(''), + exclude: '123456789'.split(''), }); expect(actual).toBe('0000'); }); - it('should allow leading zeros via option and all other digits banned via string', () => { + it('should allow leading zeros via option and all other digits excluded via string', () => { const actual = faker.string.numeric({ length: 4, allowLeadingZeros: true, - bannedDigits: '123456789', + exclude: '123456789', }); expect(actual).toBe('0000'); }); - it('should fail on leading zeros via option and all other digits banned', () => { + it('should fail on leading zeros via option and all other digits excluded', () => { expect(() => faker.string.numeric({ length: 4, allowLeadingZeros: false, - bannedDigits: '123456789'.split(''), + exclude: '123456789'.split(''), }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); - it('should fail on leading zeros via option and all other digits banned via string', () => { + it('should fail on leading zeros via option and all other digits excluded via string', () => { expect(() => faker.string.numeric({ length: 4, allowLeadingZeros: false, - bannedDigits: '123456789', + exclude: '123456789', }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); - it('should ban all digits passed via bannedDigits', () => { + it('should ban all digits passed via exclude', () => { const actual = faker.string.numeric({ length: 1000, - bannedDigits: 'c84U1'.split(''), + exclude: 'c84U1'.split(''), }); expect(actual).toHaveLength(1000); expect(actual).toMatch(/^[0235679]{1000}$/); }); - it('should ban all digits passed via bannedDigits via string', () => { + it('should ban all digits passed via exclude via string', () => { const actual = faker.string.numeric({ length: 1000, - bannedDigits: 'c84U1', + exclude: 'c84U1', }); expect(actual).toHaveLength(1000); |
