Skip to content

Commit

Permalink
chore: merge next
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Jan 26, 2023
2 parents 0aa486a + 86ae8b9 commit 568f2f8
Show file tree
Hide file tree
Showing 16 changed files with 352 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ The API covers the following modules:
| Git | `faker.git.commitMessage()` | feat: add products list page |
| Hacker | `faker.hacker.phrase()` | Try to reboot the SQL bus, maybe it will bypass the virtual application! |
| Helpers | `faker.helpers.arrayElement(['a', 'b', 'c'])` | b |
| Image | `faker.image.cats()` | https://loremflickr.com/640/480/cats <img src="https://loremflickr.com/640/480/cats" height="100"> |
| Image | `faker.image.url()` | https://picsum.photos/id/165/640/480 <img src="https://picsum.photos/id/165/640/480" height="100"> |
| Internet | `faker.internet.domainName()` | muddy-neuropathologist.net |
| Location | `faker.location.city()` | Lake Raoulfort |
| Lorem | `faker.lorem.paragraph()` | Porro nulla id vero perspiciatis nulla nihil. ... |
Expand Down
5 changes: 5 additions & 0 deletions docs/.vitepress/theme/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ table td ul li {
.nav-bar-title .logo {
min-height: 2rem;
}

.VPHero .action:not(:last-child) a.VPButton.alt {
border-color: var(--vp-button-brand-border) !important;
color: var(--vp-button-brand-border) !important;
}
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ hero:
- theme: brand
text: Get Started
link: /guide/
- theme: alt
text: Browse API
link: /api/
- theme: alt
text: View on GitHub
link: https://github.com/faker-js/faker
Expand Down
2 changes: 2 additions & 0 deletions scripts/apidoc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from 'path';
import { faker } from '../src';
import {
writeApiPagesIndex,
writeApiSearchIndex,
Expand All @@ -13,6 +14,7 @@ const pathOutputJson = resolve(pathOutputDir, 'typedoc.json');

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

const app = newTypeDocApp();

Expand Down
29 changes: 25 additions & 4 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,29 @@ function typeToText(type_?: Type, short = false): string {

const type = type_ as SomeType;
switch (type.type) {
case 'array':
return `${typeToText(type.elementType, short)}[]`;
case 'array': {
const text = typeToText(type.elementType, short);
if (text.includes('|') || text.includes('{')) {
return `Array<${text}>`;
} else {
return `${text}[]`;
}
}

case 'union':
return type.types
.map((t) => typeToText(t, short))
.map((t) => (t.includes('=>') ? `(${t})` : t))
.sort()
.join(' | ');

case 'reference':
if (!type.typeArguments || !type.typeArguments.length) {
return type.name;
} else if (type.name === 'LiteralUnion') {
return [
typeToText(type.typeArguments[0]),
typeToText(type.typeArguments[1]),
typeToText(type.typeArguments[0], short),
typeToText(type.typeArguments[1], short),
].join(' | ');
} else {
return `${type.name}<${type.typeArguments
Expand All @@ -300,13 +309,25 @@ function typeToText(type_?: Type, short = false): string {

case 'reflection':
return declarationTypeToText(type.declaration, short);

case 'indexedAccess':
return `${typeToText(type.objectType, short)}[${typeToText(
type.indexType,
short
)}]`;

case 'literal':
return formatTypescript(type.toString()).replace(/;\n$/, '');

case 'typeOperator': {
const text = typeToText(type.target, short);
if (short && type.operator === 'readonly') {
return text;
} else {
return `${type.operator} ${text}`;
}
}

default:
return type.toString();
}
Expand Down
25 changes: 25 additions & 0 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class Faker {
locales: UsedLocales;
private _locale: UsableLocale;
private _localeFallback: UsableLocale;
private _defaultRefDate: () => Date = () => new Date();

get locale(): UsableLocale {
return this._locale;
Expand Down Expand Up @@ -83,6 +84,30 @@ export class Faker {
this._localeFallback = localeFallback;
}

/**
* Gets a new reference date used to generate relative dates.
*/
get defaultRefDate(): () => Date {
return this._defaultRefDate;
}

/**
* Sets the `refDate` source to use if no `refDate` date is passed to the date methods.
*
* @param dateOrSource The function or the static value used to generate the `refDate` date instance.
* The function must return a new valid `Date` instance for every call.
* Defaults to `() => new Date()`.
*/
setDefaultRefDate(
dateOrSource: string | Date | number | (() => Date) = () => new Date()
): void {
if (typeof dateOrSource === 'function') {
this._defaultRefDate = dateOrSource;
} else {
this._defaultRefDate = () => new Date(dateOrSource);
}
}

readonly definitions: LocaleDefinition = this.initDefinitions();

/** @internal */
Expand Down
Loading

0 comments on commit 568f2f8

Please sign in to comment.