Skip to content

Commit

Permalink
Merge branch 'next' into zip-code-anomalies
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Oct 16, 2024
2 parents 8bd0ef8 + 98d1dc0 commit 545e7c2
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 436 deletions.
30 changes: 27 additions & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { DefaultTheme } from 'vitepress/theme';
import { apiPages } from './api-pages';
import {
algoliaIndex,
currentVersion,
version,
versionBannerInfix,
versionLabel,
versionLinks,
} from './versions';

Expand Down Expand Up @@ -149,6 +150,26 @@ const config: UserConfig<DefaultTheme.Config> = {
href: 'https://fosstodon.org/@faker_js',
},
],
[
'script',
{
id: 'browser-console-faker',
},
`
const logStyle = 'background: rgba(16, 183, 127, 0.14); color: rgba(255, 255, 245, 0.86); padding: 0.5rem; display: inline-block;';
console.log(\`%cIf you would like to test Faker in the browser console, you can do so using 'await enableFaker()'.
If you would like to test Faker in a playground, visit https://new.fakerjs.dev.\`, logStyle);
async function enableFaker() {
const imported = await import('https://cdn.jsdelivr.net/npm/@faker-js/faker@${version}/+esm');
Object.assign(globalThis, imported);
console.log(\`%cYou can now start using Faker v${version}:
e.g. 'faker.food.description()' or 'fakerZH_CN.person.firstName()'
For other languages please refer to https://fakerjs.dev/guide/localization.html#available-locales
For a full list of all methods please refer to https://fakerjs.dev/api/\`, logStyle);
return imported;
}
`,
],
],

themeConfig: {
Expand Down Expand Up @@ -197,7 +218,10 @@ const config: UserConfig<DefaultTheme.Config> = {
},
{
text: 'Try it',
items: [{ text: 'StackBlitz ', link: 'https://fakerjs.dev/new' }],
items: [
{ text: 'StackBlitz ', link: 'https://fakerjs.dev/new' },
{ text: 'Browser Console ', link: '/guide/usage.html#browser' },
],
},
{
text: 'About',
Expand All @@ -222,7 +246,7 @@ const config: UserConfig<DefaultTheme.Config> = {
],
},
{
text: currentVersion,
text: versionLabel,
items: [
{
text: 'Release Notes',
Expand Down
24 changes: 22 additions & 2 deletions docs/.vitepress/versions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from 'node:child_process';
import * as semver from 'semver';
import { version } from '../../package.json';
import { version as version_ } from '../../package.json';

function readBranchName(): string {
return (
Expand Down Expand Up @@ -39,6 +39,11 @@ const {
const otherVersions = readOtherLatestReleaseTagNames();
const isReleaseBranch = /^v\d+$/.test(branchName);

/**
* The text of the version banner describing the current version.
*
* This is `null` in production and thus should not be displayed.
*/
export const versionBannerInfix: string | null = (() => {
if (deployContext === 'production') {
return null;
Expand All @@ -55,7 +60,19 @@ export const versionBannerInfix: string | null = (() => {
return '"a development version"';
})();

export const currentVersion = isReleaseBranch ? `v${version}` : branchName;
/**
* The current version of Faker from package.json.
*/
export const version = version_;

/**
* The version label to display in the top-right corner of the site.
*/
export const versionLabel = isReleaseBranch ? `v${version}` : branchName;

/**
* The links to other versions of the documentation.
*/
export const versionLinks = [
{
version: 'next',
Expand All @@ -69,6 +86,9 @@ export const versionLinks = [
// Don't link to the current branch's version.
.filter(({ link }) => link !== `https://${branchName}.fakerjs.dev/`);

/**
* The name of the Algolia index to use for search.
*/
export const algoliaIndex = isReleaseBranch
? `fakerjs-v${semver.major(version)}`
: 'fakerjs-next';
5 changes: 5 additions & 0 deletions docs/guide/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ For more information on selecting and customizing a locale, please refer to our

If you want to try it yourself, you can open your browser console via `Ctrl + Shift + J` / `F12`.

On our website, you can load faker into the browser console

- by using `await enableFaker()`
- or using the following code:

```js
const { faker } = await import('https://esm.sh/@faker-js/faker');

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"@vitest/eslint-plugin": "1.1.7",
"@vitest/ui": "2.1.2",
"@vueuse/core": "11.1.0",
"commit-and-tag-version": "12.4.4",
"commit-and-tag-version": "12.5.0",
"cypress": "13.15.0",
"eslint": "9.12.0",
"eslint-config-prettier": "9.1.0",
Expand All @@ -134,13 +134,13 @@
"ts-morph": "24.0.0",
"tsup": "8.3.0",
"tsx": "4.19.1",
"typescript": "5.6.2",
"typescript": "5.6.3",
"typescript-eslint": "8.8.1",
"validator": "13.12.0",
"vite": "5.4.8",
"vitepress": "1.4.0",
"vitest": "2.1.2",
"vue": "3.5.11",
"vue": "3.5.12",
"vue-tsc": "2.1.6"
},
"packageManager": "pnpm@9.12.1",
Expand Down
Loading

0 comments on commit 545e7c2

Please sign in to comment.