Skip to content

Commit

Permalink
Merge branch 'next' into varied-product-descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Oct 16, 2024
2 parents 1887ed1 + 6a9ca8a commit 73ee1e2
Show file tree
Hide file tree
Showing 27 changed files with 744 additions and 469 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const { faker } = require('@faker-js/faker');
export function createRandomUser() {
return {
userId: faker.string.uuid(),
username: faker.internet.userName(),
username: faker.internet.username(), // before version 9.1.0, use userName()
email: faker.internet.email(),
avatar: faker.image.avatar(),
password: faker.internet.password(),
Expand Down
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';
7 changes: 6 additions & 1 deletion docs/api/ApiIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ const filtered = computed(() => {
</h3>
<ul>
<li v-for="h of item.headers" :key="h.anchor">
<!-- TODO @ST-DDT 2024-09-25: Remove this in v10 -->
<a
:href="item.link + '#' + slugify(h.anchor)"
:href="
item.link +
'#' +
(h.anchor === 'userName' ? 'username-1' : slugify(h.anchor))
"
:class="{ deprecated: h.deprecated }"
>{{ h.text }}</a
>
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import { faker } from '@faker-js/faker/locale/en';

describe('Testing the application', () => {
it('should create an account with username and password', () => {
let username = faker.internet.userName();
let username = faker.internet.username(); // before version 9.1.0, use userName()
let password = faker.internet.password();
let email = faker.internet.exampleEmail();

Expand Down Expand Up @@ -111,7 +111,7 @@ test.describe('Testing the application', () => {
test('should create an account with username and password', async ({
page,
}) => {
const username = faker.internet.userName();
const username = faker.internet.username(); // before version 9.1.0, use userName()
const password = faker.internet.password();
const email = faker.internet.exampleEmail();

Expand Down
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
1 change: 0 additions & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ const config: ReturnType<typeof tseslint.config> = tseslint.config(

// TODO @Shinigami92 2023-09-23: The following rules currently conflict with our code.
// Each rule should be checked whether it should be enabled/configured and the problems fixed, or stay disabled permanently.
'unicorn/better-regex': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/no-object-as-default-parameter': 'off',
'unicorn/prefer-export-from': 'off',
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@
"@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",
"eslint-plugin-jsdoc": "50.3.1",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-unicorn": "55.0.0",
"eslint-plugin-unicorn": "56.0.0",
"jiti": "1.21.6",
"npm-run-all2": "6.2.3",
"prettier": "3.3.3",
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": "[email protected]",
Expand Down
Loading

0 comments on commit 73ee1e2

Please sign in to comment.