Skip to content

Commit 568f2f8

Browse files
committed
chore: merge next
2 parents 0aa486a + 86ae8b9 commit 568f2f8

File tree

16 files changed

+352
-65
lines changed

16 files changed

+352
-65
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The API covers the following modules:
103103
| Git | `faker.git.commitMessage()` | feat: add products list page |
104104
| Hacker | `faker.hacker.phrase()` | Try to reboot the SQL bus, maybe it will bypass the virtual application! |
105105
| Helpers | `faker.helpers.arrayElement(['a', 'b', 'c'])` | b |
106-
| Image | `faker.image.cats()` | https://loremflickr.com/640/480/cats <img src="https://loremflickr.com/640/480/cats" height="100"> |
106+
| Image | `faker.image.url()` | https://picsum.photos/id/165/640/480 <img src="https://picsum.photos/id/165/640/480" height="100"> |
107107
| Internet | `faker.internet.domainName()` | muddy-neuropathologist.net |
108108
| Location | `faker.location.city()` | Lake Raoulfort |
109109
| Lorem | `faker.lorem.paragraph()` | Porro nulla id vero perspiciatis nulla nihil. ... |

docs/.vitepress/theme/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ table td ul li {
1313
.nav-bar-title .logo {
1414
min-height: 2rem;
1515
}
16+
17+
.VPHero .action:not(:last-child) a.VPButton.alt {
18+
border-color: var(--vp-button-brand-border) !important;
19+
color: var(--vp-button-brand-border) !important;
20+
}

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ hero:
1212
- theme: brand
1313
text: Get Started
1414
link: /guide/
15+
- theme: alt
16+
text: Browse API
17+
link: /api/
1518
- theme: alt
1619
text: View on GitHub
1720
link: https://github.com/faker-js/faker

scripts/apidoc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolve } from 'path';
2+
import { faker } from '../src';
23
import {
34
writeApiPagesIndex,
45
writeApiSearchIndex,
@@ -13,6 +14,7 @@ const pathOutputJson = resolve(pathOutputDir, 'typedoc.json');
1314

1415
async function build(): Promise<void> {
1516
await initMarkdownRenderer();
17+
faker.setDefaultRefDate(Date.UTC(2023, 0, 1));
1618

1719
const app = newTypeDocApp();
1820

scripts/apidoc/signature.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,29 @@ function typeToText(type_?: Type, short = false): string {
277277

278278
const type = type_ as SomeType;
279279
switch (type.type) {
280-
case 'array':
281-
return `${typeToText(type.elementType, short)}[]`;
280+
case 'array': {
281+
const text = typeToText(type.elementType, short);
282+
if (text.includes('|') || text.includes('{')) {
283+
return `Array<${text}>`;
284+
} else {
285+
return `${text}[]`;
286+
}
287+
}
288+
282289
case 'union':
283290
return type.types
284291
.map((t) => typeToText(t, short))
292+
.map((t) => (t.includes('=>') ? `(${t})` : t))
285293
.sort()
286294
.join(' | ');
295+
287296
case 'reference':
288297
if (!type.typeArguments || !type.typeArguments.length) {
289298
return type.name;
290299
} else if (type.name === 'LiteralUnion') {
291300
return [
292-
typeToText(type.typeArguments[0]),
293-
typeToText(type.typeArguments[1]),
301+
typeToText(type.typeArguments[0], short),
302+
typeToText(type.typeArguments[1], short),
294303
].join(' | ');
295304
} else {
296305
return `${type.name}<${type.typeArguments
@@ -300,13 +309,25 @@ function typeToText(type_?: Type, short = false): string {
300309

301310
case 'reflection':
302311
return declarationTypeToText(type.declaration, short);
312+
303313
case 'indexedAccess':
304314
return `${typeToText(type.objectType, short)}[${typeToText(
305315
type.indexType,
306316
short
307317
)}]`;
318+
308319
case 'literal':
309320
return formatTypescript(type.toString()).replace(/;\n$/, '');
321+
322+
case 'typeOperator': {
323+
const text = typeToText(type.target, short);
324+
if (short && type.operator === 'readonly') {
325+
return text;
326+
} else {
327+
return `${type.operator} ${text}`;
328+
}
329+
}
330+
310331
default:
311332
return type.toString();
312333
}

src/faker.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class Faker {
5454
locales: UsedLocales;
5555
private _locale: UsableLocale;
5656
private _localeFallback: UsableLocale;
57+
private _defaultRefDate: () => Date = () => new Date();
5758

5859
get locale(): UsableLocale {
5960
return this._locale;
@@ -83,6 +84,30 @@ export class Faker {
8384
this._localeFallback = localeFallback;
8485
}
8586

87+
/**
88+
* Gets a new reference date used to generate relative dates.
89+
*/
90+
get defaultRefDate(): () => Date {
91+
return this._defaultRefDate;
92+
}
93+
94+
/**
95+
* Sets the `refDate` source to use if no `refDate` date is passed to the date methods.
96+
*
97+
* @param dateOrSource The function or the static value used to generate the `refDate` date instance.
98+
* The function must return a new valid `Date` instance for every call.
99+
* Defaults to `() => new Date()`.
100+
*/
101+
setDefaultRefDate(
102+
dateOrSource: string | Date | number | (() => Date) = () => new Date()
103+
): void {
104+
if (typeof dateOrSource === 'function') {
105+
this._defaultRefDate = dateOrSource;
106+
} else {
107+
this._defaultRefDate = () => new Date(dateOrSource);
108+
}
109+
}
110+
86111
readonly definitions: LocaleDefinition = this.initDefinitions();
87112

88113
/** @internal */

0 commit comments

Comments
 (0)