Skip to content

Commit

Permalink
Merge branch 'next' into chore/test/iban-typos
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Oct 7, 2023
2 parents c9ef215 + eb2b18b commit b2f510f
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 44 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.js
Expand Up @@ -29,8 +29,6 @@ module.exports = defineConfig({
},
plugins: ['@typescript-eslint', 'prettier', 'deprecation', 'jsdoc'],
rules: {
// We may want to use this in the future
'no-useless-escape': 'off',
eqeqeq: ['error', 'always', { null: 'ignore' }],
'no-else-return': 'error',
'prefer-template': 'error',
Expand Down Expand Up @@ -76,7 +74,6 @@ module.exports = defineConfig({
'unicorn/prefer-array-flat-map': 'off',
'unicorn/prefer-array-some': 'off',
'unicorn/prefer-code-point': 'off',
'unicorn/prefer-date-now': 'off',
'unicorn/prefer-export-from': 'off',
'unicorn/prefer-includes': 'off',
'unicorn/prefer-module': 'off',
Expand Down
6 changes: 0 additions & 6 deletions README.md
Expand Up @@ -79,12 +79,6 @@ export const USERS: User[] = faker.helpers.multiple(createRandomUser, {
});
```

The above code indicates a basic usage of Faker.
The point of interest is the import statements at the top.
The first import indicates how one can import the entirety of Faker, which includes every locale, while the commented-out import showcases how to import only a single locale.
In most situations, importing a single locale is preferable for performance because some testing frameworks reload imports for every test file, which causes startup latencies to add up quickly.
Thus, limiting the import to a single locale can speed up startup times.

## 💎 Modules

An in-depth overview of the API methods is available in the documentation for [v8 (stable)](https://fakerjs.dev/api/) and [v8.\* (next)](https://next.fakerjs.dev/api/).
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateLocales.ts
Expand Up @@ -240,7 +240,7 @@ function updateLocaleFile(filePath: string): void {
if (lstatSync(filePath).isFile()) {
const pathParts = filePath
.substring(pathLocales.length + 1, filePath.length - 3)
.split(/[\\\/]/);
.split(/[\\/]/);
const locale = pathParts[0];
pathParts.splice(0, 1);
updateLocaleFileHook(filePath, locale, pathParts);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/git/index.ts
Expand Up @@ -97,7 +97,7 @@ export class GitModule {
const email = this.faker.internet.email({ firstName, lastName });

// Normalize user according to https://github.com/libgit2/libgit2/issues/5342
user = user.replace(/^[\.,:;"\\']|[\<\>\n]|[\.,:;"\\']$/g, '');
user = user.replace(/^[.,:;"\\']|[<>\n]|[.,:;"\\']$/g, '');

lines.push(
`Author: ${user} <${email}>`,
Expand Down
14 changes: 7 additions & 7 deletions src/modules/helpers/index.ts
Expand Up @@ -99,9 +99,9 @@ function legacyRegexpStringParse(
string: string = ''
): string {
// Deal with range repeat `{min,max}`
const RANGE_REP_REG = /(.)\{(\d+)\,(\d+)\}/;
const RANGE_REP_REG = /(.)\{(\d+),(\d+)\}/;
const REP_REG = /(.)\{(\d+)\}/;
const RANGE_REG = /\[(\d+)\-(\d+)\]/;
const RANGE_REG = /\[(\d+)-(\d+)\]/;
let min: number;
let max: number;
let tmp: number;
Expand Down Expand Up @@ -192,7 +192,7 @@ export class SimpleHelpersModule {
.normalize('NFKD') //for example è decomposes to as e + ̀
.replace(/[\u0300-\u036f]/g, '') // removes combining marks
.replace(/ /g, '-') // replaces spaces with hyphens
.replace(/[^\w\.\-]+/g, ''); // removes all non-word characters except for dots and hyphens
.replace(/[^\w.-]+/g, ''); // removes all non-word characters except for dots and hyphens
}

/**
Expand Down Expand Up @@ -416,7 +416,7 @@ export class SimpleHelpersModule {

// Deal with single wildcards
const SINGLE_CHAR_REG =
/([.A-Za-z0-9])(?:\{(\d+)(?:\,(\d+)|)\}|(\?|\*|\+))(?![^[]*]|[^{]*})/;
/([.A-Za-z0-9])(?:\{(\d+)(?:,(\d+)|)\}|(\?|\*|\+))(?![^[]*]|[^{]*})/;
let token = pattern.match(SINGLE_CHAR_REG);
while (token != null) {
const quantifierMin: string = token[2];
Expand All @@ -439,7 +439,7 @@ export class SimpleHelpersModule {

const SINGLE_RANGE_REG = /(\d-\d|\w-\w|\d|\w|[-!@#$&()`.+,/"])/;
const RANGE_ALPHANUMEMRIC_REG =
/\[(\^|)(-|)(.+?)\](?:\{(\d+)(?:\,(\d+)|)\}|(\?|\*|\+)|)/;
/\[(\^|)(-|)(.+?)\](?:\{(\d+)(?:,(\d+)|)\}|(\?|\*|\+)|)/;
// Deal with character classes with quantifiers `[a-z0-9]{min[, max]}`
token = pattern.match(RANGE_ALPHANUMEMRIC_REG);
while (token != null) {
Expand Down Expand Up @@ -548,7 +548,7 @@ export class SimpleHelpersModule {
token = pattern.match(RANGE_ALPHANUMEMRIC_REG);
}

const RANGE_REP_REG = /(.)\{(\d+)\,(\d+)\}/;
const RANGE_REP_REG = /(.)\{(\d+),(\d+)\}/;
// Deal with quantifier ranges `{min,max}`
token = pattern.match(RANGE_REP_REG);
while (token != null) {
Expand Down Expand Up @@ -1181,7 +1181,7 @@ export class SimpleHelpersModule {
} = options;
return uniqueExec.exec(method, args, {
...options,
startTime: new Date().getTime(),
startTime: Date.now(),
maxTime,
maxRetries,
currentIterations: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/helpers/unique.ts
Expand Up @@ -89,10 +89,10 @@ export function exec<
store?: Record<RecordKey, RecordKey>;
} = {}
): ReturnType<TMethod> {
const now = new Date().getTime();
const now = Date.now();

const {
startTime = new Date().getTime(),
startTime = Date.now(),
maxTime = 50,
maxRetries = 50,
compare = defaultCompare,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/internet/index.ts
Expand Up @@ -265,7 +265,7 @@ export class InternetModule {
let localPart: string = this.userName({ firstName, lastName });
// Strip any special characters from the local part of the email address
// This could happen if invalid chars are passed in manually in the firstName/lastName
localPart = localPart.replace(/[^A-Za-z0-9._+\-]+/g, '');
localPart = localPart.replace(/[^A-Za-z0-9._+-]+/g, '');

// The local part of an email address is limited to 64 chars per RFC 3696
// We limit to 50 chars to be more realistic
Expand Down
2 changes: 1 addition & 1 deletion test/modules/commerce.spec.ts
Expand Up @@ -110,7 +110,7 @@ describe('commerce', () => {
expect(
amount,
'The expected match should not include a currency symbol'
).toMatch(/^[0-9\.]+$/);
).toMatch(/^[0-9.]+$/);
});

it('should handle negative amounts, but return 0', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/modules/finance.spec.ts
Expand Up @@ -279,7 +279,7 @@ describe('finance', () => {
expect(
amount,
'The expected match should not include a currency symbol'
).toMatch(/^[0-9\.]+$/);
).toMatch(/^[0-9.]+$/);
});

it('should handle negative amounts', () => {
Expand Down Expand Up @@ -456,7 +456,7 @@ describe('finance', () => {
it('should return a correct credit card number when issuer provided', () => {
//TODO: implement checks for each format with regexp
const visa = faker.finance.creditCardNumber('visa');
expect(visa).toMatch(/^4(([0-9]){12}|([0-9]){3}(\-([0-9]){4}){3})$/);
expect(visa).toMatch(/^4(([0-9]){12}|([0-9]){3}(-([0-9]){4}){3})$/);
expect(visa).toSatisfy(luhnCheck);

const mastercard = faker.finance.creditCardNumber('mastercard');
Expand Down Expand Up @@ -490,7 +490,7 @@ describe('finance', () => {

it('should return custom formatted strings', () => {
let number = faker.finance.creditCardNumber('###-###-##L');
expect(number).toMatch(/^\d{3}\-\d{3}\-\d{3}$/);
expect(number).toMatch(/^\d{3}-\d{3}-\d{3}$/);
expect(number).toSatisfy(luhnCheck);

number = faker.finance.creditCardNumber('234[5-9]#{999}L');
Expand Down
24 changes: 11 additions & 13 deletions test/modules/helpers.spec.ts
Expand Up @@ -563,7 +563,7 @@ describe('helpers', () => {
'6453-####-####-####-###L'
);
expect(number).toMatch(
/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/
/^6453-([0-9]){4}-([0-9]){4}-([0-9]){4}-([0-9]){4}$/
);
expect(number).toSatisfy(luhnCheck);
});
Expand All @@ -574,7 +574,7 @@ describe('helpers', () => {
'*'
);
expect(number).toMatch(
/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/
/^6453-([0-9]){4}-([0-9]){4}-([0-9]){4}-([0-9]){4}$/
);
expect(number).toSatisfy(luhnCheck);
});
Expand All @@ -585,14 +585,14 @@ describe('helpers', () => {
'*'
);
expect(number).toMatch(
/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/
/^6453-([0-9]){4}-([0-9]){4}-([0-9]){4}-([0-9]){4}$/
);
expect(number).toSatisfy(luhnCheck);
number = faker.helpers.replaceCreditCardSymbols(
'645[5-9]-#{4,6}-#{1,2}-#{4,6}-#{3}L'
);
expect(number).toMatch(
/^645[5-9]\-([0-9]){4,6}\-([0-9]){1,2}\-([0-9]){4,6}\-([0-9]){4}$/
/^645[5-9]-([0-9]){4,6}-([0-9]){1,2}-([0-9]){4,6}-([0-9]){4}$/
);
expect(number).toSatisfy(luhnCheck);
});
Expand All @@ -607,14 +607,14 @@ describe('helpers', () => {
const string = faker.helpers.regexpStyleStringParse('#{5,10}');
expect(string.length).toBeLessThanOrEqual(10);
expect(string.length).toBeGreaterThanOrEqual(5);
expect(string).toMatch(/^\#{5,10}$/);
expect(string).toMatch(/^#{5,10}$/);
});

it('flips the range when min > max', () => {
const string = faker.helpers.regexpStyleStringParse('#{10,5}');
expect(string.length).toBeLessThanOrEqual(10);
expect(string.length).toBeGreaterThanOrEqual(5);
expect(string).toMatch(/^\#{5,10}$/);
expect(string).toMatch(/^#{5,10}$/);
});

it('repeats string {n} number of times', () => {
Expand All @@ -638,9 +638,7 @@ describe('helpers', () => {
const string = faker.helpers.regexpStyleStringParse(
'Test#{5}%{2,5}Testing**[1-5]**{10}END'
);
expect(string).toMatch(
/^Test\#{5}%{2,5}Testing\*\*[1-5]\*\*{10}END$/
);
expect(string).toMatch(/^Test#{5}%{2,5}Testing\*\*[1-5]\*\*{10}END$/);
});
});

Expand All @@ -649,7 +647,7 @@ describe('helpers', () => {
const string = faker.helpers.fromRegExp(/#{5,10}/);
expect(string.length).toBeLessThanOrEqual(10);
expect(string.length).toBeGreaterThanOrEqual(5);
expect(string).toMatch(/^\#{5,10}$/);
expect(string).toMatch(/^#{5,10}$/);
});

it('repeats string {n} number of times', () => {
Expand All @@ -667,7 +665,7 @@ describe('helpers', () => {
const string = faker.helpers.fromRegExp(
'Test#{5}%{2,5}Testing*[1-5]{10}END'
);
expect(string).toMatch(/^Test\#{5}%{2,5}Testing*[1-5]{10}END$/);
expect(string).toMatch(/^Test#{5}%{2,5}Testing*[1-5]{10}END$/);
});

it('throws error when min > max outside set', () => {
Expand Down Expand Up @@ -1176,7 +1174,7 @@ describe('helpers', () => {
'lName',
'domain',
]); // third argument is provider, or domain for email
expect(result).toMatch(/\@domain/);
expect(result).toMatch(/@domain/);
});

it('should be possible to limit unique call by maxTime in ms', () => {
Expand Down Expand Up @@ -1292,7 +1290,7 @@ Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().`)
it('should not mutate most of the input option properties', () => {
const method = () => 'options-mutate-test';

const startTime = new Date().getTime();
const startTime = Date.now();
const maxTime = 49;
const maxRetries = 49;
const currentIterations = 0;
Expand Down
8 changes: 4 additions & 4 deletions test/modules/image.spec.ts
Expand Up @@ -410,7 +410,7 @@ describe('image', () => {

expect(avatarUrl).toBeTypeOf('string');
expect(avatarUrl).toMatch(
/^https:\/\/cloudflare\-ipfs\.com\/ipfs\/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye\/avatar\/\d{1,4}\.jpg$/
/^https:\/\/cloudflare-ipfs\.com\/ipfs\/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye\/avatar\/\d{1,4}\.jpg$/
);
});
});
Expand Down Expand Up @@ -463,7 +463,7 @@ describe('image', () => {

expect(imageUrl).toBeTypeOf('string');
expect(imageUrl).toMatch(
/^https\:\/\/loremflickr\.com\/\d+\/\d+\?lock=\d+$/
/^https:\/\/loremflickr\.com\/\d+\/\d+\?lock=\d+$/
);
});
});
Expand All @@ -474,7 +474,7 @@ describe('image', () => {

expect(imageUrl).toBeTypeOf('string');
expect(imageUrl).toMatch(
/^https\:\/\/picsum\.photos\/seed\/[0-9a-zA-Z]+\/\d+\/\d+$/
/^https:\/\/picsum\.photos\/seed\/[0-9a-zA-Z]+\/\d+\/\d+$/
);
});
});
Expand All @@ -485,7 +485,7 @@ describe('image', () => {

expect(imageUrl).toBeTypeOf('string');
expect(imageUrl).toMatch(
/^https\:\/\/via\.placeholder\.com\/\d+x\d+\/[0-9a-fA-F]{6}\/[0-9a-fA-F]{6}\.[a-z]{3,4}\?text=.+$/
/^https:\/\/via\.placeholder\.com\/\d+x\d+\/[0-9a-fA-F]{6}\/[0-9a-fA-F]{6}\.[a-z]{3,4}\?text=.+$/
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/modules/internet.spec.ts
Expand Up @@ -649,7 +649,7 @@ describe('internet', () => {
expect(ua).toBeTypeOf('string');
expect(ua.length).toBeGreaterThanOrEqual(1);
expect(ua).toMatch(
/^(([^\d]+\/[\dA-Za-z\.]+(\s\(.*\)))|([^\d]+\/[\dA-Za-z\.]+(\s\(.*\)*))(\s[^\d]+\/[\dA-Za-z\.]+(\s\(.*\)*))*)$/
/^(([^\d]+\/[\dA-Za-z.]+(\s\(.*\)))|([^\d]+\/[\dA-Za-z.]+(\s\(.*\)*))(\s[^\d]+\/[\dA-Za-z.]+(\s\(.*\)*))*)$/
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/apidoc/verify-jsdoc-tags.spec.ts
Expand Up @@ -118,7 +118,7 @@ describe('verify JSDoc tags', () => {

const path = resolvePathToMethodFile(moduleName, methodName);
const imports = [
...new Set(examples.match(/(?<!\.)faker[^\.]*(?=\.)/g)),
...new Set(examples.match(/(?<!\.)faker[^.]*(?=\.)/g)),
];
writeFileSync(
path,
Expand Down

0 comments on commit b2f510f

Please sign in to comment.