Skip to content

Commit

Permalink
Merge branch 'next' into feat/boolean-probability
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Nov 1, 2022
2 parents 5421688 + 4204a6a commit 705ca55
Show file tree
Hide file tree
Showing 32 changed files with 1,074 additions and 411 deletions.
108 changes: 108 additions & 0 deletions docs/.vitepress/components/Banner.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<script setup lang="ts">
import { useElementSize } from '@vueuse/core';
import { ref, watchEffect } from 'vue';
defineProps<{
version: string;
}>();
const el = ref<HTMLElement>();
const { height } = useElementSize(el);
watchEffect(() => {
if (height.value) {
document.documentElement.style.setProperty(
'--vp-layout-top-height',
`${height.value + 16}px`
);
}
});
const dismiss = () => {
localStorage.setItem(
'faker-version-banner',
(Date.now() + 8.64e7 * 1).toString() // current time + 1 day
);
document.documentElement.classList.add('banner-dismissed');
};
</script>

<template>
<div ref="el" class="banner">
<div class="text">
These docs are of {{ version }}. For docs of the current version visit:
<a href="https://fakerjs.dev/">fakerjs.dev</a>
</div>

<button type="button" @click="dismiss">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
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"
/>
</svg>
</button>
</div>
</template>

<style>
.banner-dismissed {
--vp-layout-top-height: 0px !important;
}
html {
--vp-layout-top-height: 88px;
}
@media (min-width: 375px) {
html {
--vp-layout-top-height: 64px;
}
}
@media (min-width: 768px) {
html {
--vp-layout-top-height: 40px;
}
}
</style>

<style scoped>
.banner-dismissed .banner {
display: none;
}
.banner {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: var(--vp-z-index-layout-top);
padding: 8px;
text-align: center;
background: #383636;
color: #fff;
display: flex;
justify-content: space-between;
}
.text {
flex: 1;
}
a {
text-decoration: underline;
}
svg {
width: 20px;
height: 20px;
margin-left: 8px;
}
</style>
7 changes: 7 additions & 0 deletions docs/.vitepress/components/shims.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare const __BANNER__: string | false;

declare module '*.vue' {
import type { DefineComponent } from 'vue';
const component: DefineComponent;
export default component;
}
29 changes: 27 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'vitepress';
import { DefaultTheme } from 'vitepress/theme';
import { apiPages } from './api-pages';
import { currentVersion, oldVersions } from './versions';
import { currentVersion, oldVersions, versionBannerInfix } from './versions';

type SidebarGroup = DefaultTheme.SidebarGroup;

Expand Down Expand Up @@ -51,7 +51,7 @@ function extendSideNav(current: SidebarGroup): SidebarGroup[] {
return links;
}

export default defineConfig({
const config = defineConfig({
title: 'Faker',
description,

Expand Down Expand Up @@ -229,4 +229,29 @@ export default defineConfig({
}),
},
},

vite: {
define: {
__BANNER__: versionBannerInfix ?? false,
},
},
});

if (versionBannerInfix) {
config.head?.push([
'script',
{ id: 'restore-banner-preference' },
`
(() => {
const restore = (key, cls, def = false) => {
const saved = localStorage.getItem(key);
if (saved ? saved !== 'false' && new Date() < saved : def) {
document.documentElement.classList.add(cls);
}
};
restore('faker-version-banner', 'banner-dismissed');
})();`,
]);
}

export default config;
20 changes: 19 additions & 1 deletion docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import DefaultTheme from 'vitepress/theme';
import { defineAsyncComponent, h } from 'vue';
import './index.css';

export default DefaultTheme;
export default {
...DefaultTheme,
Layout() {
return h(
DefaultTheme.Layout,
null,
__BANNER__
? {
'layout-top': () =>
h(
defineAsyncComponent(() => import('../components/Banner.vue')),
{ version: __BANNER__ }
),
}
: null
);
},
};
1 change: 1 addition & 0 deletions docs/.vitepress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "Node",
"resolveJsonModule": true
}
Expand Down
13 changes: 13 additions & 0 deletions docs/.vitepress/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ const hiddenLink =
const otherVersions = readOtherLatestReleaseTagNames();
const isReleaseBranch = /^v\d+$/.test(branchName);

export const versionBannerInfix: string | null = (() => {
if (deployContext === 'production') {
return null;
}
if (isReleaseBranch) {
return '"an old version"';
}
if (branchName === 'next') {
return '"the next (unreleased) version"';
}
return '"a development version"';
})();

export const currentVersion = isReleaseBranch ? `v${version}` : branchName;
export const oldVersions = [
{
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const randomName = faker.person.fullName(); // Rowan Nikolaus
const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
```

Or if you using CommonJS
Or if you're using CommonJS:

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

const randomName = faker.person.findName(); // Willie Bahringer
const randomName = faker.person.fullName(); // Willie Bahringer
const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com
```

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

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

function createRandomUser(): User {
const sex = this.faker.person.sexType();
const sex = faker.person.sexType();
const firstName = faker.person.firstName(sex);
const lastName = faker.person.lastName();
const email = faker.helpers.unique(faker.internet.email, [
Expand Down
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,26 @@
"@algolia/client-search": "~4.14.2",
"@types/glob": "~8.0.0",
"@types/markdown-it": "~12.2.3",
"@types/node": "~18.8.4",
"@types/node": "~18.11.8",
"@types/prettier": "~2.7.1",
"@types/react": "~18.0.21",
"@types/react": "~18.0.24",
"@types/sanitize-html": "~2.6.2",
"@types/semver": "~7.3.12",
"@types/validator": "~13.7.9",
"@typescript-eslint/eslint-plugin": "~5.40.1",
"@typescript-eslint/parser": "~5.40.1",
"@types/semver": "~7.3.13",
"@types/validator": "~13.7.10",
"@typescript-eslint/eslint-plugin": "~5.41.0",
"@typescript-eslint/parser": "~5.41.0",
"@vitest/coverage-c8": "~0.24.3",
"@vitest/ui": "~0.24.3",
"@vueuse/core": "~9.4.0",
"c8": "~7.12.0",
"conventional-changelog-cli": "~2.2.2",
"cypress": "~10.10.0",
"cypress": "~10.11.0",
"esbuild": "~0.15.12",
"eslint": "~8.26.0",
"eslint-config-prettier": "~8.5.0",
"eslint-define-config": "~1.8.0",
"eslint-define-config": "~1.11.0",
"eslint-gitignore": "~0.1.0",
"eslint-plugin-jsdoc": "~39.3.23",
"eslint-plugin-jsdoc": "~39.4.0",
"eslint-plugin-prettier": "~4.2.1",
"glob": "~8.0.3",
"lint-staged": "~13.0.3",
Expand All @@ -127,22 +128,23 @@
"react": "~18.2.0",
"react-dom": "~18.2.0",
"rimraf": "~3.0.2",
"sanitize-html": "~2.7.2",
"sanitize-html": "~2.7.3",
"semver": "~7.3.8",
"simple-git-hooks": "~2.8.1",
"standard-version": "~9.5.0",
"tsx": "~3.11.0",
"typedoc": "~0.23.16",
"typedoc": "~0.23.19",
"typedoc-plugin-missing-exports": "~1.0.0",
"typescript": "~4.8.4",
"validator": "~13.7.0",
"vite": "~3.1.8",
"vitepress": "1.0.0-alpha.21",
"vitest": "~0.24.3"
"vite": "~3.2.1",
"vitepress": "1.0.0-alpha.26",
"vitest": "~0.24.3",
"vue": "~3.2.41"
},
"packageManager": "pnpm@7.14.0",
"packageManager": "pnpm@7.14.1",
"engines": {
"node": ">=14.0.0",
"npm": ">=6.0.0"
"node": "^14.17.0 || ^16.13.0 || >=18.0.0",
"npm": ">=6.14.13"
}
}
Loading

0 comments on commit 705ca55

Please sign in to comment.