Skip to content

Commit

Permalink
Merge branch 'next' into feat/bio
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Dec 31, 2022
2 parents 08e3a78 + 351f8f0 commit 9572c0f
Show file tree
Hide file tree
Showing 48 changed files with 491 additions and 353 deletions.
27 changes: 14 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ module.exports = defineConfig({
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
format: ['PascalCase'],
selector: ['class', 'interface', 'typeAlias', 'enumMember'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
],
'@typescript-eslint/no-inferrable-types': [
'error',
{ ignoreParameters: true },
Expand All @@ -43,23 +52,15 @@ module.exports = defineConfig({
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/restrict-template-expressions': [
'@typescript-eslint/padding-line-between-statements': [
'error',
{
allowNumber: true,
allowBoolean: true,
},
{ blankLine: 'always', prev: 'block-like', next: '*' },
],
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/naming-convention': [
'@typescript-eslint/restrict-template-expressions': [
'error',
{
format: ['PascalCase'],
selector: ['class', 'interface', 'typeAlias', 'enumMember'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{ allowNumber: true, allowBoolean: true },
],
'@typescript-eslint/unbound-method': 'off',
},
overrides: [
{
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/apiDocsWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function writeApiSearchIndex(project: ProjectReflection): void {
},
];
}

return apiSection;
})
.sort((a, b) => a.text.localeCompare(b.text));
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/moduleMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function extractModuleName(module: DeclarationReflection): string {
} else if (name === 'NameModule') {
return 'Person';
}

return name.replace(/Module$/, '');
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/apidoc/parameterDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function cleanParameterDefault(value?: string): string | undefined {
if (value == null) {
return undefined;
}

// Strip type casts: "'foobar' as unknown as T" => "'foobar'"
return value.replace(/ as unknown as [A-Za-z<>]+/, '');
}
Expand Down Expand Up @@ -124,6 +125,7 @@ function patchSignatureParameterDefaults(
if (signatureParameters.length !== parameterDefaults.length) {
throw new Error('Unexpected parameter length mismatch');
}

signatureParameters.forEach(
(param, index) =>
(param.defaultValue = parameterDefaults[index] || param.defaultValue)
Expand Down
12 changes: 11 additions & 1 deletion scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export function analyzeSignature(
if (signatureTypeParameters.length !== 0) {
signatureTypeParametersString = `<${signatureTypeParameters.join(', ')}>`;
}

const signatureParametersString = signatureParameters.join(', ');

let examples: string;
Expand All @@ -150,6 +151,7 @@ export function analyzeSignature(
} else {
examples = `faker.${methodName}${signatureTypeParametersString}(${signatureParametersString}): ${signature.type?.toString()}\n`;
}

faker.seed(0);
if (moduleName) {
try {
Expand Down Expand Up @@ -230,6 +232,7 @@ function analyzeParameterOptions(
if (!parameterType) {
return [];
}

if (parameterType.type === 'union') {
return parameterType.types.flatMap((type) =>
analyzeParameterOptions(name, type)
Expand All @@ -243,7 +246,7 @@ function analyzeParameterOptions(
description: mdToHtml(
toBlock(
property.comment ??
(property.type as ReflectionType)?.declaration.signatures?.[0]
(property.type as ReflectionType)?.declaration?.signatures?.[0]
.comment
)
),
Expand All @@ -261,6 +264,7 @@ function typeToText(type_?: Type, short = false): string {
if (!type_) {
return '?';
}

const type = type_ as SomeType;
switch (type.type) {
case 'array':
Expand All @@ -283,6 +287,7 @@ function typeToText(type_?: Type, short = false): string {
.map((t) => typeToText(t, short))
.join(', ')}>`;
}

case 'reflection':
return declarationTypeToText(type.declaration, short);
case 'indexedAccess':
Expand Down Expand Up @@ -335,6 +340,7 @@ function signatureTypeToText(signature?: SignatureReflection): string {
if (!signature) {
return '(???) => ?';
}

return `(${signature.parameters
?.map((p) => `${p.name}: ${typeToText(p.type)}`)
.join(', ')}) => ${typeToText(signature.type)}`;
Expand All @@ -350,18 +356,22 @@ function extractDefaultFromComment(comment?: Comment): string | undefined {
if (!comment) {
return;
}

const summary = comment.summary;
const text = joinTagParts(summary).trim();
if (!text) {
return;
}

const result = /^(.*)[ \n]Defaults to `([^`]+)`\.(.*)$/s.exec(text);
if (!result) {
return;
}

if (result[3].trim()) {
throw new Error(`Found description text after the default value:\n${text}`);
}

summary.splice(summary.length - 2, 2);
const lastSummaryPart = summary[summary.length - 1];
lastSummaryPart.text = lastSummaryPart.text.replace(/[ \n]Defaults to $/, '');
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export function extractSeeAlsos(signature?: SignatureReflection): string[] {
if (link.startsWith('-')) {
link = link.slice(1).trim();
}

return link;
})
.filter((link) => link)
Expand Down
1 change: 1 addition & 0 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const target = ['ES2019', 'node14.17'];
if (existsSync(localeDir)) {
rmSync(localeDir, { recursive: true, force: true });
}

mkdirSync(localeDir);
for (const locale of Object.keys(locales)) {
writeFileSync(
Expand Down
3 changes: 3 additions & 0 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function removeIndexTs(files: string[]): string[] {
if (index !== -1) {
files.splice(index, 1);
}

return files;
}

Expand Down Expand Up @@ -152,6 +153,7 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
console.error(`Failed to load ${pathModules} or manually parse it.`, e);
}
}

return localeDef;
}

Expand All @@ -177,6 +179,7 @@ function generateLocalesIndexFile(
)}';`
);
}

content.push(
...modules.map((m) => `import ${escapeImport(m)} from './${m}';`)
);
Expand Down
2 changes: 2 additions & 0 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class Faker {
`Locale ${locale} is not supported. You might want to add the requested locale first to \`faker.locales\`.`
);
}

this._locale = locale;
}

Expand All @@ -75,6 +76,7 @@ export class Faker {
`Locale ${localeFallback} is not supported. You might want to add the requested locale first to \`faker.locales\`.`
);
}

this._localeFallback = localeFallback;
}

Expand Down
4 changes: 4 additions & 0 deletions src/internal/mersenne/twister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default class MersenneTwister19937 {
sum = this.addition32(sum, this.unsigned32(n2 << i));
}
}

return sum;
}

Expand Down Expand Up @@ -194,10 +195,12 @@ export default class MersenneTwister19937 {
this.mt[0] = this.mt[this.N - 1];
i = 1;
}

if (j >= keyLength) {
j = 0;
}
}

for (k = this.N - 1; k; k--) {
// mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941)) - i
this.mt[i] = this.subtraction32(
Expand All @@ -218,6 +221,7 @@ export default class MersenneTwister19937 {
i = 1;
}
}

this.mt[0] = 0x80000000; // MSB is 1; assuring non-zero initial array
}

Expand Down
140 changes: 140 additions & 0 deletions src/locales/de_CH/person/female_first_name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
export default [
'Alice',
'Andrea',
'Angela',
'Anita',
'Anna',
'Anne',
'Anne-Marie',
'Annemarie',
'Astrid',
'Barbara',
'Beatrice',
'Beatrix',
'Bernadette',
'Bettina',
'Brigitta',
'Brigitte',
'Carmen',
'Caroline',
'Catherine',
'Chantal',
'Charlotte',
'Christa',
'Christiane',
'Christina',
'Christine',
'Claire',
'Claudia',
'Claudine',
'Corinne',
'Cornelia',
'Daniela',
'Danielle',
'Denise',
'Dominique',
'Dora',
'Doris',
'Edith',
'Eliane',
'Elisabeth',
'Elsa',
'Elsbeth',
'Erica',
'Erika',
'Esther',
'Eva',
'Eveline',
'Evelyne',
'Fabienne',
'Florence',
'Françoise',
'Franziska',
'Gabriela',
'Gabrielle',
'Gertrud',
'Gisela',
'Hanna',
'Heidi',
'Helen',
'Helena',
'Helene',
'Hildegard',
'Ingrid',
'Irene',
'Iris',
'Isabelle',
'Jacqueline',
'Janine',
'Jean',
'Johanna',
'Jolanda',
'Josette',
'Josiane',
'Judith',
'Julia',
'Karin',
'Katharina',
'Laura',
'Laurence',
'Liliane',
'Liselotte',
'Lydia',
'Madeleine',
'Maja',
'Manuela',
'Margrit',
'Margrith',
'Maria',
'Marianne',
'Marion',
'Marlène',
'Marlies',
'Marlis',
'Martha',
'Martina',
'Martine',
'Maya',
'Michele',
'Micheline',
'Monica',
'Monika',
'Monique',
'Myriam',
'Nadia',
'Nadja',
'Nathalie',
'Nelly',
'Nicole',
'Paola',
'Patricia',
'Petra',
'Pia',
'Priska',
'Regina',
'Regula',
'Renata',
'Renate',
'Ruth',
'Sabine',
'Sandra',
'Silvia',
'Simone',
'Sonia',
'Sonja',
'Stéphanie',
'Susanna',
'Susanne',
'Suzanne',
'Sylvia',
'Sylvie',
'Therese',
'Toni',
'Ursula',
'Verena',
'Véronique',
'Vreni',
'Yolande',
'Yvette',
'Yvonne',
];
Loading

0 comments on commit 9572c0f

Please sign in to comment.