Skip to content

Commit

Permalink
refactor(string): rename alphaNumeric to alphanumeric
Browse files Browse the repository at this point in the history
  • Loading branch information
xDivisionByZerox committed Jul 21, 2022
1 parent db5d983 commit 298cd80
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/modules/random/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ export class Random {
): string {
deprecated({
deprecated: 'faker.random.alphaNumeric()',
proposed: 'faker.string.alphaNumeric()',
proposed: 'faker.string.alphanumeric()',
since: '8.0',
until: '9.0',
});
return this.faker.string.alphaNumeric({
return this.faker.string.alphanumeric({
bannedChars: options.bannedChars,
casing: options.casing,
count,
Expand Down
8 changes: 4 additions & 4 deletions src/modules/string/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ export class StringModule {
* @param options.bannedChars An array of characters and digits which should be banned in the generated string. Defaults to `[]`.
*
* @example
* faker.string.alphaNumeric() // '2'
* faker.string.alphaNumeric(5) // '3e5v7'
* faker.string.alphaNumeric(5, { bannedChars: ["a"] }) // 'xszlm'
* faker.string.alphanumeric() // '2'
* faker.string.alphanumeric(5) // '3e5v7'
* faker.string.alphanumeric(5, { bannedChars: ["a"] }) // 'xszlm'
*/
alphaNumeric(
alphanumeric(
options:
| number
| {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/vehicle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ export class Vehicle {
*/
vin(): string {
const bannedChars = ['o', 'i', 'q', 'O', 'I', 'Q'];
return `${this.faker.string.alphaNumeric({
return `${this.faker.string.alphanumeric({
count: 10,
casing: 'upper',
bannedChars,
})}${this.faker.string.alpha({
count: 1,
casing: 'upper',
bannedChars,
})}${this.faker.string.alphaNumeric({
})}${this.faker.string.alphanumeric({
count: 1,
casing: 'upper',
bannedChars,
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/string.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`string > random() > should return a deterministic string of given lengt
exports[`string > seed: 42 > alpha() 1`] = `"t"`;
exports[`string > seed: 42 > alphaNumeric() 1`] = `"n"`;
exports[`string > seed: 42 > alphanumeric() 1`] = `"n"`;
exports[`string > seed: 42 > hexadecimal() > should return a deterministic hex of given length 1`] = `"8BE4ABdd39321aD7d3fe01FfCE404F4d6db0906bd8"`;
Expand All @@ -22,7 +22,7 @@ exports[`string > seed: 42 > uuid() 1`] = `"5cf2bc99-2721-407d-992b-a00fbdf302f2
exports[`string > seed: 1211 > alpha() 1`] = `"W"`;
exports[`string > seed: 1211 > alphaNumeric() 1`] = `"V"`;
exports[`string > seed: 1211 > alphanumeric() 1`] = `"V"`;
exports[`string > seed: 1211 > hexadecimal() > should return a deterministic hex of given length 1`] = `"EaDB42F0e3f4A973fAB0AeefCE96DFCF49cD438dF9"`;
Expand All @@ -36,7 +36,7 @@ exports[`string > seed: 1211 > uuid() 1`] = `"e7ec32f0-a2a3-4c65-abbd-0caabde64d
exports[`string > seed: 1337 > alpha() 1`] = `"n"`;
exports[`string > seed: 1337 > alphaNumeric() 1`] = `"g"`;
exports[`string > seed: 1337 > alphanumeric() 1`] = `"g"`;
exports[`string > seed: 1337 > hexadecimal() > should return a deterministic hex of given length 1`] = `"5c346ba075bd57F5A62B82d72AF39CBBB07a98cbA8"`;
Expand Down
26 changes: 13 additions & 13 deletions test/string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const functionNames: (keyof StringModule)[] = [
'hexadecimal',
'random',
'alpha',
'alphaNumeric',
'alphanumeric',
'numeric',
];

Expand Down Expand Up @@ -212,7 +212,7 @@ describe('string', () => {

describe('alphaNumeric', () => {
it('should generate single character when no additional argument was provided', () => {
const actual = faker.string.alphaNumeric();
const actual = faker.string.alphanumeric();

expect(actual).toHaveLength(1);
});
Expand All @@ -222,28 +222,28 @@ describe('string', () => {
['lower', /^[a-z0-9]{250}$/],
['mixed', /^[a-zA-Z0-9]{250}$/],
] as const)('should return %s-case', (casing, pattern) => {
const actual = faker.string.alphaNumeric({ count: 250, casing });
const actual = faker.string.alphanumeric({ count: 250, casing });
expect(actual).toMatch(pattern);
});

it('should generate many random characters', () => {
const actual = faker.string.alphaNumeric(5);
const actual = faker.string.alphanumeric(5);

expect(actual).toHaveLength(5);
});

it.each([0, -1, -100])(
'should return empty string when length is <= 0',
(length) => {
const actual = faker.string.alphaNumeric(length);
const actual = faker.string.alphanumeric(length);

expect(actual).toBe('');
}
);

it('should be able to ban all alphabetic characters', () => {
const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split('');
const alphaText = faker.string.alphaNumeric({
const alphaText = faker.string.alphanumeric({
count: 5,
bannedChars,
casing: 'lower',
Expand All @@ -257,7 +257,7 @@ describe('string', () => {

it('should be able to ban all alphabetic characters via string', () => {
const bannedChars = 'abcdefghijklmnopqrstuvwxyz';
const alphaText = faker.string.alphaNumeric({
const alphaText = faker.string.alphanumeric({
count: 5,
bannedChars,
casing: 'lower',
Expand All @@ -271,7 +271,7 @@ describe('string', () => {

it('should be able to ban all numeric characters', () => {
const bannedChars = '0123456789'.split('');
const alphaText = faker.string.alphaNumeric({
const alphaText = faker.string.alphanumeric({
count: 5,
bannedChars,
});
Expand All @@ -284,7 +284,7 @@ describe('string', () => {

it('should be able to ban all numeric characters via string', () => {
const bannedChars = '0123456789';
const alphaText = faker.string.alphaNumeric({
const alphaText = faker.string.alphanumeric({
count: 5,
bannedChars,
});
Expand All @@ -296,7 +296,7 @@ describe('string', () => {
});

it('should be able to handle mistake in banned characters array', () => {
const alphaText = faker.string.alphaNumeric({
const alphaText = faker.string.alphanumeric({
count: 5,
bannedChars: ['a', 'p', 'a'],
casing: 'lower',
Expand All @@ -309,7 +309,7 @@ describe('string', () => {
it('should throw if all possible characters being banned', () => {
const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split('');
expect(() =>
faker.string.alphaNumeric({
faker.string.alphanumeric({
count: 5,
bannedChars,
casing: 'lower',
Expand All @@ -324,7 +324,7 @@ describe('string', () => {
it('should throw if all possible characters being banned via string', () => {
const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789';
expect(() =>
faker.string.alphaNumeric({
faker.string.alphanumeric({
count: 5,
bannedChars,
casing: 'lower',
Expand All @@ -341,7 +341,7 @@ describe('string', () => {
count: 5,
});

expect(() => faker.string.alphaNumeric(input)).not.toThrow();
expect(() => faker.string.alphanumeric(input)).not.toThrow();
expect(input.bannedChars).toEqual(['a', '0', '%']);
});
});
Expand Down

0 comments on commit 298cd80

Please sign in to comment.