Skip to content

Commit

Permalink
Merge branch 'next' into chore/more-states-za
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Mar 30, 2023
2 parents c3b39ea + b5bfca4 commit 1d9a824
Show file tree
Hide file tree
Showing 135 changed files with 827 additions and 310 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
12 changes: 7 additions & 5 deletions docs/api/ApiIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ onUnmounted(() => window.removeEventListener('keydown', apiSearchFocusHandler));
<h2 :id="slugify(section.text)">{{ section.text }}</h2>
<div class="api-groups">
<div v-for="item of section.items" :key="item.text" class="api-group">
<h3>{{ item.text }}</h3>
<h3>
<a :href="item.link + '.html'">{{ item.text }}</a>
</h3>
<ul>
<li v-for="h of item.headers" :key="h.anchor">
<a :href="item.link + '.html#' + slugify(h.anchor)">{{
Expand Down Expand Up @@ -158,19 +160,19 @@ h3 {
margin-bottom: 64px;
}

.api-groups a {
.api-groups ul a {
font-size: 15px;
font-weight: 500;
line-height: 2;
color: var(--vp-c-text-code);
transition: color 0.5s;
}

.dark .api-groups a {
.dark .api-groups ul a {
font-weight: 400;
}

.api-groups a:hover {
.api-groups ul a:hover {
color: var(--vp-c-green);
transition: none;
}
Expand Down Expand Up @@ -233,7 +235,7 @@ h3 {
padding-top: 32px;
}

.api-groups a {
.api-groups ul a {
font-size: 14px;
}

Expand Down
13 changes: 11 additions & 2 deletions docs/guide/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ If our built-in faker instances don't satisfy your needs, you can build your own

```ts
import type { LocaleDefinition } from '@faker-js/faker';
import { Faker, de_CH, de, en } from '@faker-js/faker';
import { Faker, de_CH, de, en, base } from '@faker-js/faker';

const customLocale: LocaleDefinition = {
title: 'My custom locale',
Expand All @@ -54,10 +54,18 @@ const customLocale: LocaleDefinition = {
};

export const customFaker = new Faker({
locale: [customLocale, de_CH, de, en, global],
locale: [customLocale, de_CH, de, en, base],
});
```

In this example there are 5 locales. Each of these is checked in order, and the first locale which contains the requested data will be used:

- `customLocale` is your custom locale definition which will override all other fallback definitions.
- `de_CH` is a specific locale definition that overrides some German definitions with `CH` (Switzerland) data.
- `de` is a generic `de` (German) locale definition.
- `en` is a generic `en` (English) locale definition. This is our most complete locale, so we add it to fill some gaps. Depending on your needs, you might want or not want to have it as a fallback.
- `base` is the base locale definition which contains definitions that can be used in every language (e.g. emojis).

## Available locales

<!-- LOCALES-AUTO-GENERATED-START -->
Expand All @@ -69,6 +77,7 @@ export const customFaker = new Faker({
| `af_ZA` | Afrikaans | `fakerAF_ZA` |
| `ar` | Arabic | `fakerAR` |
| `az` | Azerbaijani | `fakerAZ` |
| `base` | Base | `fakerBASE` |
| `cz` | Czech | `fakerCZ` |
| `de` | German | `fakerDE` |
| `de_AT` | German (Austria) | `fakerDE_AT` |
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ const b = customFaker.internet.emoji();
**New**

```ts
import { Faker, de_CH, de, en, global } from '@faker-js/faker';
import { Faker, de_CH, de, en, base } from '@faker-js/faker';

// same as fakerDE_CH
export const customFaker = new Faker({
// Now multiple fallbacks are supported
locale: [de_CH, de, en, global],
locale: [de_CH, de, en, base],
});
const a = customFaker.internet.email();
const b = customFaker.internet.emoji();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"glob": "~9.3.2",
"npm-run-all": "~4.1.5",
"picocolors": "~1.0.0",
"prettier": "2.8.4",
"prettier": "2.8.7",
"prettier-plugin-organize-imports": "~3.2.2",
"react": "~18.2.0",
"react-dom": "~18.2.0",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/apidoc/moduleMethods.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DeclarationReflection, ProjectReflection } from 'typedoc';
import type { Method } from '../../docs/.vitepress/components/api-docs/method';
import { writeApiDocsData, writeApiDocsModulePage } from './apiDocsWriter';
import { analyzeSignature, toBlock } from './signature';
import { analyzeSignature, stripAbsoluteFakerUrls, toBlock } from './signature';
import {
extractModuleFieldName,
extractModuleName,
Expand Down Expand Up @@ -40,7 +40,7 @@ function processModuleMethod(module: DeclarationReflection): PageAndDiffIndex {
const moduleName = extractModuleName(module);
const moduleFieldName = extractModuleFieldName(module);
console.log(`Processing Module ${moduleName}`);
const comment = toBlock(module.comment);
const comment = stripAbsoluteFakerUrls(toBlock(module.comment));

const methods: Method[] = [];

Expand Down
20 changes: 18 additions & 2 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ function prettifyMethodName(method: string): string {
);
}

export const MISSING_DESCRIPTION = 'Missing';

export function toBlock(comment?: Comment): string {
return joinTagParts(comment?.summary) || 'Missing';
return joinTagParts(comment?.summary) || MISSING_DESCRIPTION;
}

export function stripAbsoluteFakerUrls(markdown: string): string {
return markdown.replace(/https:\/\/(next.)?fakerjs.dev\//g, '/');
}

let markdown: MarkdownRenderer;
Expand Down Expand Up @@ -304,7 +310,17 @@ function typeToText(type_?: Type, short = false): string {

case 'reference':
if (!type.typeArguments || !type.typeArguments.length) {
return type.name;
const reflection = type.reflection as DeclarationReflection | undefined;
const reflectionType = reflection?.type;
if (
(reflectionType?.type === 'literal' ||
reflectionType?.type === 'union') &&
!type.name.match(/Char$/)
) {
return typeToText(reflectionType, short);
} else {
return type.name;
}
} else if (type.name === 'LiteralUnion') {
return [
typeToText(type.typeArguments[0], short),
Expand Down
20 changes: 14 additions & 6 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ function generateLocaleFile(locale: string): void {
}
}

if (locales[locales.length - 1] !== 'en') {
// TODO christopher 2023-03-07: Remove 'en' fallback in a separate PR
if (locales[locales.length - 1] !== 'en' && locale !== 'base') {
locales.push('en');
}

if (locales[locales.length - 1] !== 'base') {
locales.push('base');
}

let content = `
${autoGeneratedCommentHeader}
Expand All @@ -148,8 +153,10 @@ function generateLocaleFile(locale: string): void {
writeFileSync(resolve(pathLocale, `${locale}.ts`), content);
}

function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
let localeDef: LocaleDefinition;
function tryLoadLocalesMainIndexFile(
pathModules: string
): LocaleDefinition | undefined {
let localeDef: LocaleDefinition | undefined;
// This call might fail, if the module setup is broken.
// Unfortunately, we try to fix it with this script
// Thats why have a fallback logic here, we only need the title anyway
Expand All @@ -165,9 +172,10 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
resolve(pathModules, 'index.ts'),
'utf-8'
);
localeDef = {
title: localeIndex.match(/title: '(.*)',/)[1],
};
const title = localeIndex.match(/title: '(.*)',/)?.[1];
if (title) {
localeDef = { title };
}
} catch {
console.error(`Failed to load ${pathModules} or manually parse it.`, e);
}
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ export type LocationDefinitions = LocaleEntry<{
country_code: Array<{ alpha2: string; alpha3: string }>;

/**
* The names of this country's states.
* The names of this country's states, or other first-level administrative areas.
*/
state: string[];

/**
* The abbreviated names of this country's states.
* The abbreviated names of this country's states, or other first-level administrative areas.
*/
state_abbr: string[];

/**
* The names of counties inside the country or state.
* The names of counties, or other second-level administrative areas, inside the country's states.
*/
county: string[];

Expand Down
3 changes: 2 additions & 1 deletion src/locale/af_ZA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import { Faker } from '../faker';
import af_ZA from '../locales/af_ZA';
import base from '../locales/base';
import en from '../locales/en';

export const faker = new Faker({
locale: [af_ZA, en],
locale: [af_ZA, en, base],
});
3 changes: 2 additions & 1 deletion src/locale/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import { Faker } from '../faker';
import ar from '../locales/ar';
import base from '../locales/base';
import en from '../locales/en';

export const faker = new Faker({
locale: [ar, en],
locale: [ar, en, base],
});
3 changes: 2 additions & 1 deletion src/locale/az.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import { Faker } from '../faker';
import az from '../locales/az';
import base from '../locales/base';
import en from '../locales/en';

export const faker = new Faker({
locale: [az, en],
locale: [az, en, base],
});
11 changes: 11 additions & 0 deletions src/locale/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/

import { Faker } from '../faker';
import base from '../locales/base';

export const faker = new Faker({
locale: base,
});
3 changes: 2 additions & 1 deletion src/locale/cz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/

import { Faker } from '../faker';
import base from '../locales/base';
import cz from '../locales/cz';
import en from '../locales/en';

export const faker = new Faker({
locale: [cz, en],
locale: [cz, en, base],
});
3 changes: 2 additions & 1 deletion src/locale/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/

import { Faker } from '../faker';
import base from '../locales/base';
import de from '../locales/de';
import en from '../locales/en';

export const faker = new Faker({
locale: [de, en],
locale: [de, en, base],
});
3 changes: 2 additions & 1 deletion src/locale/de_AT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/

import { Faker } from '../faker';
import base from '../locales/base';
import de from '../locales/de';
import de_AT from '../locales/de_AT';
import en from '../locales/en';

export const faker = new Faker({
locale: [de_AT, de, en],
locale: [de_AT, de, en, base],
});
3 changes: 2 additions & 1 deletion src/locale/de_CH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/

import { Faker } from '../faker';
import base from '../locales/base';
import de from '../locales/de';
import de_CH from '../locales/de_CH';
import en from '../locales/en';

export const faker = new Faker({
locale: [de_CH, de, en],
locale: [de_CH, de, en, base],
});
Loading

0 comments on commit 1d9a824

Please sign in to comment.