From dd327e9239aeba9cd95dd6a35e8e895d3c1451ec Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 10 Sep 2022 15:05:24 +0200 Subject: [PATCH 01/14] docs(website): add `usage` page to `guide` --- docs/.vitepress/config.ts | 4 ++++ docs/guide/usage.md | 0 2 files changed, 4 insertions(+) create mode 100644 docs/guide/usage.md diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index aad3bdf2ace..ef274b9df31 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -130,6 +130,10 @@ export default defineConfig({ text: 'Getting Started', link: '/guide/', }, + { + text: 'Usage', + link: '/guide/usage', + }, { text: 'Localization', link: '/guide/localization', diff --git a/docs/guide/usage.md b/docs/guide/usage.md new file mode 100644 index 00000000000..e69de29bb2d From 9bf9bf55487480c80816fa5c2f9ef33efc2809dd Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 10 Sep 2022 15:07:35 +0200 Subject: [PATCH 02/14] docs(website): move usage section into own page --- docs/guide/index.md | 88 --------------------------------------------- docs/guide/usage.md | 87 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 88 deletions(-) diff --git a/docs/guide/index.md b/docs/guide/index.md index bd39ec2c3cb..cfee521dc27 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -37,94 +37,6 @@ or pnpm add @faker-js/faker --save-dev ``` -## Usage - -### Node.js - -```js -import { faker } from '@faker-js/faker'; -// or, if using CommonJS -// const { faker } = require('@faker-js/faker'); - -const randomName = faker.name.fullName(); // Rowan Nikolaus -const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz -``` - -### Browser - -```html - - -``` - -:::tip Note -Using the browser is great for experimenting 👍. However, due to all of the strings Faker uses to generate fake data, **Faker is a large package**. It's `> 5 MiB` minified. **Please avoid deploying the full Faker in your web app.** -::: - -### CDN/Deno - -```js -import { faker } from 'https://cdn.skypack.dev/@faker-js/faker'; - -const randomName = faker.name.findName(); // Willie Bahringer -const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com -``` - -:::tip Note -It is highly recommended to use version tags when importing libraries in Deno, e.g: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0"`. Add `?dts` to import with type definitions: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0?dts"`. -::: - -#### Alternative CDN links - -**esm:** - -- https://esm.sh/@faker-js/faker -- https://cdn.jsdelivr.net/npm/@faker-js/faker/+esm - -**cjs:** - -- https://cdn.jsdelivr.net/npm/@faker-js/faker - -### TypeScript Support - -Since version `v6+` there is native TypeScript support. - -In order to have faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: - -```json -{ - "compilerOptions": { - "esModuleInterop": true, - "moduleResolution": "Node" - } -} -``` - -And then simply import it like everything else: - -```ts -import { faker } from '@faker-js/faker'; -``` - -If you want for whatever reason the versions prior to `v6`, -you can use `@types/faker` and rebind the declarations to the `@faker-js/faker` package with a `faker.d.ts` file in your e.g. src folder. - -```ts -// faker.d.ts -declare module '@faker-js/faker' { - import faker from 'faker'; - export default faker; -} -``` - ## Community If you have questions or need help, reach out to the community via [Discord](https://chat.fakerjs.dev) and [GitHub Discussions](https://github.com/faker-js/faker/discussions). diff --git a/docs/guide/usage.md b/docs/guide/usage.md index e69de29bb2d..67907e5c060 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -0,0 +1,87 @@ +# Usage + +## Node.js + +```js +import { faker } from '@faker-js/faker'; +// or, if using CommonJS +// const { faker } = require('@faker-js/faker'); + +const randomName = faker.name.fullName(); // Rowan Nikolaus +const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz +``` + +## Browser + +```html + + +``` + +:::tip Note +Using the browser is great for experimenting 👍. However, due to all of the strings Faker uses to generate fake data, **Faker is a large package**. It's `> 5 MiB` minified. **Please avoid deploying the full Faker in your web app.** +::: + +## CDN/Deno + +```js +import { faker } from 'https://cdn.skypack.dev/@faker-js/faker'; + +const randomName = faker.name.findName(); // Willie Bahringer +const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com +``` + +:::tip Note +It is highly recommended to use version tags when importing libraries in Deno, e.g: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0"`. Add `?dts` to import with type definitions: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0?dts"`. +::: + +### Alternative CDN links + +**esm:** + +- https://esm.sh/@faker-js/faker +- https://cdn.jsdelivr.net/npm/@faker-js/faker/+esm + +**cjs:** + +- https://cdn.jsdelivr.net/npm/@faker-js/faker + +## TypeScript Support + +Since version `v6+` there is native TypeScript support. + +In order to have faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: + +```json +{ + "compilerOptions": { + "esModuleInterop": true, + "moduleResolution": "Node" + } +} +``` + +And then simply import it like everything else: + +```ts +import { faker } from '@faker-js/faker'; +``` + +If you want for whatever reason the versions prior to `v6`, +you can use `@types/faker` and rebind the declarations to the `@faker-js/faker` package with a `faker.d.ts` file in your e.g. src folder. + +```ts +// faker.d.ts +declare module '@faker-js/faker' { + import faker from 'faker'; + export default faker; +} +``` From 43b7acee6842028fea6de4a0c7ec2b635e9bae17 Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 10 Sep 2022 15:43:14 +0200 Subject: [PATCH 03/14] docs(website): update typescript section in usage page --- docs/guide/usage.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index 67907e5c060..131b586621e 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -56,7 +56,7 @@ It is highly recommended to use version tags when importing libraries in Deno, e ## TypeScript Support -Since version `v6+` there is native TypeScript support. +Faker has native TypeScript support, out of the box. So you don't have to install any extra packages. In order to have faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: @@ -74,14 +74,3 @@ And then simply import it like everything else: ```ts import { faker } from '@faker-js/faker'; ``` - -If you want for whatever reason the versions prior to `v6`, -you can use `@types/faker` and rebind the declarations to the `@faker-js/faker` package with a `faker.d.ts` file in your e.g. src folder. - -```ts -// faker.d.ts -declare module '@faker-js/faker' { - import faker from 'faker'; - export default faker; -} -``` From d2768b6cdc0b46f11c4a0fa5845999edab99d5ef Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 10 Sep 2022 15:43:43 +0200 Subject: [PATCH 04/14] docs(website): update nodejs section in usage page --- docs/guide/usage.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index 131b586621e..5f36640d3d9 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -2,10 +2,19 @@ ## Node.js +Using Faker is as easy as importing it from `@faker-js/faker`. + ```js import { faker } from '@faker-js/faker'; -// or, if using CommonJS -// const { faker } = require('@faker-js/faker'); + +const randomName = faker.name.fullName(); // Rowan Nikolaus +const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz +``` + +Or if you using CommonJS + +```js +const { faker } = require('@faker-js/faker'); const randomName = faker.name.fullName(); // Rowan Nikolaus const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz From b6b3b275d3509d4440267b49bcb1f3937e4235a7 Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 10 Sep 2022 16:08:31 +0200 Subject: [PATCH 05/14] docs(website): usage remove comment for script type --- docs/guide/usage.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index 5f36640d3d9..f63c614eafa 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -23,7 +23,6 @@ const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz ## Browser ```html - -``` - -:::tip Note -Using the browser is great for experimenting 👍. However, due to all of the strings Faker uses to generate fake data, **Faker is a large package**. It's `> 5 MiB` minified. **Please avoid deploying the full Faker in your web app.** -::: - -## CDN/Deno - -```js -import { faker } from 'https://cdn.skypack.dev/@faker-js/faker'; - -const randomName = faker.name.findName(); // Willie Bahringer -const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com -``` - -:::tip Note -It is highly recommended to use version tags when importing libraries in Deno, e.g: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0"`. Add `?dts` to import with type definitions: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0?dts"`. -::: - -### Alternative CDN links - -**esm:** - -- https://esm.sh/@faker-js/faker -- https://cdn.jsdelivr.net/npm/@faker-js/faker/+esm - -**cjs:** - -- https://cdn.jsdelivr.net/npm/@faker-js/faker - -## TypeScript Support - -Faker has native TypeScript support, out of the box. So you don't have to install any extra packages. - -In order to have faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: - -```json -{ - "compilerOptions": { - "esModuleInterop": true, - "moduleResolution": "Node" - } -} -``` - -## Create complex objects - -Faker mostly generates vales for primitives. -This is because in the real world most object schemas simply look way too different. -So if you want to create an object you most likely need to write a factory function for it. - -For our example, we use typescript to strongly type our model. -The models we will use are described below: - -```ts -import type { SexType } from '@faker-js/faker'; - -type SubscriptionTier = 'free' | 'basic' | 'business'; - -class User { - _id: string; - avatar: string; - birthday: Date; - email: string; - firstname: string; - lastname: string; - sex: SexType; - subscriptionTier: SubscriptionTier; -} -``` - -As you can see, your `User` model probably looks completly different from the one you have in your codebase. -One thing to keep an eye on is the `subscriptionTier` property, as it is not simply a string, but only one of the strings defined in the `SubscriptionTier` type (`'free'` or `'basic'` or `'business'`). -Also, in a real scenario your model should not depend on a type of a third party library (`SexType` in this case). - -Let's create our first user factory function. - -```ts -import { faker } from '@faker-js/faker'; - -function createRandomUser(): User { - return { - _id: faker.datatype.uuid(), - avatar: faker.image.avatar(), - birthday: faker.date.birthdate(), - email: faker.internet.email(), - firstname: faker.name.firstname(), - lastname: faker.name.lastname(), - sex: faker.name.sexType(); - subscriptionTier: faker.helpers.arrayElement([ - 'free', - 'basic', - 'business', - ]), - }; -} - -const user = createRandomUser(); -``` - - +# Usage + +## Node.js + +Using Faker is as easy as importing it from `@faker-js/faker`. + +```js +import { faker } from '@faker-js/faker'; + +const randomName = faker.name.fullName(); // Rowan Nikolaus +const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz +``` + +Or if you using CommonJS + +```js +const { faker } = require('@faker-js/faker'); + +const randomName = faker.name.fullName(); // Rowan Nikolaus +const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz +``` + +## Browser + +```html + +``` + +:::tip Note +Using the browser is great for experimenting 👍. However, due to all of the strings Faker uses to generate fake data, **Faker is a large package**. It's `> 5 MiB` minified. **Please avoid deploying the full Faker in your web app.** +::: + +## CDN/Deno + +```js +import { faker } from 'https://cdn.skypack.dev/@faker-js/faker'; + +const randomName = faker.name.findName(); // Willie Bahringer +const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com +``` + +:::tip Note +It is highly recommended to use version tags when importing libraries in Deno, e.g: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0"`. Add `?dts` to import with type definitions: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0?dts"`. +::: + +### Alternative CDN links + +**esm:** + +- https://esm.sh/@faker-js/faker +- https://cdn.jsdelivr.net/npm/@faker-js/faker/+esm + +**cjs:** + +- https://cdn.jsdelivr.net/npm/@faker-js/faker + +## TypeScript Support + +Faker has native TypeScript support, out of the box. So you don't have to install any extra packages. + +In order to have faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: + +```json +{ + "compilerOptions": { + "esModuleInterop": true, + "moduleResolution": "Node" + } +} +``` + +## Create complex objects + +Faker mostly generates vales for primitives. +This is because in the real world most object schemas simply look way too different. +So if you want to create an object you most likely need to write a factory function for it. + +For our example, we use typescript to strongly type our model. +The models we will use are described below: + +```ts +import type { SexType } from '@faker-js/faker'; + +type SubscriptionTier = 'free' | 'basic' | 'business'; + +class User { + _id: string; + avatar: string; + birthday: Date; + email: string; + firstname: string; + lastname: string; + sex: SexType; + subscriptionTier: SubscriptionTier; +} +``` + +As you can see, your `User` model probably looks completly different from the one you have in your codebase. +One thing to keep an eye on is the `subscriptionTier` property, as it is not simply a string, but only one of the strings defined in the `SubscriptionTier` type (`'free'` or `'basic'` or `'business'`). +Also, in a real scenario your model should not depend on a type of a third party library (`SexType` in this case). + +Let's create our first user factory function. + +```ts +import { faker } from '@faker-js/faker'; + +function createRandomUser(): User { + return { + _id: faker.datatype.uuid(), + avatar: faker.image.avatar(), + birthday: faker.date.birthdate(), + email: faker.internet.email(), + firstname: faker.name.firstname(), + lastname: faker.name.lastname(), + sex: faker.name.sexType(); + subscriptionTier: faker.helpers.arrayElement([ + 'free', + 'basic', + 'business', + ]), + }; +} + +const user = createRandomUser(); +``` From c33891c7e37db89964c7e92c09af52a9aedebd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Tue, 13 Sep 2022 23:10:31 +0200 Subject: [PATCH 09/14] docs(website): fix grammar and spelling Co-authored-by: Eric Cheng --- docs/guide/usage.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index d3001facfec..6bbd197c4b0 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -64,7 +64,7 @@ It is highly recommended to use version tags when importing libraries in Deno, e ## TypeScript Support -Faker has native TypeScript support, out of the box. So you don't have to install any extra packages. +Faker supports TypeScript out of the box, so you don't have to install any extra packages. In order to have faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: @@ -79,11 +79,11 @@ In order to have faker working properly, you need to check if these `compilerOpt ## Create complex objects -Faker mostly generates vales for primitives. -This is because in the real world most object schemas simply look way too different. -So if you want to create an object you most likely need to write a factory function for it. +Faker mostly generates values for primitives. +This is because in the real world, most object schemas simply look very different. +So, if you want to create an object, you most likely need to write a factory function for it. -For our example, we use typescript to strongly type our model. +For our example, we use TypeScript to strongly type our model. The models we will use are described below: ```ts @@ -96,8 +96,8 @@ class User { avatar: string; birthday: Date; email: string; - firstname: string; - lastname: string; + firstName: string; + lastName: string; sex: SexType; subscriptionTier: SubscriptionTier; } @@ -118,8 +118,8 @@ function createRandomUser(): User { avatar: faker.image.avatar(), birthday: faker.date.birthdate(), email: faker.internet.email(), - firstname: faker.name.firstname(), - lastname: faker.name.lastname(), + firstName: faker.name.firstName(), + lastName: faker.name.lastName(), sex: faker.name.sexType(); subscriptionTier: faker.helpers.arrayElement([ 'free', From b9db627304e6aa1627a9cbe70d9a11500437931f Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Wed, 14 Sep 2022 20:36:02 +0200 Subject: [PATCH 10/14] docs(website): extend usage section --- docs/guide/usage.md | 92 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index 6bbd197c4b0..02617df8965 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -103,11 +103,11 @@ class User { } ``` -As you can see, your `User` model probably looks completly different from the one you have in your codebase. +As you can see, your `User` model probably looks completely different from the one you have in your codebase. One thing to keep an eye on is the `subscriptionTier` property, as it is not simply a string, but only one of the strings defined in the `SubscriptionTier` type (`'free'` or `'basic'` or `'business'`). Also, in a real scenario your model should not depend on a type of a third party library (`SexType` in this case). -Let's create our first user factory function. +Let's create our first user factory function: ```ts import { faker } from '@faker-js/faker'; @@ -120,7 +120,7 @@ function createRandomUser(): User { email: faker.internet.email(), firstName: faker.name.firstName(), lastName: faker.name.lastName(), - sex: faker.name.sexType(); + sex: faker.name.sexType(), subscriptionTier: faker.helpers.arrayElement([ 'free', 'basic', @@ -131,3 +131,89 @@ function createRandomUser(): User { const user = createRandomUser(); ``` + +At this point we have a perfectly working function that will work for most purposes. +But we can take this a step further. +Currently all properties are just randomly generated. +This can lead to some undesirable values being produces. +For example: The `sex` property having value `'female'` while `firstName` is `'Bob'`. + +Lets refactor our current code: + +```ts {4-7,13-16} +import { faker } from '@faker-js/faker'; + +function createRandomUser(): User { + const sex = this.faker.name.sexType(); + const firstName = faker.name.firstName(sex); + const lastName = faker.name.lastName(); + const email = faker.internet.email(firstName, lastName) + + return { + _id: faker.datatype.uuid(), + avatar: faker.image.avatar(), + birthday: faker.date.birthdate(), + email, + firstName, + lastName, + sex, + subscriptionTier: faker.helpers.arrayElement([ + 'free', + 'basic', + 'business', + ]), + }; +} + +const user = createRandomUser(); +``` + +As you can see, we changed the order in which we generate our values. +First we generate a `sex` value to use it as input for the generation of `firstName`. +Then we generate the `lastName`. +Here, we could also pass in the `sex` value as argument, but in our use-case there are no special cases in where a female last name would differ from a male one. +By doing this first we are able to pass both names into the `email` generation function. +This allows the value to be more reasonable based on the provided arguments. + +But we can take this even another step further. +Opposite to the `_id` property that uses an `uuid` implementation, which is unique by design, the `email` property potentially isn't. +But in most use-cases this would be desireable. + +Faker got your back, with another helper method: +```ts {7-9} +import { faker } from '@faker-js/faker'; + +function createRandomUser(): User { + const sex = this.faker.name.sexType(); + const firstName = faker.name.firstName(sex); + const lastName = faker.name.lastName(); + const email = faker.helpers.unique( + faker.internet.email, + [ + firstName, + lastName, + ], + ); + + return { + _id: faker.datatype.uuid(), + avatar: faker.image.avatar(), + birthday: faker.date.birthdate(), + email, + firstName, + lastName, + sex, + subscriptionTier: faker.helpers.arrayElement([ + 'free', + 'basic', + 'business', + ]), + }; +} + +const user = createRandomUser(); +``` + +By wrapping Faker's `email` function with the [`unique`](../api/helpers.md#unique) helper function we ensure that the return value of `email` is always unique. + +Congratulation, you should now be able to create any complex object you desire. Happy faking 🥳. \ No newline at end of file From cdb44e0fd2284d3cd6cbfcd1d0327cf59c2553f1 Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Wed, 14 Sep 2022 20:53:57 +0200 Subject: [PATCH 11/14] chore: formatting --- docs/guide/usage.md | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index 02617df8965..9ebe45f0c29 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -121,11 +121,7 @@ function createRandomUser(): User { firstName: faker.name.firstName(), lastName: faker.name.lastName(), sex: faker.name.sexType(), - subscriptionTier: faker.helpers.arrayElement([ - 'free', - 'basic', - 'business', - ]), + subscriptionTier: faker.helpers.arrayElement(['free', 'basic', 'business']), }; } @@ -147,7 +143,7 @@ function createRandomUser(): User { const sex = this.faker.name.sexType(); const firstName = faker.name.firstName(sex); const lastName = faker.name.lastName(); - const email = faker.internet.email(firstName, lastName) + const email = faker.internet.email(firstName, lastName); return { _id: faker.datatype.uuid(), @@ -157,11 +153,7 @@ function createRandomUser(): User { firstName, lastName, sex, - subscriptionTier: faker.helpers.arrayElement([ - 'free', - 'basic', - 'business', - ]), + subscriptionTier: faker.helpers.arrayElement(['free', 'basic', 'business']), }; } @@ -180,6 +172,7 @@ Opposite to the `_id` property that uses an `uuid` implementation, which is uniq But in most use-cases this would be desireable. Faker got your back, with another helper method: + ```ts {7-9} import { faker } from '@faker-js/faker'; @@ -187,13 +180,10 @@ function createRandomUser(): User { const sex = this.faker.name.sexType(); const firstName = faker.name.firstName(sex); const lastName = faker.name.lastName(); - const email = faker.helpers.unique( - faker.internet.email, - [ - firstName, - lastName, - ], - ); + const email = faker.helpers.unique(faker.internet.email, [ + firstName, + lastName, + ]); return { _id: faker.datatype.uuid(), @@ -203,11 +193,7 @@ function createRandomUser(): User { firstName, lastName, sex, - subscriptionTier: faker.helpers.arrayElement([ - 'free', - 'basic', - 'business', - ]), + subscriptionTier: faker.helpers.arrayElement(['free', 'basic', 'business']), }; } @@ -216,4 +202,4 @@ const user = createRandomUser(); By wrapping Faker's `email` function with the [`unique`](../api/helpers.md#unique) helper function we ensure that the return value of `email` is always unique. -Congratulation, you should now be able to create any complex object you desire. Happy faking 🥳. \ No newline at end of file +Congratulation, you should now be able to create any complex object you desire. Happy faking 🥳. From 96777a2643f928dd0f18e584b5d62b6cc367f492 Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Wed, 14 Sep 2022 21:01:05 +0200 Subject: [PATCH 12/14] docs(website): update `note` sections --- docs/guide/usage.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index 9ebe45f0c29..a3daa7b747e 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -34,7 +34,7 @@ const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz ``` -:::tip Note +:::note Using the browser is great for experimenting 👍. However, due to all of the strings Faker uses to generate fake data, **Faker is a large package**. It's `> 5 MiB` minified. **Please avoid deploying the full Faker in your web app.** ::: @@ -47,7 +47,7 @@ const randomName = faker.name.findName(); // Willie Bahringer const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com ``` -:::tip Note +:::note It is highly recommended to use version tags when importing libraries in Deno, e.g: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0"`. Add `?dts` to import with type definitions: `import { faker } from "https://cdn.skypack.dev/@faker-js/faker@v7.4.0?dts"`. ::: From 5acb31fe8553885247e178c6e2bd3aab7835cacf Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Wed, 14 Sep 2022 21:04:12 +0200 Subject: [PATCH 13/14] docs(website): consistent mention of Faker Co-authored-by: Shinigami --- docs/guide/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index a3daa7b747e..e02bb13d7fc 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -66,7 +66,7 @@ It is highly recommended to use version tags when importing libraries in Deno, e Faker supports TypeScript out of the box, so you don't have to install any extra packages. -In order to have faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: +In order to have Faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: ```json { From 10b697e888bade4b66ea3e45581abe6c3239a687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Wed, 21 Sep 2022 15:12:53 +0200 Subject: [PATCH 14/14] docs(website): fix grammar Co-authored-by: Eric Cheng --- docs/guide/usage.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/guide/usage.md b/docs/guide/usage.md index e02bb13d7fc..8d211354d7d 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -105,7 +105,7 @@ class User { As you can see, your `User` model probably looks completely different from the one you have in your codebase. One thing to keep an eye on is the `subscriptionTier` property, as it is not simply a string, but only one of the strings defined in the `SubscriptionTier` type (`'free'` or `'basic'` or `'business'`). -Also, in a real scenario your model should not depend on a type of a third party library (`SexType` in this case). +Also, in a real scenario, your model should not depend on a type of a third party library (`SexType` in this case). Let's create our first user factory function: @@ -128,13 +128,13 @@ function createRandomUser(): User { const user = createRandomUser(); ``` -At this point we have a perfectly working function that will work for most purposes. +At this point, we have a perfectly working function that will work for most purposes. But we can take this a step further. -Currently all properties are just randomly generated. -This can lead to some undesirable values being produces. +Currently, all properties are just randomly generated. +This can lead to some undesirable values being produced. For example: The `sex` property having value `'female'` while `firstName` is `'Bob'`. -Lets refactor our current code: +Let's refactor our current code: ```ts {4-7,13-16} import { faker } from '@faker-js/faker'; @@ -161,17 +161,17 @@ const user = createRandomUser(); ``` As you can see, we changed the order in which we generate our values. -First we generate a `sex` value to use it as input for the generation of `firstName`. +First, we generate a `sex` value to use it as input for the generation of `firstName`. Then we generate the `lastName`. Here, we could also pass in the `sex` value as argument, but in our use-case there are no special cases in where a female last name would differ from a male one. -By doing this first we are able to pass both names into the `email` generation function. +By doing this first, we are able to pass both names into the `email` generation function. This allows the value to be more reasonable based on the provided arguments. But we can take this even another step further. Opposite to the `_id` property that uses an `uuid` implementation, which is unique by design, the `email` property potentially isn't. -But in most use-cases this would be desireable. +But, in most use-cases, this would be desirable. -Faker got your back, with another helper method: +Faker has your back, with another helper method: ```ts {7-9} import { faker } from '@faker-js/faker'; @@ -200,6 +200,6 @@ function createRandomUser(): User { const user = createRandomUser(); ``` -By wrapping Faker's `email` function with the [`unique`](../api/helpers.md#unique) helper function we ensure that the return value of `email` is always unique. +By wrapping Faker's `email` function with the [`unique`](../api/helpers.md#unique) helper function, we ensure that the return value of `email` is always unique. -Congratulation, you should now be able to create any complex object you desire. Happy faking 🥳. +Congratulations, you should now be able to create any complex object you desire. Happy faking 🥳.