Skip to content

Commit 705ca55

Browse files
authored
Merge branch 'next' into feat/boolean-probability
2 parents 5421688 + 4204a6a commit 705ca55

32 files changed

Lines changed: 1074 additions & 411 deletions
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<script setup lang="ts">
2+
import { useElementSize } from '@vueuse/core';
3+
import { ref, watchEffect } from 'vue';
4+
5+
defineProps<{
6+
version: string;
7+
}>();
8+
9+
const el = ref<HTMLElement>();
10+
const { height } = useElementSize(el);
11+
12+
watchEffect(() => {
13+
if (height.value) {
14+
document.documentElement.style.setProperty(
15+
'--vp-layout-top-height',
16+
`${height.value + 16}px`
17+
);
18+
}
19+
});
20+
21+
const dismiss = () => {
22+
localStorage.setItem(
23+
'faker-version-banner',
24+
(Date.now() + 8.64e7 * 1).toString() // current time + 1 day
25+
);
26+
document.documentElement.classList.add('banner-dismissed');
27+
};
28+
</script>
29+
30+
<template>
31+
<div ref="el" class="banner">
32+
<div class="text">
33+
These docs are of {{ version }}. For docs of the current version visit:
34+
<a href="https://fakerjs.dev/">fakerjs.dev</a>
35+
</div>
36+
37+
<button type="button" @click="dismiss">
38+
<svg
39+
xmlns="http://www.w3.org/2000/svg"
40+
viewBox="0 0 20 20"
41+
fill="currentColor"
42+
>
43+
<path
44+
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
45+
/>
46+
</svg>
47+
</button>
48+
</div>
49+
</template>
50+
51+
<style>
52+
.banner-dismissed {
53+
--vp-layout-top-height: 0px !important;
54+
}
55+
56+
html {
57+
--vp-layout-top-height: 88px;
58+
}
59+
60+
@media (min-width: 375px) {
61+
html {
62+
--vp-layout-top-height: 64px;
63+
}
64+
}
65+
66+
@media (min-width: 768px) {
67+
html {
68+
--vp-layout-top-height: 40px;
69+
}
70+
}
71+
</style>
72+
73+
<style scoped>
74+
.banner-dismissed .banner {
75+
display: none;
76+
}
77+
78+
.banner {
79+
position: fixed;
80+
top: 0;
81+
right: 0;
82+
left: 0;
83+
z-index: var(--vp-z-index-layout-top);
84+
85+
padding: 8px;
86+
text-align: center;
87+
88+
background: #383636;
89+
color: #fff;
90+
91+
display: flex;
92+
justify-content: space-between;
93+
}
94+
95+
.text {
96+
flex: 1;
97+
}
98+
99+
a {
100+
text-decoration: underline;
101+
}
102+
103+
svg {
104+
width: 20px;
105+
height: 20px;
106+
margin-left: 8px;
107+
}
108+
</style>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare const __BANNER__: string | false;
2+
3+
declare module '*.vue' {
4+
import type { DefineComponent } from 'vue';
5+
const component: DefineComponent;
6+
export default component;
7+
}

docs/.vitepress/config.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig } from 'vitepress';
22
import { DefaultTheme } from 'vitepress/theme';
33
import { apiPages } from './api-pages';
4-
import { currentVersion, oldVersions } from './versions';
4+
import { currentVersion, oldVersions, versionBannerInfix } from './versions';
55

66
type SidebarGroup = DefaultTheme.SidebarGroup;
77

@@ -51,7 +51,7 @@ function extendSideNav(current: SidebarGroup): SidebarGroup[] {
5151
return links;
5252
}
5353

54-
export default defineConfig({
54+
const config = defineConfig({
5555
title: 'Faker',
5656
description,
5757

@@ -229,4 +229,29 @@ export default defineConfig({
229229
}),
230230
},
231231
},
232+
233+
vite: {
234+
define: {
235+
__BANNER__: versionBannerInfix ?? false,
236+
},
237+
},
232238
});
239+
240+
if (versionBannerInfix) {
241+
config.head?.push([
242+
'script',
243+
{ id: 'restore-banner-preference' },
244+
`
245+
(() => {
246+
const restore = (key, cls, def = false) => {
247+
const saved = localStorage.getItem(key);
248+
if (saved ? saved !== 'false' && new Date() < saved : def) {
249+
document.documentElement.classList.add(cls);
250+
}
251+
};
252+
restore('faker-version-banner', 'banner-dismissed');
253+
})();`,
254+
]);
255+
}
256+
257+
export default config;

docs/.vitepress/theme/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
import DefaultTheme from 'vitepress/theme';
2+
import { defineAsyncComponent, h } from 'vue';
23
import './index.css';
34

4-
export default DefaultTheme;
5+
export default {
6+
...DefaultTheme,
7+
Layout() {
8+
return h(
9+
DefaultTheme.Layout,
10+
null,
11+
__BANNER__
12+
? {
13+
'layout-top': () =>
14+
h(
15+
defineAsyncComponent(() => import('../components/Banner.vue')),
16+
{ version: __BANNER__ }
17+
),
18+
}
19+
: null
20+
);
21+
},
22+
};

docs/.vitepress/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "ES2020",
4+
"module": "ES2020",
45
"moduleResolution": "Node",
56
"resolveJsonModule": true
67
}

docs/.vitepress/versions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ const hiddenLink =
4141
const otherVersions = readOtherLatestReleaseTagNames();
4242
const isReleaseBranch = /^v\d+$/.test(branchName);
4343

44+
export const versionBannerInfix: string | null = (() => {
45+
if (deployContext === 'production') {
46+
return null;
47+
}
48+
if (isReleaseBranch) {
49+
return '"an old version"';
50+
}
51+
if (branchName === 'next') {
52+
return '"the next (unreleased) version"';
53+
}
54+
return '"a development version"';
55+
})();
56+
4457
export const currentVersion = isReleaseBranch ? `v${version}` : branchName;
4558
export const oldVersions = [
4659
{

docs/guide/usage.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const randomName = faker.person.fullName(); // Rowan Nikolaus
1111
const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
1212
```
1313

14-
Or if you using CommonJS
14+
Or if you're using CommonJS:
1515

1616
```js
1717
const { faker } = require('@faker-js/faker');
@@ -43,7 +43,7 @@ Using the browser is great for experimenting 👍. However, due to all of the st
4343
```js
4444
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
4545

46-
const randomName = faker.person.findName(); // Willie Bahringer
46+
const randomName = faker.person.fullName(); // Willie Bahringer
4747
const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com
4848
```
4949

@@ -142,7 +142,7 @@ Let's refactor our current code:
142142
import { faker } from '@faker-js/faker';
143143

144144
function createRandomUser(): User {
145-
const sex = this.faker.person.sexType();
145+
const sex = faker.person.sexType();
146146
const firstName = faker.person.firstName(sex);
147147
const lastName = faker.person.lastName();
148148
const email = faker.internet.email(firstName, lastName);
@@ -179,7 +179,7 @@ Faker has your back, with another helper method:
179179
import { faker } from '@faker-js/faker';
180180

181181
function createRandomUser(): User {
182-
const sex = this.faker.person.sexType();
182+
const sex = faker.person.sexType();
183183
const firstName = faker.person.firstName(sex);
184184
const lastName = faker.person.lastName();
185185
const email = faker.helpers.unique(faker.internet.email, [

package.json

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,26 @@
9797
"@algolia/client-search": "~4.14.2",
9898
"@types/glob": "~8.0.0",
9999
"@types/markdown-it": "~12.2.3",
100-
"@types/node": "~18.8.4",
100+
"@types/node": "~18.11.8",
101101
"@types/prettier": "~2.7.1",
102-
"@types/react": "~18.0.21",
102+
"@types/react": "~18.0.24",
103103
"@types/sanitize-html": "~2.6.2",
104-
"@types/semver": "~7.3.12",
105-
"@types/validator": "~13.7.9",
106-
"@typescript-eslint/eslint-plugin": "~5.40.1",
107-
"@typescript-eslint/parser": "~5.40.1",
104+
"@types/semver": "~7.3.13",
105+
"@types/validator": "~13.7.10",
106+
"@typescript-eslint/eslint-plugin": "~5.41.0",
107+
"@typescript-eslint/parser": "~5.41.0",
108108
"@vitest/coverage-c8": "~0.24.3",
109109
"@vitest/ui": "~0.24.3",
110+
"@vueuse/core": "~9.4.0",
110111
"c8": "~7.12.0",
111112
"conventional-changelog-cli": "~2.2.2",
112-
"cypress": "~10.10.0",
113+
"cypress": "~10.11.0",
113114
"esbuild": "~0.15.12",
114115
"eslint": "~8.26.0",
115116
"eslint-config-prettier": "~8.5.0",
116-
"eslint-define-config": "~1.8.0",
117+
"eslint-define-config": "~1.11.0",
117118
"eslint-gitignore": "~0.1.0",
118-
"eslint-plugin-jsdoc": "~39.3.23",
119+
"eslint-plugin-jsdoc": "~39.4.0",
119120
"eslint-plugin-prettier": "~4.2.1",
120121
"glob": "~8.0.3",
121122
"lint-staged": "~13.0.3",
@@ -127,22 +128,23 @@
127128
"react": "~18.2.0",
128129
"react-dom": "~18.2.0",
129130
"rimraf": "~3.0.2",
130-
"sanitize-html": "~2.7.2",
131+
"sanitize-html": "~2.7.3",
131132
"semver": "~7.3.8",
132133
"simple-git-hooks": "~2.8.1",
133134
"standard-version": "~9.5.0",
134135
"tsx": "~3.11.0",
135-
"typedoc": "~0.23.16",
136+
"typedoc": "~0.23.19",
136137
"typedoc-plugin-missing-exports": "~1.0.0",
137138
"typescript": "~4.8.4",
138139
"validator": "~13.7.0",
139-
"vite": "~3.1.8",
140-
"vitepress": "1.0.0-alpha.21",
141-
"vitest": "~0.24.3"
140+
"vite": "~3.2.1",
141+
"vitepress": "1.0.0-alpha.26",
142+
"vitest": "~0.24.3",
143+
"vue": "~3.2.41"
142144
},
143-
"packageManager": "pnpm@7.14.0",
145+
"packageManager": "pnpm@7.14.1",
144146
"engines": {
145-
"node": ">=14.0.0",
146-
"npm": ">=6.0.0"
147+
"node": "^14.17.0 || ^16.13.0 || >=18.0.0",
148+
"npm": ">=6.14.13"
147149
}
148150
}

0 commit comments

Comments
 (0)