From 6160c3c22d17317e1216a77298e98b3f73630b34 Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Wed, 16 Mar 2022 12:31:32 +0000
Subject: [PATCH 01/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20First=20punt=20at?=
=?UTF-8?q?=20priority=20option?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Allow user to set length priority to length or unique (POC)
✅ Closes: #220
---
README.md | 2 +-
docs/docs/getting-started.mdx | 2 +-
packages/falso/src/lib/core/core.ts | 75 ++++++++++++++++++++++++++---
3 files changed, 71 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 1b36faadb..88959eb0c 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Create massive amounts of fake data in the browser and NodeJS. Tree Shakeable &
-✅ 192 Functions
+✅ 193 Functions
✅ Tree Shakable
✅ Fully Typed
✅ Entity Functions
diff --git a/docs/docs/getting-started.mdx b/docs/docs/getting-started.mdx
index bd00e6dcf..9efc9309d 100644
--- a/docs/docs/getting-started.mdx
+++ b/docs/docs/getting-started.mdx
@@ -13,7 +13,7 @@ title: Getting Started
/>
-✅ 192 Functions
+✅ 193 Functions
✅ Tree Shakable
✅ Fully Typed
✅ Entity Functions
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index 95444f98b..e62e30f97 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -2,6 +2,7 @@ import { random } from '../random';
export interface FakeOptions {
length?: number;
+ priority?: 'length' | 'unique';
}
type Return = [O] extends [never]
@@ -11,21 +12,83 @@ type Return = [O] extends [never]
: T;
export function fake(
- data: T[] | ((i: number) => T),
+ data: T[] | (() => T),
options?: Options
): Return {
- const dataSource = Array.isArray(data) ? () => randElement(data) : data;
+ if (Array.isArray(data)) {
+ return fakeFromArray(data, options) as any;
+ }
+
+ return fakeFromFunction(data, options) as any;
+}
+
+export function fakeFromFunction(
+ data: () => T,
+ options?: Options
+) {
+ if (!options?.length) {
+ return data();
+ }
+
+ const priority = options?.priority ?? 'length';
+
+ if (priority === 'length') {
+ return Array.from({ length: options.length }, (_, index) => data());
+ }
+
+ const items: T[] = [];
+
+ let attempts = 0;
+ const maxAttempts = options.length * 2;
+
+ while (items.length < options.length) {
+ if (attempts >= maxAttempts) {
+ break;
+ }
+ const item = data();
+
+ if (!items.includes(item)) {
+ items.push(item);
+ }
+
+ attempts++;
+ }
+
+ return items;
+}
+
+export function fakeFromArray(
+ data: T[],
+ options?: Options
+) {
if (!options?.length) {
- return dataSource(0) as any;
+ return randElement(data);
}
+ const priority = options?.priority ?? 'length';
+
+ if (priority === 'length') {
+ return Array.from({ length: options.length }, (_, index) =>
+ randElement(data)
+ );
+ }
+
+ const clonedData: T[] = JSON.parse(JSON.stringify(data));
return Array.from({ length: options.length }, (_, index) =>
- dataSource(index)
- ) as any;
+ randUniqueElement(clonedData)
+ ).filter((item) => item);
+}
+
+export function randUniqueElement(arr: T[]): T {
+ const index = Math.floor(random() * arr.length);
+ const item = arr[index];
+ arr.splice(index, 1);
+
+ return item;
}
-export function randElement(arr: T[]) {
+export function randElement(arr: T[]): T {
return arr[Math.floor(random() * arr.length)];
}
From 6b57aa0d62bcb6c2d2c2e63ac615d0772313936a Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Tue, 22 Mar 2022 18:13:18 +0000
Subject: [PATCH 02/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Clean=20up=20fakFr?=
=?UTF-8?q?omArray=20logic?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Move randUniqueElement logic into fakFromArray. Simplified
fakeFromFunction while loop logic
#220
---
README.md | 2 +-
docs/docs/getting-started.mdx | 2 +-
packages/falso/src/lib/core/core.ts | 24 ++++++++++--------------
3 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index 88959eb0c..1b36faadb 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Create massive amounts of fake data in the browser and NodeJS. Tree Shakeable &
-✅ 193 Functions
+✅ 192 Functions
✅ Tree Shakable
✅ Fully Typed
✅ Entity Functions
diff --git a/docs/docs/getting-started.mdx b/docs/docs/getting-started.mdx
index 9efc9309d..bd00e6dcf 100644
--- a/docs/docs/getting-started.mdx
+++ b/docs/docs/getting-started.mdx
@@ -13,7 +13,7 @@ title: Getting Started
/>
-✅ 193 Functions
+✅ 192 Functions
✅ Tree Shakable
✅ Fully Typed
✅ Entity Functions
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index e62e30f97..5e4b0f96b 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -41,11 +41,7 @@ export function fakeFromFunction(
let attempts = 0;
const maxAttempts = options.length * 2;
- while (items.length < options.length) {
- if (attempts >= maxAttempts) {
- break;
- }
-
+ while (items.length < options.length && attempts < maxAttempts) {
const item = data();
if (!items.includes(item)) {
@@ -75,17 +71,17 @@ export function fakeFromArray(
}
const clonedData: T[] = JSON.parse(JSON.stringify(data));
- return Array.from({ length: options.length }, (_, index) =>
- randUniqueElement(clonedData)
- ).filter((item) => item);
-}
+ const newArray: T[] = [];
-export function randUniqueElement(arr: T[]): T {
- const index = Math.floor(random() * arr.length);
- const item = arr[index];
- arr.splice(index, 1);
+ while (clonedData.length && newArray.length !== options.length) {
+ const randomIndex = getRandomInRange({ min: clonedData.length });
+ const item = clonedData[randomIndex];
+
+ newArray.push(item);
+ clonedData.splice(randomIndex, 1);
+ }
- return item;
+ return newArray;
}
export function randElement(arr: T[]): T {
From 713c77d5b34b3334a2f189fc8a7f7f5a1e347aea Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Tue, 22 Mar 2022 19:02:12 +0000
Subject: [PATCH 03/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Replace=20use=20of?=
=?UTF-8?q?=20random=20index=20logic=20with=20getRandomInRange?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
✅ Closes: #220
---
packages/falso/src/lib/core/core.ts | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index 5e4b0f96b..d03c3bdbd 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -74,7 +74,7 @@ export function fakeFromArray(
const newArray: T[] = [];
while (clonedData.length && newArray.length !== options.length) {
- const randomIndex = getRandomInRange({ min: clonedData.length });
+ const randomIndex = getRandomInRange({ max: clonedData.length - 1 });
const item = clonedData[randomIndex];
newArray.push(item);
@@ -85,7 +85,8 @@ export function fakeFromArray(
}
export function randElement(arr: T[]): T {
- return arr[Math.floor(random() * arr.length)];
+ const randomIndex = getRandomInRange({ max: arr.length - 1 });
+ return arr[randomIndex];
}
export interface RandomInRangeOptions {
From bbe7b0b6a645c53e4f27f1e001bf4c02455e125d Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Tue, 22 Mar 2022 19:19:40 +0000
Subject: [PATCH 04/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Revert=20rand=20el?=
=?UTF-8?q?ement=20logic=20for=20now?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
✅ Closes: #220
---
packages/falso/src/lib/core/core.ts | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index d03c3bdbd..b3d9a8ca3 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -74,7 +74,7 @@ export function fakeFromArray(
const newArray: T[] = [];
while (clonedData.length && newArray.length !== options.length) {
- const randomIndex = getRandomInRange({ max: clonedData.length - 1 });
+ const randomIndex = Math.floor(random() * clonedData.length);
const item = clonedData[randomIndex];
newArray.push(item);
@@ -85,8 +85,7 @@ export function fakeFromArray(
}
export function randElement(arr: T[]): T {
- const randomIndex = getRandomInRange({ max: arr.length - 1 });
- return arr[randomIndex];
+ return arr[Math.floor(random() * arr.length)];
}
export interface RandomInRangeOptions {
From 7f69bade05fc76ee9b80abdb17bbf466c3eea36c Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Wed, 23 Mar 2022 12:10:15 +0000
Subject: [PATCH 05/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Allow=20devs=20to?=
=?UTF-8?q?=20pass=20in=20comparison=20functions?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Add default comparison functions for most likely use cases. Implimented
them
✅ Closes: #220
---
packages/falso/src/lib/core/core.ts | 24 ++++++++++++++-----
packages/falso/src/lib/post.ts | 8 ++++---
packages/falso/src/lib/product.ts | 36 ++++++++++++++++-------------
packages/falso/src/lib/superhero.ts | 9 ++++++--
packages/falso/src/lib/user.ts | 8 ++++---
5 files changed, 55 insertions(+), 30 deletions(-)
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index b3d9a8ca3..9831fbfa2 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -13,17 +13,22 @@ type Return = [O] extends [never]
export function fake(
data: T[] | (() => T),
- options?: Options
+ options?: Options,
+ comparisonFunction: (
+ item: T,
+ items: T[]
+ ) => boolean = primitiveComparisonFunction
): Return {
if (Array.isArray(data)) {
return fakeFromArray(data, options) as any;
}
- return fakeFromFunction(data, options) as any;
+ return fakeFromFunction(data, comparisonFunction, options) as any;
}
export function fakeFromFunction(
data: () => T,
+ comparisonFunction: (item: T, items: T[]) => boolean,
options?: Options
) {
if (!options?.length) {
@@ -44,7 +49,7 @@ export function fakeFromFunction(
while (items.length < options.length && attempts < maxAttempts) {
const item = data();
- if (!items.includes(item)) {
+ if (!comparisonFunction(item, items)) {
items.push(item);
}
@@ -65,9 +70,7 @@ export function fakeFromArray(
const priority = options?.priority ?? 'length';
if (priority === 'length') {
- return Array.from({ length: options.length }, (_, index) =>
- randElement(data)
- );
+ return Array.from({ length: options.length }, () => randElement(data));
}
const clonedData: T[] = JSON.parse(JSON.stringify(data));
@@ -84,6 +87,15 @@ export function fakeFromArray(
return newArray;
}
+export const primitiveComparisonFunction: (item: T, items: T[]) => boolean =
+ (item, items) => items.includes(item);
+export const objectWithIdComparisonFunction: (
+ item: T,
+ items: T[]
+) => boolean = (item, items) => {
+ return items.some((i) => i.id === item.id);
+};
+
export function randElement(arr: T[]): T {
return arr[Math.floor(random() * arr.length)];
}
diff --git a/packages/falso/src/lib/post.ts b/packages/falso/src/lib/post.ts
index 648053b27..a0b854e97 100644
--- a/packages/falso/src/lib/post.ts
+++ b/packages/falso/src/lib/post.ts
@@ -1,4 +1,4 @@
-import { FakeOptions, fake } from './core/core';
+import { FakeOptions, fake, objectWithIdComparisonFunction } from './core/core';
import { randUser, User } from './user';
import { randUuid } from './uuid';
import { randText } from './text';
@@ -28,7 +28,7 @@ export interface Post {
export function randPost(
options?: Options
) {
- return fake(() => {
+ const factory = () => {
const post: Post = {
id: randUuid(),
title: randText({ charCount: 40 }),
@@ -43,5 +43,7 @@ export function randPost(
};
return post;
- }, options);
+ };
+
+ return fake(factory, options, objectWithIdComparisonFunction);
}
diff --git a/packages/falso/src/lib/product.ts b/packages/falso/src/lib/product.ts
index 4f393805b..0db862e29 100644
--- a/packages/falso/src/lib/product.ts
+++ b/packages/falso/src/lib/product.ts
@@ -1,4 +1,9 @@
-import { FakeOptions, fake, getRandomInRange } from './core/core';
+import {
+ FakeOptions,
+ fake,
+ getRandomInRange,
+ objectWithIdComparisonFunction,
+} from './core/core';
import { randUuid } from './uuid';
import { randProductName } from './product-name';
import { randProductDescription } from './product-description';
@@ -35,19 +40,18 @@ export interface Product {
export function randProduct(
options?: Options
) {
- return fake(
- () => ({
- id: randUuid(),
- title: randProductName(),
- description: randProductDescription(),
- price: getRandomInRange({ fraction: 2 }).toString(),
- category: randProductCategory(),
- image: randImg(),
- rating: {
- rate: getRandomInRange({ min: 0.1, max: 5.0, fraction: 1 }).toString(),
- count: getRandomInRange({ min: 0, max: 10000 }).toString(),
- },
- }),
- options
- );
+ const factory = () => ({
+ id: randUuid(),
+ title: randProductName(),
+ description: randProductDescription(),
+ price: getRandomInRange({ fraction: 2 }).toString(),
+ category: randProductCategory(),
+ image: randImg(),
+ rating: {
+ rate: getRandomInRange({ min: 0.1, max: 5.0, fraction: 1 }).toString(),
+ count: getRandomInRange({ min: 0, max: 10000 }).toString(),
+ },
+ });
+
+ return fake(factory, options, objectWithIdComparisonFunction);
}
diff --git a/packages/falso/src/lib/superhero.ts b/packages/falso/src/lib/superhero.ts
index fa029cf90..050e8f184 100644
--- a/packages/falso/src/lib/superhero.ts
+++ b/packages/falso/src/lib/superhero.ts
@@ -1,4 +1,9 @@
-import { fake, FakeOptions, randElement } from './core/core';
+import {
+ fake,
+ FakeOptions,
+ objectWithIdComparisonFunction,
+ randElement,
+} from './core/core';
import { data } from './superhero.json';
import { randUuid } from './uuid';
@@ -50,5 +55,5 @@ export function randSuperhero(
};
};
- return fake(factory, options);
+ return fake(factory, options, objectWithIdComparisonFunction);
}
diff --git a/packages/falso/src/lib/user.ts b/packages/falso/src/lib/user.ts
index ca300b948..1e9fc7e6a 100644
--- a/packages/falso/src/lib/user.ts
+++ b/packages/falso/src/lib/user.ts
@@ -1,4 +1,4 @@
-import { fake, FakeOptions } from './core/core';
+import { fake, FakeOptions, objectWithIdComparisonFunction } from './core/core';
import { randUuid } from './uuid';
import { randEmail } from './email';
import { randFirstName } from './first-name';
@@ -40,7 +40,7 @@ export interface User {
export function randUser(
options?: Options
) {
- return fake(() => {
+ const factory = () => {
const firstName = randFirstName({ withAccents: false });
const lastName = randLastName({ withAccents: false });
@@ -56,5 +56,7 @@ export function randUser(
};
return user;
- }, options);
+ };
+
+ return fake(factory, options, objectWithIdComparisonFunction);
}
From 77831a534ddf168497aec32d11a0ce0f4571aa14 Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Wed, 23 Mar 2022 14:29:00 +0000
Subject: [PATCH 06/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Add=20custom=20com?=
=?UTF-8?q?parison=20functions=20non-conforming=20function?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
✅ Closes: #220
---
packages/falso/src/lib/address.ts | 9 ++++++++-
packages/falso/src/lib/between-date.ts | 4 ++--
packages/falso/src/lib/core/core.ts | 6 ++++++
packages/falso/src/lib/credit-card.ts | 9 ++++++++-
packages/falso/src/lib/flight-details.ts | 12 ++++++++++++
packages/falso/src/lib/float.ts | 2 --
packages/falso/src/lib/full-address.ts | 4 ++--
packages/falso/src/lib/future-date.ts | 6 ++++--
packages/falso/src/lib/nearby-gpscoordinate.ts | 13 ++++++++++++-
packages/falso/src/lib/past-date.ts | 8 ++++++--
packages/falso/src/lib/recent-date.ts | 8 ++++++--
packages/falso/src/lib/soon-date.ts | 8 ++++++--
packages/falso/src/lib/todo.ts | 16 ++++++++--------
packages/falso/src/lib/user-name.ts | 6 ++++--
packages/falso/src/lib/zip-code.ts | 6 ++++--
15 files changed, 88 insertions(+), 29 deletions(-)
diff --git a/packages/falso/src/lib/address.ts b/packages/falso/src/lib/address.ts
index cbafe0631..638a29aa2 100644
--- a/packages/falso/src/lib/address.ts
+++ b/packages/falso/src/lib/address.ts
@@ -64,5 +64,12 @@ export function randAddress(
return address;
};
- return fake(factory, options);
+ return fake(factory, options, comparisonFunction);
}
+
+const comparisonFunction: (item: Address, items: Address[]) => boolean = (
+ item: Address,
+ items: Address[]
+) => {
+ return items.some((i) => i.street + i.zipCode === item.street + item.zipCode);
+};
diff --git a/packages/falso/src/lib/between-date.ts b/packages/falso/src/lib/between-date.ts
index d8e08f055..9a80590e0 100644
--- a/packages/falso/src/lib/between-date.ts
+++ b/packages/falso/src/lib/between-date.ts
@@ -1,4 +1,4 @@
-import { fake, FakeOptions } from './core/core';
+import { dateComparisonFunction, fake, FakeOptions } from './core/core';
import { randNumber } from './number';
interface BetweenOptions extends FakeOptions {
@@ -39,5 +39,5 @@ export function randBetweenDate(
);
};
- return fake(generator, options);
+ return fake(generator, options, dateComparisonFunction);
}
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index 9831fbfa2..d28f70d3e 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -95,6 +95,12 @@ export const objectWithIdComparisonFunction: (
) => boolean = (item, items) => {
return items.some((i) => i.id === item.id);
};
+export const dateComparisonFunction: (date: Date, dates: Date[]) => boolean = (
+ date,
+ dates
+) => {
+ return dates.some((d) => d.valueOf() === date.valueOf());
+};
export function randElement(arr: T[]): T {
return arr[Math.floor(random() * arr.length)];
diff --git a/packages/falso/src/lib/credit-card.ts b/packages/falso/src/lib/credit-card.ts
index 6a538c962..8001c18bc 100644
--- a/packages/falso/src/lib/credit-card.ts
+++ b/packages/falso/src/lib/credit-card.ts
@@ -81,5 +81,12 @@ export function randCreditCard(
};
};
- return fake(factory, options);
+ return fake(factory, options, comparisonFunction);
}
+
+export const comparisonFunction: (
+ card: CreditCard,
+ cards: CreditCard[]
+) => boolean = (card, cards) => {
+ return cards.some((c) => c.number === card.number);
+};
diff --git a/packages/falso/src/lib/flight-details.ts b/packages/falso/src/lib/flight-details.ts
index cb43e378d..2c08d913b 100644
--- a/packages/falso/src/lib/flight-details.ts
+++ b/packages/falso/src/lib/flight-details.ts
@@ -5,6 +5,7 @@ import { Airline, randFlightNumber } from './flight-number';
import { randFullName } from './full-name';
import { randSeatNumber } from './seat-number';
import { Airport, randAirport } from './airport';
+import { CreditCard } from './credit-card';
export interface FlightDetailsOptions extends FakeOptions {
airline?: Airline;
@@ -73,3 +74,14 @@ export function randFlightDetails(
return fake(factory, options);
}
+
+export const comparisonFunction: (
+ flight: FlightDetails,
+ flights: FlightDetails[]
+) => boolean = (flight, flights) => {
+ return flights.some(
+ (f) =>
+ f.passenger + f.flightNumber + f.date ===
+ flight.passenger + flight.flightNumber + flight.date
+ );
+};
diff --git a/packages/falso/src/lib/float.ts b/packages/falso/src/lib/float.ts
index 6558b5754..e4793adc1 100644
--- a/packages/falso/src/lib/float.ts
+++ b/packages/falso/src/lib/float.ts
@@ -37,5 +37,3 @@ export function randFloat(
};
return fake(() => getRandomInRange(o), options);
}
-
-randFloat();
diff --git a/packages/falso/src/lib/full-address.ts b/packages/falso/src/lib/full-address.ts
index 29898f173..905b180dc 100644
--- a/packages/falso/src/lib/full-address.ts
+++ b/packages/falso/src/lib/full-address.ts
@@ -1,4 +1,4 @@
-import { FakeOptions, fake } from './core/core';
+import { fake } from './core/core';
import { AddressOptions, randAddress } from './address';
/**
@@ -29,7 +29,7 @@ export function randFullAddress(
const includeCounty: boolean = options?.includeCounty ?? true;
const includeCountry: boolean = options?.includeCountry ?? true;
- const factory = () => {
+ const factory: () => string = () => {
const { street, city, county, country, zipCode } = randAddress({
includeCounty,
includeCountry,
diff --git a/packages/falso/src/lib/future-date.ts b/packages/falso/src/lib/future-date.ts
index 4374bd4fe..209efe085 100644
--- a/packages/falso/src/lib/future-date.ts
+++ b/packages/falso/src/lib/future-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { fake, FakeOptions } from './core/core';
+import { dateComparisonFunction, fake, FakeOptions } from './core/core';
interface FutureOptions extends FakeOptions {
years?: number;
@@ -35,5 +35,7 @@ export function randFutureDate(
const yearsInMilliseconds = years * 365 * 24 * 60 * 60 * 1000;
const from = new Date();
const to = new Date(from.getTime() + yearsInMilliseconds);
- return fake(() => randBetweenDate({ from, to }), options);
+ const factory: () => Date = () => randBetweenDate({ from, to });
+
+ return fake(factory, options, dateComparisonFunction);
}
diff --git a/packages/falso/src/lib/nearby-gpscoordinate.ts b/packages/falso/src/lib/nearby-gpscoordinate.ts
index a37f3d3f5..f3353b8ac 100644
--- a/packages/falso/src/lib/nearby-gpscoordinate.ts
+++ b/packages/falso/src/lib/nearby-gpscoordinate.ts
@@ -19,5 +19,16 @@ import { randLongitude } from './longitude';
export function randNearbyGPSCoordinate(
options?: Options
) {
- return fake(() => [randLatitude(), randLongitude()], options);
+ return fake(
+ () => [randLatitude(), randLongitude()],
+ options,
+ comparisonFunction
+ );
}
+
+const comparisonFunction: (
+ coordinate: number[],
+ coordinates: number[][]
+) => boolean = (coordinate, coordinates) => {
+ return coordinates.some((c) => c.join('') === c.join(''));
+};
diff --git a/packages/falso/src/lib/past-date.ts b/packages/falso/src/lib/past-date.ts
index abc6b8ee9..d62ed73df 100644
--- a/packages/falso/src/lib/past-date.ts
+++ b/packages/falso/src/lib/past-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { fake, FakeOptions } from './core/core';
+import { dateComparisonFunction, fake, FakeOptions } from './core/core';
interface PastOptions extends FakeOptions {
years?: number;
@@ -36,5 +36,9 @@ export function randPastDate(
const to = new Date();
const from = new Date(to.getTime() - yearsInMilliseconds);
- return fake(() => randBetweenDate({ from, to }), options);
+ return fake(
+ () => randBetweenDate({ from, to }),
+ options,
+ dateComparisonFunction
+ );
}
diff --git a/packages/falso/src/lib/recent-date.ts b/packages/falso/src/lib/recent-date.ts
index dda73db0a..3736b1b40 100644
--- a/packages/falso/src/lib/recent-date.ts
+++ b/packages/falso/src/lib/recent-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { fake, FakeOptions } from './core/core';
+import { dateComparisonFunction, fake, FakeOptions } from './core/core';
interface RecentOptions extends FakeOptions {
days?: number;
@@ -36,5 +36,9 @@ export function randRecentDate(
const to = new Date();
const from = new Date(to.getTime() - daysInMilliseconds);
- return fake(() => randBetweenDate({ from, to }), options);
+ return fake(
+ () => randBetweenDate({ from, to }),
+ options,
+ dateComparisonFunction
+ );
}
diff --git a/packages/falso/src/lib/soon-date.ts b/packages/falso/src/lib/soon-date.ts
index fd53303f9..6bd91c4c0 100644
--- a/packages/falso/src/lib/soon-date.ts
+++ b/packages/falso/src/lib/soon-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { fake, FakeOptions } from './core/core';
+import { dateComparisonFunction, fake, FakeOptions } from './core/core';
interface SoonOptions extends FakeOptions {
days?: number;
@@ -35,5 +35,9 @@ export function randSoonDate(
const daysInMilliseconds = days * 24 * 60 * 60 * 1000;
const from = new Date();
const to = new Date(from.getTime() + daysInMilliseconds);
- return fake(() => randBetweenDate({ from, to }), options);
+ return fake(
+ () => randBetweenDate({ from, to }),
+ options,
+ dateComparisonFunction
+ );
}
diff --git a/packages/falso/src/lib/todo.ts b/packages/falso/src/lib/todo.ts
index 4cf0c51fc..3ae26779a 100644
--- a/packages/falso/src/lib/todo.ts
+++ b/packages/falso/src/lib/todo.ts
@@ -1,4 +1,4 @@
-import { fake, FakeOptions } from './core/core';
+import { fake, FakeOptions, objectWithIdComparisonFunction } from './core/core';
import { randUuid } from './uuid';
import { randBoolean } from './boolean';
import { randText } from './text';
@@ -26,11 +26,11 @@ export interface Todo {
export function randTodo(
options?: Options
) {
- return fake(() => {
- return {
- id: randUuid(),
- title: randText({ charCount: 40 }),
- completed: randBoolean(),
- } as Todo;
- }, options);
+ const factory: () => Todo = () => ({
+ id: randUuid(),
+ title: randText({ charCount: 40 }),
+ completed: randBoolean(),
+ });
+
+ return fake(factory, options, objectWithIdComparisonFunction);
}
diff --git a/packages/falso/src/lib/user-name.ts b/packages/falso/src/lib/user-name.ts
index e005a45fb..f276781f8 100644
--- a/packages/falso/src/lib/user-name.ts
+++ b/packages/falso/src/lib/user-name.ts
@@ -34,7 +34,7 @@ export interface UserNameOptions extends FakeOptions {
export function randUserName(
options?: Options
) {
- return fake(() => {
+ const factory: () => string = () => {
const firstName = options?.firstName ?? randFirstName();
const lastName = options?.lastName ?? randLastName();
let userName = `${firstName} ${lastName}`.replace(' ', fake(['.', '_']));
@@ -44,5 +44,7 @@ export function randUserName(
}
return userName;
- }, options);
+ };
+
+ return fake(factory, options);
}
diff --git a/packages/falso/src/lib/zip-code.ts b/packages/falso/src/lib/zip-code.ts
index 5432bbf49..33e3df580 100644
--- a/packages/falso/src/lib/zip-code.ts
+++ b/packages/falso/src/lib/zip-code.ts
@@ -19,7 +19,7 @@ import { randBoolean } from './boolean';
export function randZipCode(
options?: Options
) {
- return fake(() => {
+ const factory: () => string = () => {
let zipCode = '' + randNumber({ min: 10_000, max: 99_999 });
if (randBoolean()) {
@@ -27,5 +27,7 @@ export function randZipCode(
}
return zipCode;
- }, options);
+ };
+
+ return fake(factory, options);
}
From af09284089842baa4133c57984e6482d61155ecb Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Thu, 24 Mar 2022 08:04:30 +0000
Subject: [PATCH 07/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Add=20json=20check?=
=?UTF-8?q?=20unique=20function.=20Clean=20up=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
✅ Closes: #220
---
packages/falso/src/lib/address.ts | 8 ++---
packages/falso/src/lib/between-date.ts | 4 +--
packages/falso/src/lib/core/core.ts | 29 +++++++++----------
packages/falso/src/lib/credit-card.ts | 12 ++++----
packages/falso/src/lib/flight-details.ts | 9 +++---
packages/falso/src/lib/future-date.ts | 4 +--
packages/falso/src/lib/json.ts | 7 ++++-
.../falso/src/lib/nearby-gpscoordinate.ts | 15 +++-------
packages/falso/src/lib/past-date.ts | 8 ++---
packages/falso/src/lib/post.ts | 4 +--
packages/falso/src/lib/product.ts | 4 +--
packages/falso/src/lib/recent-date.ts | 8 ++---
packages/falso/src/lib/soon-date.ts | 8 ++---
packages/falso/src/lib/superhero.ts | 4 +--
packages/falso/src/lib/todo.ts | 4 +--
packages/falso/src/lib/user.ts | 4 +--
packages/falso/src/tests/json.spec.ts | 26 +++++------------
17 files changed, 62 insertions(+), 96 deletions(-)
diff --git a/packages/falso/src/lib/address.ts b/packages/falso/src/lib/address.ts
index 638a29aa2..f1984c89c 100644
--- a/packages/falso/src/lib/address.ts
+++ b/packages/falso/src/lib/address.ts
@@ -64,12 +64,10 @@ export function randAddress(
return address;
};
- return fake(factory, options, comparisonFunction);
+ return fake(factory, options, checkUnique);
}
-const comparisonFunction: (item: Address, items: Address[]) => boolean = (
+const checkUnique: (item: Address, items: Address[]) => boolean = (
item: Address,
items: Address[]
-) => {
- return items.some((i) => i.street + i.zipCode === item.street + item.zipCode);
-};
+) => items.some((i) => i.street + i.zipCode === item.street + item.zipCode);
diff --git a/packages/falso/src/lib/between-date.ts b/packages/falso/src/lib/between-date.ts
index 9a80590e0..54af5cd16 100644
--- a/packages/falso/src/lib/between-date.ts
+++ b/packages/falso/src/lib/between-date.ts
@@ -1,4 +1,4 @@
-import { dateComparisonFunction, fake, FakeOptions } from './core/core';
+import { checkUniqueDate, fake, FakeOptions } from './core/core';
import { randNumber } from './number';
interface BetweenOptions extends FakeOptions {
@@ -39,5 +39,5 @@ export function randBetweenDate(
);
};
- return fake(generator, options, dateComparisonFunction);
+ return fake(generator, options, checkUniqueDate);
}
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index d28f70d3e..8dfe72519 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -14,10 +14,7 @@ type Return = [O] extends [never]
export function fake(
data: T[] | (() => T),
options?: Options,
- comparisonFunction: (
- item: T,
- items: T[]
- ) => boolean = primitiveComparisonFunction
+ comparisonFunction: (item: T, items: T[]) => boolean = checkUniquePrimitive
): Return {
if (Array.isArray(data)) {
return fakeFromArray(data, options) as any;
@@ -87,20 +84,20 @@ export function fakeFromArray(
return newArray;
}
-export const primitiveComparisonFunction: (item: T, items: T[]) => boolean =
- (item, items) => items.includes(item);
-export const objectWithIdComparisonFunction: (
- item: T,
- items: T[]
-) => boolean = (item, items) => {
- return items.some((i) => i.id === item.id);
-};
-export const dateComparisonFunction: (date: Date, dates: Date[]) => boolean = (
+export const checkUniquePrimitive: (item: T, items: T[]) => boolean = (
+ item,
+ items
+) => items.includes(item);
+
+export const checkUniqueDate: (date: Date, dates: Date[]) => boolean = (
date,
dates
-) => {
- return dates.some((d) => d.valueOf() === date.valueOf());
-};
+) => dates.some((d) => d.valueOf() === date.valueOf());
+
+export const checkUniqueObjectWithId: (
+ item: T,
+ items: T[]
+) => boolean = (item, items) => items.some((i) => i.id === item.id);
export function randElement(arr: T[]): T {
return arr[Math.floor(random() * arr.length)];
diff --git a/packages/falso/src/lib/credit-card.ts b/packages/falso/src/lib/credit-card.ts
index 8001c18bc..566b71583 100644
--- a/packages/falso/src/lib/credit-card.ts
+++ b/packages/falso/src/lib/credit-card.ts
@@ -81,12 +81,10 @@ export function randCreditCard(
};
};
- return fake(factory, options, comparisonFunction);
+ return fake(factory, options, checkUnique);
}
-export const comparisonFunction: (
- card: CreditCard,
- cards: CreditCard[]
-) => boolean = (card, cards) => {
- return cards.some((c) => c.number === card.number);
-};
+const checkUnique: (card: CreditCard, cards: CreditCard[]) => boolean = (
+ card,
+ cards
+) => cards.some((c) => c.number === card.number);
diff --git a/packages/falso/src/lib/flight-details.ts b/packages/falso/src/lib/flight-details.ts
index 2c08d913b..37aa40ed5 100644
--- a/packages/falso/src/lib/flight-details.ts
+++ b/packages/falso/src/lib/flight-details.ts
@@ -72,16 +72,15 @@ export function randFlightDetails(
};
};
- return fake(factory, options);
+ return fake(factory, options, checkUnique);
}
-export const comparisonFunction: (
+const checkUnique: (
flight: FlightDetails,
flights: FlightDetails[]
-) => boolean = (flight, flights) => {
- return flights.some(
+) => boolean = (flight, flights) =>
+ flights.some(
(f) =>
f.passenger + f.flightNumber + f.date ===
flight.passenger + flight.flightNumber + flight.date
);
-};
diff --git a/packages/falso/src/lib/future-date.ts b/packages/falso/src/lib/future-date.ts
index 209efe085..12ed2259f 100644
--- a/packages/falso/src/lib/future-date.ts
+++ b/packages/falso/src/lib/future-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { dateComparisonFunction, fake, FakeOptions } from './core/core';
+import { checkUniqueDate, fake, FakeOptions } from './core/core';
interface FutureOptions extends FakeOptions {
years?: number;
@@ -37,5 +37,5 @@ export function randFutureDate(
const to = new Date(from.getTime() + yearsInMilliseconds);
const factory: () => Date = () => randBetweenDate({ from, to });
- return fake(factory, options, dateComparisonFunction);
+ return fake(factory, options, checkUniqueDate);
}
diff --git a/packages/falso/src/lib/json.ts b/packages/falso/src/lib/json.ts
index 779fa30ae..2aa7e5eca 100644
--- a/packages/falso/src/lib/json.ts
+++ b/packages/falso/src/lib/json.ts
@@ -88,5 +88,10 @@ export function randJSON(
return generatedObject;
};
- return fake(factory, options);
+ return fake(factory, options, checkUnique);
}
+
+const checkUnique: (item: object, items: object[]) => boolean = (
+ item: object,
+ items: object[]
+) => items.some((i) => JSON.stringify(i) === JSON.stringify(item));
diff --git a/packages/falso/src/lib/nearby-gpscoordinate.ts b/packages/falso/src/lib/nearby-gpscoordinate.ts
index f3353b8ac..c5f7671cb 100644
--- a/packages/falso/src/lib/nearby-gpscoordinate.ts
+++ b/packages/falso/src/lib/nearby-gpscoordinate.ts
@@ -19,16 +19,9 @@ import { randLongitude } from './longitude';
export function randNearbyGPSCoordinate(
options?: Options
) {
- return fake(
- () => [randLatitude(), randLongitude()],
- options,
- comparisonFunction
- );
+ return fake(() => [randLatitude(), randLongitude()], options, checkUnique);
}
-const comparisonFunction: (
- coordinate: number[],
- coordinates: number[][]
-) => boolean = (coordinate, coordinates) => {
- return coordinates.some((c) => c.join('') === c.join(''));
-};
+const checkUnique: (coordinate: number[], coordinates: number[][]) => boolean =
+ (coordinate, coordinates) =>
+ coordinates.some((c) => c.join('') === c.join(''));
diff --git a/packages/falso/src/lib/past-date.ts b/packages/falso/src/lib/past-date.ts
index d62ed73df..b36cb79f7 100644
--- a/packages/falso/src/lib/past-date.ts
+++ b/packages/falso/src/lib/past-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { dateComparisonFunction, fake, FakeOptions } from './core/core';
+import { checkUniqueDate, fake, FakeOptions } from './core/core';
interface PastOptions extends FakeOptions {
years?: number;
@@ -36,9 +36,5 @@ export function randPastDate(
const to = new Date();
const from = new Date(to.getTime() - yearsInMilliseconds);
- return fake(
- () => randBetweenDate({ from, to }),
- options,
- dateComparisonFunction
- );
+ return fake(() => randBetweenDate({ from, to }), options, checkUniqueDate);
}
diff --git a/packages/falso/src/lib/post.ts b/packages/falso/src/lib/post.ts
index a0b854e97..a9a706dbb 100644
--- a/packages/falso/src/lib/post.ts
+++ b/packages/falso/src/lib/post.ts
@@ -1,4 +1,4 @@
-import { FakeOptions, fake, objectWithIdComparisonFunction } from './core/core';
+import { FakeOptions, fake, checkUniqueObjectWithId } from './core/core';
import { randUser, User } from './user';
import { randUuid } from './uuid';
import { randText } from './text';
@@ -45,5 +45,5 @@ export function randPost(
return post;
};
- return fake(factory, options, objectWithIdComparisonFunction);
+ return fake(factory, options, checkUniqueObjectWithId);
}
diff --git a/packages/falso/src/lib/product.ts b/packages/falso/src/lib/product.ts
index 0db862e29..8b9a51212 100644
--- a/packages/falso/src/lib/product.ts
+++ b/packages/falso/src/lib/product.ts
@@ -2,7 +2,7 @@ import {
FakeOptions,
fake,
getRandomInRange,
- objectWithIdComparisonFunction,
+ checkUniqueObjectWithId,
} from './core/core';
import { randUuid } from './uuid';
import { randProductName } from './product-name';
@@ -53,5 +53,5 @@ export function randProduct(
},
});
- return fake(factory, options, objectWithIdComparisonFunction);
+ return fake(factory, options, checkUniqueObjectWithId);
}
diff --git a/packages/falso/src/lib/recent-date.ts b/packages/falso/src/lib/recent-date.ts
index 3736b1b40..f9db31f78 100644
--- a/packages/falso/src/lib/recent-date.ts
+++ b/packages/falso/src/lib/recent-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { dateComparisonFunction, fake, FakeOptions } from './core/core';
+import { checkUniqueDate, fake, FakeOptions } from './core/core';
interface RecentOptions extends FakeOptions {
days?: number;
@@ -36,9 +36,5 @@ export function randRecentDate(
const to = new Date();
const from = new Date(to.getTime() - daysInMilliseconds);
- return fake(
- () => randBetweenDate({ from, to }),
- options,
- dateComparisonFunction
- );
+ return fake(() => randBetweenDate({ from, to }), options, checkUniqueDate);
}
diff --git a/packages/falso/src/lib/soon-date.ts b/packages/falso/src/lib/soon-date.ts
index 6bd91c4c0..00bd32313 100644
--- a/packages/falso/src/lib/soon-date.ts
+++ b/packages/falso/src/lib/soon-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { dateComparisonFunction, fake, FakeOptions } from './core/core';
+import { checkUniqueDate, fake, FakeOptions } from './core/core';
interface SoonOptions extends FakeOptions {
days?: number;
@@ -35,9 +35,5 @@ export function randSoonDate(
const daysInMilliseconds = days * 24 * 60 * 60 * 1000;
const from = new Date();
const to = new Date(from.getTime() + daysInMilliseconds);
- return fake(
- () => randBetweenDate({ from, to }),
- options,
- dateComparisonFunction
- );
+ return fake(() => randBetweenDate({ from, to }), options, checkUniqueDate);
}
diff --git a/packages/falso/src/lib/superhero.ts b/packages/falso/src/lib/superhero.ts
index 050e8f184..4466008d7 100644
--- a/packages/falso/src/lib/superhero.ts
+++ b/packages/falso/src/lib/superhero.ts
@@ -1,7 +1,7 @@
import {
fake,
FakeOptions,
- objectWithIdComparisonFunction,
+ checkUniqueObjectWithId,
randElement,
} from './core/core';
import { data } from './superhero.json';
@@ -55,5 +55,5 @@ export function randSuperhero(
};
};
- return fake(factory, options, objectWithIdComparisonFunction);
+ return fake(factory, options, checkUniqueObjectWithId);
}
diff --git a/packages/falso/src/lib/todo.ts b/packages/falso/src/lib/todo.ts
index 3ae26779a..e227dbd6a 100644
--- a/packages/falso/src/lib/todo.ts
+++ b/packages/falso/src/lib/todo.ts
@@ -1,4 +1,4 @@
-import { fake, FakeOptions, objectWithIdComparisonFunction } from './core/core';
+import { fake, FakeOptions, checkUniqueObjectWithId } from './core/core';
import { randUuid } from './uuid';
import { randBoolean } from './boolean';
import { randText } from './text';
@@ -32,5 +32,5 @@ export function randTodo(
completed: randBoolean(),
});
- return fake(factory, options, objectWithIdComparisonFunction);
+ return fake(factory, options, checkUniqueObjectWithId);
}
diff --git a/packages/falso/src/lib/user.ts b/packages/falso/src/lib/user.ts
index 1e9fc7e6a..8a5746a1a 100644
--- a/packages/falso/src/lib/user.ts
+++ b/packages/falso/src/lib/user.ts
@@ -1,4 +1,4 @@
-import { fake, FakeOptions, objectWithIdComparisonFunction } from './core/core';
+import { fake, FakeOptions, checkUniqueObjectWithId } from './core/core';
import { randUuid } from './uuid';
import { randEmail } from './email';
import { randFirstName } from './first-name';
@@ -58,5 +58,5 @@ export function randUser(
return user;
};
- return fake(factory, options, objectWithIdComparisonFunction);
+ return fake(factory, options, checkUniqueObjectWithId);
}
diff --git a/packages/falso/src/tests/json.spec.ts b/packages/falso/src/tests/json.spec.ts
index 5c2f6260b..d0e6be211 100644
--- a/packages/falso/src/tests/json.spec.ts
+++ b/packages/falso/src/tests/json.spec.ts
@@ -1,5 +1,5 @@
-import { randNumber } from '../lib/number';
import { randJSON } from '../lib/json';
+import { randNumber } from '../lib/number';
describe('randJSON', () => {
describe('when it returns the expected values', () => {
@@ -26,28 +26,16 @@ describe('randJSON', () => {
});
describe('length is passed', () => {
- describe('length is 1', () => {
- it('should return an array length of 1', () => {
- const result = randJSON({ length: 1 });
-
- expect(result?.length).toEqual(1);
- });
- });
-
- describe('length is 5', () => {
- it('should return an array length of 5', () => {
- const result = randJSON({ length: 5 });
+ let length: number;
- expect(result?.length).toEqual(5);
- });
+ beforeEach(() => {
+ length = randNumber({ min: 1, max: 30, fraction: 1 });
});
- describe('length is 100', () => {
- it('should return an array length of 100', () => {
- const result = randJSON({ length: 100 });
+ it('should return an array length passed', () => {
+ const result = randJSON({ length });
- expect(result?.length).toEqual(100);
- });
+ expect(result?.length).toEqual(length);
});
});
});
From 6833592fd94df26cfda6339c817fa075f936aa92 Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Fri, 1 Apr 2022 18:47:13 +0100
Subject: [PATCH 08/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Add=20generic=20co?=
=?UTF-8?q?mparison=20function?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Add comparison function and start change over to using it
✅ Closes: #220
---
packages/falso/src/lib/between-date.ts | 4 +-
packages/falso/src/lib/core/core.ts | 45 ++++++--
packages/falso/src/lib/future-date.ts | 4 +-
packages/falso/src/lib/json.ts | 16 ++-
packages/falso/src/lib/past-date.ts | 4 +-
packages/falso/src/lib/recent-date.ts | 4 +-
packages/falso/src/lib/soon-date.ts | 4 +-
packages/falso/src/tests/core/core.spec.ts | 114 +++++++++++++++++++++
8 files changed, 173 insertions(+), 22 deletions(-)
create mode 100644 packages/falso/src/tests/core/core.spec.ts
diff --git a/packages/falso/src/lib/between-date.ts b/packages/falso/src/lib/between-date.ts
index 54af5cd16..baa46a352 100644
--- a/packages/falso/src/lib/between-date.ts
+++ b/packages/falso/src/lib/between-date.ts
@@ -1,4 +1,4 @@
-import { checkUniqueDate, fake, FakeOptions } from './core/core';
+import { dateIsUnique, fake, FakeOptions } from './core/core';
import { randNumber } from './number';
interface BetweenOptions extends FakeOptions {
@@ -39,5 +39,5 @@ export function randBetweenDate(
);
};
- return fake(generator, options, checkUniqueDate);
+ return fake(generator, options, dateIsUnique);
}
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index 8dfe72519..f728c9c53 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -14,18 +14,29 @@ type Return = [O] extends [never]
export function fake(
data: T[] | (() => T),
options?: Options,
- comparisonFunction: (item: T, items: T[]) => boolean = checkUniquePrimitive
+ comparisonFunction: (item: T, items: T[]) => boolean = primitiveValueIsUnique,
+ comparisonKeys?: string[]
): Return {
if (Array.isArray(data)) {
return fakeFromArray(data, options) as any;
}
- return fakeFromFunction(data, comparisonFunction, options) as any;
+ return fakeFromFunction(
+ data,
+ comparisonFunction,
+ comparisonKeys,
+ options
+ ) as any;
}
export function fakeFromFunction(
data: () => T,
- comparisonFunction: (item: T, items: T[]) => boolean,
+ isItemADuplicateFunction: (
+ item: T,
+ items: T[],
+ comparisonKeys?: string[]
+ ) => boolean,
+ comparisonKeys?: string[],
options?: Options
) {
if (!options?.length) {
@@ -46,7 +57,7 @@ export function fakeFromFunction(
while (items.length < options.length && attempts < maxAttempts) {
const item = data();
- if (!comparisonFunction(item, items)) {
+ if (!isItemADuplicateFunction(item, items, comparisonKeys)) {
items.push(item);
}
@@ -84,21 +95,39 @@ export function fakeFromArray(
return newArray;
}
-export const checkUniquePrimitive: (item: T, items: T[]) => boolean = (
+export const primitiveValueIsUnique: (item: T, items: T[]) => boolean = (
item,
items
-) => items.includes(item);
+) => !items.includes(item);
-export const checkUniqueDate: (date: Date, dates: Date[]) => boolean = (
+export const dateIsUnique: (date: Date, dates: Date[]) => boolean = (
date,
dates
-) => dates.some((d) => d.valueOf() === date.valueOf());
+) => !dates.some((d) => d.valueOf() === date.valueOf());
export const checkUniqueObjectWithId: (
item: T,
items: T[]
) => boolean = (item, items) => items.some((i) => i.id === item.id);
+export const objectIsUnique: (
+ item: any,
+ items: any[],
+ keys: string[]
+) => boolean = (item: any, items: any[], keys: string[]) => {
+ for (const key of keys) {
+ if (!item[key]) {
+ throw `${key} does not exist in this array value type`;
+ }
+
+ if (items.some((arrayItem) => arrayItem[key] === item[key])) {
+ return true;
+ }
+ }
+
+ return false;
+};
+
export function randElement(arr: T[]): T {
return arr[Math.floor(random() * arr.length)];
}
diff --git a/packages/falso/src/lib/future-date.ts b/packages/falso/src/lib/future-date.ts
index 12ed2259f..83218892b 100644
--- a/packages/falso/src/lib/future-date.ts
+++ b/packages/falso/src/lib/future-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { checkUniqueDate, fake, FakeOptions } from './core/core';
+import { dateIsUnique, fake, FakeOptions } from './core/core';
interface FutureOptions extends FakeOptions {
years?: number;
@@ -37,5 +37,5 @@ export function randFutureDate(
const to = new Date(from.getTime() + yearsInMilliseconds);
const factory: () => Date = () => randBetweenDate({ from, to });
- return fake(factory, options, checkUniqueDate);
+ return fake(factory, options, dateIsUnique);
}
diff --git a/packages/falso/src/lib/json.ts b/packages/falso/src/lib/json.ts
index 2aa7e5eca..8b9bbc75c 100644
--- a/packages/falso/src/lib/json.ts
+++ b/packages/falso/src/lib/json.ts
@@ -59,13 +59,21 @@ const generateRandomValue = (): any => {
* @example
* randJSON()
*
- * @example If a fixed number of keys are required
+ * @example
+ *
+ * randJSON({ totalKeys: 10 }) // If a fixed number of keys are required
+ *
+ * @example
*
- * randJSON({ totalKeys: 10 })
+ * randJSON({ minKeys: 1, maxKeys: 10 }) // If a random number of keys are required
*
- * @example If a random number of keys are required
+ * @example
+ *
+ * randJSON({ length: 10 })
+ *
+ * @example
*
- * randJSON({ minKeys: 1, maxKeys: 10 })
+ * randJSON({ length: 10, priority: 'length' })
*
*/
export function randJSON(
diff --git a/packages/falso/src/lib/past-date.ts b/packages/falso/src/lib/past-date.ts
index b36cb79f7..ae168b160 100644
--- a/packages/falso/src/lib/past-date.ts
+++ b/packages/falso/src/lib/past-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { checkUniqueDate, fake, FakeOptions } from './core/core';
+import { dateIsUnique, fake, FakeOptions } from './core/core';
interface PastOptions extends FakeOptions {
years?: number;
@@ -36,5 +36,5 @@ export function randPastDate(
const to = new Date();
const from = new Date(to.getTime() - yearsInMilliseconds);
- return fake(() => randBetweenDate({ from, to }), options, checkUniqueDate);
+ return fake(() => randBetweenDate({ from, to }), options, dateIsUnique);
}
diff --git a/packages/falso/src/lib/recent-date.ts b/packages/falso/src/lib/recent-date.ts
index f9db31f78..2c87dd62b 100644
--- a/packages/falso/src/lib/recent-date.ts
+++ b/packages/falso/src/lib/recent-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { checkUniqueDate, fake, FakeOptions } from './core/core';
+import { dateIsUnique, fake, FakeOptions } from './core/core';
interface RecentOptions extends FakeOptions {
days?: number;
@@ -36,5 +36,5 @@ export function randRecentDate(
const to = new Date();
const from = new Date(to.getTime() - daysInMilliseconds);
- return fake(() => randBetweenDate({ from, to }), options, checkUniqueDate);
+ return fake(() => randBetweenDate({ from, to }), options, dateIsUnique);
}
diff --git a/packages/falso/src/lib/soon-date.ts b/packages/falso/src/lib/soon-date.ts
index 00bd32313..7eea8e55a 100644
--- a/packages/falso/src/lib/soon-date.ts
+++ b/packages/falso/src/lib/soon-date.ts
@@ -1,5 +1,5 @@
import { randBetweenDate } from './between-date';
-import { checkUniqueDate, fake, FakeOptions } from './core/core';
+import { dateIsUnique, fake, FakeOptions } from './core/core';
interface SoonOptions extends FakeOptions {
days?: number;
@@ -35,5 +35,5 @@ export function randSoonDate(
const daysInMilliseconds = days * 24 * 60 * 60 * 1000;
const from = new Date();
const to = new Date(from.getTime() + daysInMilliseconds);
- return fake(() => randBetweenDate({ from, to }), options, checkUniqueDate);
+ return fake(() => randBetweenDate({ from, to }), options, dateIsUnique);
}
diff --git a/packages/falso/src/tests/core/core.spec.ts b/packages/falso/src/tests/core/core.spec.ts
new file mode 100644
index 000000000..254d1570e
--- /dev/null
+++ b/packages/falso/src/tests/core/core.spec.ts
@@ -0,0 +1,114 @@
+import { objectIsUnique } from '../../lib/core/core';
+import { randUser, User } from '../../lib/user';
+import { randUuid } from '../../lib/uuid';
+import { randFirstName } from '../../lib/first-name';
+
+describe('valueExistsInObjectArray', () => {
+ describe("keys contains a key that doesn't exist", () => {
+ let array: User[];
+ let newItem: User;
+ let keys: string[];
+
+ beforeEach(() => {
+ array = randUser({ length: 3 });
+ newItem = randUser();
+ keys = ['id', 'noExistentKey', 'firstName'];
+ });
+
+ it('should throw error', () => {
+ expect(() => objectIsUnique(newItem, array, keys)).toThrow(
+ 'noExistentKey does not exist in this array value type'
+ );
+ });
+ });
+
+ describe('1 key is passed', () => {
+ let array: User[];
+ let newItem: User;
+ let keys: string[];
+
+ beforeEach(() => {
+ array = randUser({ length: 3 });
+ newItem = randUser();
+ keys = ['id'];
+ });
+
+ describe('passed item matches and array item have 1 matching key value', () => {
+ let sharedId: string;
+
+ beforeEach(() => {
+ sharedId = randUuid();
+ newItem.id = sharedId;
+ array[1].id = sharedId;
+ });
+
+ it('should return true', () => {
+ const result = objectIsUnique(newItem, array, keys);
+
+ expect(result).toEqual(true);
+ });
+ });
+
+ describe('passed item matches and array item have 0 matching key values', () => {
+ beforeEach(() => {
+ array[0].id = randUuid() + '0';
+ array[1].id = randUuid() + '1';
+ array[2].id = randUuid() + '2';
+ newItem.id = randUuid() + '3';
+ });
+
+ it('should return true', () => {
+ const result = objectIsUnique(newItem, array, keys);
+
+ expect(result).toEqual(false);
+ });
+ });
+ });
+
+ describe('multiple keys are passed', () => {
+ let array: User[];
+ let newItem: User;
+ let keys: string[];
+
+ beforeEach(() => {
+ array = randUser({ length: 3 });
+ newItem = randUser();
+ keys = ['id', 'firstName'];
+ });
+
+ describe('passed item matches and array item have 1 matching key value', () => {
+ let sharedFirstName: string;
+
+ beforeEach(() => {
+ sharedFirstName = randFirstName();
+ newItem.firstName = sharedFirstName;
+ array[1].firstName = sharedFirstName;
+ });
+
+ it('should return true', () => {
+ const result = objectIsUnique(newItem, array, keys);
+
+ expect(result).toEqual(true);
+ });
+ });
+
+ describe('passed item matches and array item have 0 matching key values', () => {
+ beforeEach(() => {
+ array[0].id = randUuid() + '0';
+ array[0].firstName = randFirstName() + '0';
+ array[1].id = randUuid() + '1';
+ array[1].id = randFirstName() + '1';
+ array[2].id = randUuid() + '2';
+ array[2].id = randFirstName() + '2';
+ newItem.id = randUuid() + '3';
+ newItem.id = randFirstName() + '3';
+ });
+
+ it('should return true', () => {
+ const result = objectIsUnique(newItem, array, keys);
+
+ expect(result).toEqual(false);
+ });
+ });
+ });
+});
From 13998f6423ee41c85fa5680424a495909dbe3cf5 Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Mon, 4 Apr 2022 20:23:13 +0100
Subject: [PATCH 09/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Replace=20duplicat?=
=?UTF-8?q?e=20checkUnique=20logic=20with=20objectIsUnique?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
✅ Closes: #220
---
packages/falso/src/lib/address.ts | 10 +++++-----
packages/falso/src/lib/core/core.ts | 2 +-
packages/falso/src/lib/credit-card.ts | 9 +++++----
packages/falso/src/lib/flight-details.ts | 15 ++++++++-------
4 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/packages/falso/src/lib/address.ts b/packages/falso/src/lib/address.ts
index f1984c89c..bb5c86fee 100644
--- a/packages/falso/src/lib/address.ts
+++ b/packages/falso/src/lib/address.ts
@@ -1,4 +1,4 @@
-import { FakeOptions, fake } from './core/core';
+import { FakeOptions, fake, objectIsUnique } from './core/core';
import { randCity } from './city';
import { randStreetAddress } from './street-address';
import { randZipCode } from './zip-code';
@@ -67,7 +67,7 @@ export function randAddress(
return fake(factory, options, checkUnique);
}
-const checkUnique: (item: Address, items: Address[]) => boolean = (
- item: Address,
- items: Address[]
-) => items.some((i) => i.street + i.zipCode === item.street + item.zipCode);
+const checkUnique: (address: Address, addresses: Address[]) => boolean = (
+ address: Address,
+ addresses: Address[]
+) => objectIsUnique(address, addresses, ['street', 'zipCode']);
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index f728c9c53..e1d3be94d 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -108,7 +108,7 @@ export const dateIsUnique: (date: Date, dates: Date[]) => boolean = (
export const checkUniqueObjectWithId: (
item: T,
items: T[]
-) => boolean = (item, items) => items.some((i) => i.id === item.id);
+) => boolean = (item, items) => objectIsUnique(item, items, ['id']);
export const objectIsUnique: (
item: any,
diff --git a/packages/falso/src/lib/credit-card.ts b/packages/falso/src/lib/credit-card.ts
index 566b71583..cbba1588c 100644
--- a/packages/falso/src/lib/credit-card.ts
+++ b/packages/falso/src/lib/credit-card.ts
@@ -1,4 +1,4 @@
-import { fake, FakeOptions } from './core/core';
+import { fake, FakeOptions, objectIsUnique } from './core/core';
import { randCreditCardCVV } from './credit-card-cvv';
import { randCreditCardBrand } from './credit-card-brand';
import { Brand, randCreditCardNumber } from './credit-card-number';
@@ -8,6 +8,7 @@ import { rand } from './rand';
import { randPastDate } from './past-date';
import { randFutureDate } from './future-date';
import { randPersonTitle } from './person-title';
+import { Address } from './address';
export interface CreditCardOptions extends FakeOptions {
fullName?: string;
@@ -85,6 +86,6 @@ export function randCreditCard(
}
const checkUnique: (card: CreditCard, cards: CreditCard[]) => boolean = (
- card,
- cards
-) => cards.some((c) => c.number === card.number);
+ card: CreditCard,
+ cards: CreditCard[]
+) => objectIsUnique(card, cards, ['number']);
diff --git a/packages/falso/src/lib/flight-details.ts b/packages/falso/src/lib/flight-details.ts
index 37aa40ed5..300aa1bb7 100644
--- a/packages/falso/src/lib/flight-details.ts
+++ b/packages/falso/src/lib/flight-details.ts
@@ -1,4 +1,9 @@
-import { fake, FakeOptions, getRandomInRange } from './core/core';
+import {
+ fake,
+ FakeOptions,
+ getRandomInRange,
+ objectIsUnique,
+} from './core/core';
import { randFutureDate } from './future-date';
import { randAirline } from './airline';
import { Airline, randFlightNumber } from './flight-number';
@@ -78,9 +83,5 @@ export function randFlightDetails(
const checkUnique: (
flight: FlightDetails,
flights: FlightDetails[]
-) => boolean = (flight, flights) =>
- flights.some(
- (f) =>
- f.passenger + f.flightNumber + f.date ===
- flight.passenger + flight.flightNumber + flight.date
- );
+) => boolean = (flight: FlightDetails, flights: FlightDetails[]) =>
+ objectIsUnique(flight, flights, ['passenger', 'flightNumber', 'date']);
From 717bb7d5428ec4e9ae2653bd1dbd46b01c8476a7 Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Mon, 4 Apr 2022 20:26:39 +0100
Subject: [PATCH 10/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Fix=20function=20n?=
=?UTF-8?q?ame.=20Update=20file=20name?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/tests/core/{core.spec.ts => object-is-unique.spec.ts} | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename packages/falso/src/tests/core/{core.spec.ts => object-is-unique.spec.ts} (98%)
diff --git a/packages/falso/src/tests/core/core.spec.ts b/packages/falso/src/tests/core/object-is-unique.spec.ts
similarity index 98%
rename from packages/falso/src/tests/core/core.spec.ts
rename to packages/falso/src/tests/core/object-is-unique.spec.ts
index 254d1570e..ad26ab480 100644
--- a/packages/falso/src/tests/core/core.spec.ts
+++ b/packages/falso/src/tests/core/object-is-unique.spec.ts
@@ -3,7 +3,7 @@ import { randUser, User } from '../../lib/user';
import { randUuid } from '../../lib/uuid';
import { randFirstName } from '../../lib/first-name';
-describe('valueExistsInObjectArray', () => {
+describe('objectIsUnique', () => {
describe("keys contains a key that doesn't exist", () => {
let array: User[];
let newItem: User;
From 660f53a991532940d2da314e38d05f890c133443 Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Mon, 4 Apr 2022 20:30:37 +0100
Subject: [PATCH 11/34] =?UTF-8?q?test:=20=F0=9F=A5=B3=20Move=20error=20to?=
=?UTF-8?q?=20snapshot?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../tests/core/__snapshots__/object-is-unique.spec.ts.snap | 3 +++
packages/falso/src/tests/core/object-is-unique.spec.ts | 6 +++---
2 files changed, 6 insertions(+), 3 deletions(-)
create mode 100644 packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap
diff --git a/packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap b/packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap
new file mode 100644
index 000000000..592ad4ac0
--- /dev/null
+++ b/packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap
@@ -0,0 +1,3 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`objectIsUnique keys contains a key that doesn't exist should throw error 1`] = `undefined`;
diff --git a/packages/falso/src/tests/core/object-is-unique.spec.ts b/packages/falso/src/tests/core/object-is-unique.spec.ts
index ad26ab480..d70e2fa5f 100644
--- a/packages/falso/src/tests/core/object-is-unique.spec.ts
+++ b/packages/falso/src/tests/core/object-is-unique.spec.ts
@@ -16,9 +16,9 @@ describe('objectIsUnique', () => {
});
it('should throw error', () => {
- expect(() => objectIsUnique(newItem, array, keys)).toThrow(
- 'noExistentKey does not exist in this array value type'
- );
+ expect(() =>
+ objectIsUnique(newItem, array, keys)
+ ).toThrowErrorMatchingSnapshot();
});
});
From 42a54d4f71dd4b844be7b41636a84bd08fa5b14f Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Tue, 5 Apr 2022 19:03:28 +0100
Subject: [PATCH 12/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Fix=20snapshot?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fix snapshot error. Ensure all thrown errors throw actual errors rather
than strings
✅ Closes: #220
---
packages/falso/src/lib/core/core.ts | 2 +-
packages/falso/src/lib/food.ts | 4 ++--
packages/falso/src/lib/line.ts | 2 +-
packages/falso/src/lib/sports.ts | 2 +-
packages/falso/src/lib/text.ts | 2 +-
.../tests/core/__snapshots__/object-is-unique.spec.ts.snap | 2 +-
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index e1d3be94d..e5e4eef74 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -117,7 +117,7 @@ export const objectIsUnique: (
) => boolean = (item: any, items: any[], keys: string[]) => {
for (const key of keys) {
if (!item[key]) {
- throw `${key} does not exist in this array value type`;
+ throw new Error(`${key} does not exist in this array value type`);
}
if (items.some((arrayItem) => arrayItem[key] === item[key])) {
diff --git a/packages/falso/src/lib/food.ts b/packages/falso/src/lib/food.ts
index 36759a30e..015e7a0f7 100644
--- a/packages/falso/src/lib/food.ts
+++ b/packages/falso/src/lib/food.ts
@@ -52,11 +52,11 @@ export function randFood(
const origin: string | undefined = options?.origin;
if (!totalOrigins) {
- throw 'No foods found';
+ throw new Error('No foods found');
}
if (origin && !foodData[origin]) {
- throw 'No foods found for selected origin';
+ throw Error('No foods found for selected origin');
}
const factory: () => string = () => {
diff --git a/packages/falso/src/lib/line.ts b/packages/falso/src/lib/line.ts
index 42ff0ab99..c214c256a 100644
--- a/packages/falso/src/lib/line.ts
+++ b/packages/falso/src/lib/line.ts
@@ -25,7 +25,7 @@ export function randLine(
const lineCount: number = options?.lineCount ?? 5;
if (lineCount < 1 || isNaN(lineCount)) {
- throw 'Line count must be greater than 0';
+ throw Error('Line count must be greater than 0');
}
const factory = () => {
diff --git a/packages/falso/src/lib/sports.ts b/packages/falso/src/lib/sports.ts
index 41581d905..d4e04cbfb 100644
--- a/packages/falso/src/lib/sports.ts
+++ b/packages/falso/src/lib/sports.ts
@@ -33,7 +33,7 @@ export function randSports(
const category: string | undefined = options?.category;
if (!categoriesCount) {
- throw 'No Sport Categories found';
+ throw Error('No Sport Categories found');
}
if (category && !sportsData[category]) {
diff --git a/packages/falso/src/lib/text.ts b/packages/falso/src/lib/text.ts
index e8d1dc3e6..42fb53fa7 100644
--- a/packages/falso/src/lib/text.ts
+++ b/packages/falso/src/lib/text.ts
@@ -30,7 +30,7 @@ export function randText(
const charCount: number = options?.charCount ?? 10;
if (charCount < 1 || isNaN(charCount)) {
- throw 'Character count must be greater than 0';
+ throw new Error('Character count must be greater than 0');
}
const factory = () => {
diff --git a/packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap b/packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap
index 592ad4ac0..c3e55400d 100644
--- a/packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap
+++ b/packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`objectIsUnique keys contains a key that doesn't exist should throw error 1`] = `undefined`;
+exports[`objectIsUnique keys contains a key that doesn't exist should throw error 1`] = `"noExistentKey does not exist in this array value type"`;
From 0ec65bea26ca4899c16487080bb9b4b007af6808 Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Tue, 5 Apr 2022 19:40:37 +0100
Subject: [PATCH 13/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Move=20snapshots?=
=?UTF-8?q?=20folder=20to=20tests/=20route?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/falso/jest.config.js | 1 +
packages/falso/snapshot-resolver.js | 11 +++++++++++
.../core}/object-is-unique.spec.ts.snap | 0
packages/falso/src/tests/text-range.spec.ts | 2 +-
4 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 packages/falso/snapshot-resolver.js
rename packages/falso/src/tests/{core/__snapshots__ => __snapshots__/core}/object-is-unique.spec.ts.snap (100%)
diff --git a/packages/falso/jest.config.js b/packages/falso/jest.config.js
index 81b9239e3..c5930a5fb 100644
--- a/packages/falso/jest.config.js
+++ b/packages/falso/jest.config.js
@@ -12,4 +12,5 @@ module.exports = {
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/falso',
+ snapshotResolver: "./snapshot-resolver.js"
};
diff --git a/packages/falso/snapshot-resolver.js b/packages/falso/snapshot-resolver.js
new file mode 100644
index 000000000..d37877caf
--- /dev/null
+++ b/packages/falso/snapshot-resolver.js
@@ -0,0 +1,11 @@
+module.exports = {
+ testPathForConsistencyCheck: 'some/tests/example.spec.ts',
+ resolveSnapshotPath: (testPath, snapshotExtension) => {
+ return testPath.replace('tests/', 'tests/__snapshots__/') + snapshotExtension
+ },
+ resolveTestPath: (snapshotFilePath, snapshotExtension) => {
+ return snapshotFilePath
+ .replace('tests/__snapshots__/', 'tests/')
+ .slice(0, -snapshotExtension.length)
+ },
+}
diff --git a/packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap b/packages/falso/src/tests/__snapshots__/core/object-is-unique.spec.ts.snap
similarity index 100%
rename from packages/falso/src/tests/core/__snapshots__/object-is-unique.spec.ts.snap
rename to packages/falso/src/tests/__snapshots__/core/object-is-unique.spec.ts.snap
diff --git a/packages/falso/src/tests/text-range.spec.ts b/packages/falso/src/tests/text-range.spec.ts
index a0eeafcbf..6e72cc241 100644
--- a/packages/falso/src/tests/text-range.spec.ts
+++ b/packages/falso/src/tests/text-range.spec.ts
@@ -14,7 +14,7 @@ describe('randTextRange', () => {
it('should return string of length between min and max', () => {
const result = randTextRange({ min, max });
- expect(result.length).toBeGreaterThan(min);
+ expect(result.length).toBeGreaterThanOrEqual(min);
expect(result.length).toBeLessThanOrEqual(max);
});
});
From ff6980a9f1254c78d2615dbd3c53a4f193c9d900 Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Tue, 5 Apr 2022 19:58:25 +0100
Subject: [PATCH 14/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Clean=20up=20core?=
=?UTF-8?q?=20file?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/falso/src/lib/core/core.ts | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts
index e5e4eef74..1a257392e 100644
--- a/packages/falso/src/lib/core/core.ts
+++ b/packages/falso/src/lib/core/core.ts
@@ -38,7 +38,7 @@ export function fakeFromFunction(
) => boolean,
comparisonKeys?: string[],
options?: Options
-) {
+): T | T[] {
if (!options?.length) {
return data();
}
@@ -70,7 +70,7 @@ export function fakeFromFunction(
export function fakeFromArray(
data: T[],
options?: Options
-) {
+): T | T[] {
if (!options?.length) {
return randElement(data);
}
@@ -85,7 +85,10 @@ export function fakeFromArray(
const newArray: T[] = [];
while (clonedData.length && newArray.length !== options.length) {
- const randomIndex = Math.floor(random() * clonedData.length);
+ const randomIndex = getRandomInRange({
+ min: 0,
+ max: clonedData.length - 1,
+ });
const item = clonedData[randomIndex];
newArray.push(item);
From d57bd2592e8ca8fdcd25af7ba7a1a0a4f5c979dd Mon Sep 17 00:00:00 2001
From: Ryan Smee
Date: Tue, 5 Apr 2022 20:45:22 +0100
Subject: [PATCH 15/34] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Add=20missing=20pr?=
=?UTF-8?q?iority=20doc=20comment?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Add missing priority doc comment
✅ Closes: #220
---
packages/falso/src/lib/abbreviation.ts | 4 ++++
packages/falso/src/lib/accessory.ts | 4 ++++
packages/falso/src/lib/account.ts | 4 ++++
packages/falso/src/lib/address.ts | 4 ++++
packages/falso/src/lib/airline.ts | 4 ++++
packages/falso/src/lib/airport-code.ts | 4 ++++
packages/falso/src/lib/airport-name.ts | 4 ++++
packages/falso/src/lib/airport.ts | 4 ++++
packages/falso/src/lib/alpha-numeric.ts | 4 ++++
packages/falso/src/lib/alpha.ts | 4 ++++
packages/falso/src/lib/american-football-team.ts | 4 ++++
packages/falso/src/lib/animal-type.ts | 4 ++++
packages/falso/src/lib/arn.ts | 4 ++++
packages/falso/src/lib/avatar.ts | 6 +++++-
packages/falso/src/lib/aws-region.ts | 4 ++++
packages/falso/src/lib/aws-request-id.ts | 4 ++++
packages/falso/src/lib/aws-service.ts | 4 ++++
packages/falso/src/lib/baseball-team.ts | 4 ++++
packages/falso/src/lib/basketball-team.ts | 4 ++++
packages/falso/src/lib/bear.ts | 4 ++++
packages/falso/src/lib/between-date.ts | 4 ++++
packages/falso/src/lib/binary.ts | 4 ++++
packages/falso/src/lib/bird.ts | 4 ++++
packages/falso/src/lib/bitcoin-address.ts | 4 ++++
packages/falso/src/lib/book.ts | 6 +++++-
packages/falso/src/lib/boolean.ts | 4 ++++
packages/falso/src/lib/brand.ts | 4 ++++
packages/falso/src/lib/browser.ts | 4 ++++
packages/falso/src/lib/cardinal-direction.ts | 4 ++++
packages/falso/src/lib/cat.ts | 4 ++++
packages/falso/src/lib/catch-phrase.ts | 4 ++++
packages/falso/src/lib/cetacean.ts | 4 ++++
packages/falso/src/lib/city.ts | 4 ++++
packages/falso/src/lib/clothing-size.ts | 4 ++++
packages/falso/src/lib/code-snippet.ts | 6 +++++-
packages/falso/src/lib/color.ts | 4 ++++
packages/falso/src/lib/company-name.ts | 4 ++++
packages/falso/src/lib/country-code.ts | 4 ++++
packages/falso/src/lib/country.ts | 4 ++++
packages/falso/src/lib/county.ts | 4 ++++
packages/falso/src/lib/cow.ts | 4 ++++
packages/falso/src/lib/credit-card-brand.ts | 4 ++++
packages/falso/src/lib/credit-card-cvv.ts | 4 ++++
packages/falso/src/lib/credit-card-number.ts | 4 ++++
packages/falso/src/lib/credit-card.ts | 5 ++++-
packages/falso/src/lib/crocodilia.ts | 4 ++++
packages/falso/src/lib/currency-code.ts | 4 ++++
packages/falso/src/lib/currency-name.ts | 4 ++++
packages/falso/src/lib/currency-symbol.ts | 4 ++++
packages/falso/src/lib/database-collation.ts | 4 ++++
packages/falso/src/lib/database-column.ts | 4 ++++
packages/falso/src/lib/database-engine.ts | 4 ++++
packages/falso/src/lib/database-type.ts | 4 ++++
packages/falso/src/lib/department.ts | 4 ++++
packages/falso/src/lib/direction.ts | 4 ++++
packages/falso/src/lib/directory-path.ts | 4 ++++
packages/falso/src/lib/dog.ts | 4 ++++
packages/falso/src/lib/domain-name.ts | 4 ++++
packages/falso/src/lib/domain-suffix.ts | 4 ++++
packages/falso/src/lib/drinks.ts | 4 ++++
packages/falso/src/lib/email-provider.ts | 4 ++++
packages/falso/src/lib/email.ts | 11 +++++++----
packages/falso/src/lib/emoji.ts | 4 ++++
packages/falso/src/lib/ethereum-address.ts | 4 ++++
packages/falso/src/lib/file-ext.ts | 4 ++++
packages/falso/src/lib/file-name.ts | 4 ++++
packages/falso/src/lib/file-path.ts | 4 ++++
packages/falso/src/lib/file-type.ts | 4 ++++
packages/falso/src/lib/first-name.ts | 4 ++++
packages/falso/src/lib/fish.ts | 4 ++++
packages/falso/src/lib/flight-details.ts | 5 ++++-
packages/falso/src/lib/flight-number.ts | 4 ++++
packages/falso/src/lib/float.ts | 11 ++++++++---
packages/falso/src/lib/font-family.ts | 4 ++++
packages/falso/src/lib/font-size.ts | 4 ++++
packages/falso/src/lib/food.ts | 4 ++++
packages/falso/src/lib/football-team.ts | 4 ++++
packages/falso/src/lib/frequency.ts | 4 ++++
packages/falso/src/lib/full-address.ts | 4 ++++
packages/falso/src/lib/full-name.ts | 4 ++++
packages/falso/src/lib/future-date.ts | 6 +++++-
packages/falso/src/lib/gender.ts | 6 +++++-
packages/falso/src/lib/git-branch.ts | 4 ++++
packages/falso/src/lib/git-commit-entry.ts | 4 ++++
packages/falso/src/lib/git-commit-message.ts | 4 ++++
packages/falso/src/lib/git-commit-sha.ts | 4 ++++
packages/falso/src/lib/git-short-sha.ts | 4 ++++
packages/falso/src/lib/hex.ts | 4 ++++
packages/falso/src/lib/hexa-decimal.ts | 4 ++++
packages/falso/src/lib/horse.ts | 4 ++++
packages/falso/src/lib/hsl.ts | 6 +++++-
packages/falso/src/lib/http-method.ts | 4 ++++
packages/falso/src/lib/iban.ts | 4 ++++
packages/falso/src/lib/ice-hockey-team.ts | 4 ++++
packages/falso/src/lib/img.ts | 4 ++++
packages/falso/src/lib/integration.ts | 4 ++++
packages/falso/src/lib/ip.ts | 4 ++++
packages/falso/src/lib/ipv6.ts | 4 ++++
packages/falso/src/lib/job-area.ts | 4 ++++
packages/falso/src/lib/job-descriptor.ts | 4 ++++
packages/falso/src/lib/job-title.ts | 4 ++++
packages/falso/src/lib/job-type.ts | 4 ++++
packages/falso/src/lib/json.ts | 2 +-
packages/falso/src/lib/language.ts | 6 +++++-
packages/falso/src/lib/last-name.ts | 4 ++++
packages/falso/src/lib/latitude.ts | 4 ++++
packages/falso/src/lib/line.ts | 4 ++++
packages/falso/src/lib/lines.ts | 4 ++++
packages/falso/src/lib/lion.ts | 4 ++++
packages/falso/src/lib/locale.ts | 4 ++++
packages/falso/src/lib/longitude.ts | 4 ++++
packages/falso/src/lib/mac.ts | 4 ++++
packages/falso/src/lib/mask.ts | 4 ++++
packages/falso/src/lib/mime-type.ts | 4 ++++
packages/falso/src/lib/month.ts | 4 ++++
packages/falso/src/lib/movie-character.ts | 4 ++++
packages/falso/src/lib/movie.ts | 4 ++++
packages/falso/src/lib/music-genre.ts | 4 ++++
packages/falso/src/lib/nearby-gpscoordinate.ts | 4 ++++
packages/falso/src/lib/number.ts | 13 +++++++++----
packages/falso/src/lib/oauth-provider.ts | 4 ++++
packages/falso/src/lib/octal.ts | 6 +++++-
packages/falso/src/lib/ordinal-direction.ts | 4 ++++
packages/falso/src/lib/paragraph.ts | 8 ++++++--
packages/falso/src/lib/password.ts | 6 +++++-
packages/falso/src/lib/past-date.ts | 6 +++++-
packages/falso/src/lib/permission.ts | 6 +++++-
packages/falso/src/lib/person-title.ts | 4 ++++
packages/falso/src/lib/phone-number.ts | 4 ++++
packages/falso/src/lib/phrase.ts | 4 ++++
packages/falso/src/lib/port.ts | 4 ++++
packages/falso/src/lib/post.ts | 4 ++++
packages/falso/src/lib/priority.ts | 4 ++++
packages/falso/src/lib/product-adjective.ts | 4 ++++
packages/falso/src/lib/product-category.ts | 4 ++++
packages/falso/src/lib/product-description.ts | 4 ++++
packages/falso/src/lib/product-material.ts | 4 ++++
packages/falso/src/lib/product-name.ts | 4 ++++
packages/falso/src/lib/product.ts | 4 ++++
packages/falso/src/lib/programming-language.ts | 4 ++++
packages/falso/src/lib/pronoun.ts | 8 ++++++++
packages/falso/src/lib/protocol.ts | 6 +++++-
packages/falso/src/lib/quote.ts | 4 ++++
packages/falso/src/lib/rabbit.ts | 4 ++++
packages/falso/src/lib/rand.ts | 4 ++++
packages/falso/src/lib/recent-date.ts | 4 ++++
packages/falso/src/lib/rgb.ts | 4 ++++
packages/falso/src/lib/role.ts | 4 ++++
packages/falso/src/lib/routing-number.ts | 4 ++++
packages/falso/src/lib/seat-number.ts | 4 ++++
packages/falso/src/lib/semver.ts | 6 +++++-
packages/falso/src/lib/sentence.ts | 4 ++++
packages/falso/src/lib/sequence.ts | 4 ++++
packages/falso/src/lib/shape.ts | 4 ++++
packages/falso/src/lib/singer.ts | 4 ++++
packages/falso/src/lib/skill.ts | 4 ++++
packages/falso/src/lib/slug.ts | 4 ++++
packages/falso/src/lib/snake.ts | 4 ++++
packages/falso/src/lib/social.ts | 4 ++++
packages/falso/src/lib/song.ts | 4 ++++
packages/falso/src/lib/soon-date.ts | 4 ++++
packages/falso/src/lib/sports-team.ts | 4 ++++
packages/falso/src/lib/sports.ts | 4 ++++
packages/falso/src/lib/state-abbr.ts | 4 ++++
packages/falso/src/lib/state.ts | 4 ++++
packages/falso/src/lib/status.ts | 4 ++++
packages/falso/src/lib/street-address.ts | 4 ++++
packages/falso/src/lib/street-name.ts | 4 ++++
packages/falso/src/lib/subscription-plan.ts | 4 ++++
packages/falso/src/lib/superhero-name.ts | 4 ++++
packages/falso/src/lib/superhero.ts | 4 ++++
packages/falso/src/lib/svg.ts | 4 ++++
packages/falso/src/lib/text-range.ts | 4 ++++
packages/falso/src/lib/text.ts | 6 +++++-
packages/falso/src/lib/time-zone.ts | 4 ++++
packages/falso/src/lib/todo.ts | 4 ++++
packages/falso/src/lib/transaction-type.ts | 4 ++++
packages/falso/src/lib/url.ts | 4 ++++
packages/falso/src/lib/user-agent.ts | 4 ++++
packages/falso/src/lib/user-name.ts | 10 +++++++---
packages/falso/src/lib/user.ts | 4 ++++
packages/falso/src/lib/uuid.ts | 4 ++++
packages/falso/src/lib/vehicle-fuel.ts | 4 ++++
packages/falso/src/lib/vehicle-manufacturer.ts | 4 ++++
packages/falso/src/lib/vehicle-model.ts | 4 ++++
packages/falso/src/lib/vehicle-type.ts | 4 ++++
packages/falso/src/lib/vehicle.ts | 4 ++++
packages/falso/src/lib/verb.ts | 4 ++++
packages/falso/src/lib/weekday.ts | 4 ++++
packages/falso/src/lib/word.ts | 4 ++++
packages/falso/src/lib/zip-code.ts | 4 ++++
packages/falso/src/{lib => tests}/user-name.spec.ts | 0
192 files changed, 796 insertions(+), 33 deletions(-)
rename packages/falso/src/{lib => tests}/user-name.spec.ts (100%)
diff --git a/packages/falso/src/lib/abbreviation.ts b/packages/falso/src/lib/abbreviation.ts
index 385cf873f..bb55eae2d 100644
--- a/packages/falso/src/lib/abbreviation.ts
+++ b/packages/falso/src/lib/abbreviation.ts
@@ -14,6 +14,10 @@ import { data } from './abbreviation.json';
*
* randAbbreviation({ length: 10 })
*
+ * @example
+ *
+ * randAbbreviation({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAbbreviation(options?: O) {
return fake(data, options);
diff --git a/packages/falso/src/lib/accessory.ts b/packages/falso/src/lib/accessory.ts
index fb9eae78d..bf9be5a6a 100644
--- a/packages/falso/src/lib/accessory.ts
+++ b/packages/falso/src/lib/accessory.ts
@@ -14,6 +14,10 @@ import { data } from './accessory.json';
*
* randAccessory({ length: 10 })
*
+ * @example
+ *
+ * randAccessory({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAccessory(
options?: Options
diff --git a/packages/falso/src/lib/account.ts b/packages/falso/src/lib/account.ts
index 839d89f07..3873b773a 100644
--- a/packages/falso/src/lib/account.ts
+++ b/packages/falso/src/lib/account.ts
@@ -21,6 +21,10 @@ export interface AccountOptions extends FakeOptions {
*
* randAccount({ length: 10 })
*
+ * @example
+ *
+ * randAccount({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAccount(
options?: Options
diff --git a/packages/falso/src/lib/address.ts b/packages/falso/src/lib/address.ts
index bb5c86fee..2c7a117de 100644
--- a/packages/falso/src/lib/address.ts
+++ b/packages/falso/src/lib/address.ts
@@ -39,6 +39,10 @@ export interface Address {
*
* randAddress({ length: 10 })
*
+ * @example
+ *
+ * randAddress({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAddress(
options?: Options
diff --git a/packages/falso/src/lib/airline.ts b/packages/falso/src/lib/airline.ts
index 9b37efdb8..6ec1aad08 100644
--- a/packages/falso/src/lib/airline.ts
+++ b/packages/falso/src/lib/airline.ts
@@ -14,6 +14,10 @@ import { data } from './airline.json';
*
* randAirline({ length: 10 })
*
+ * @example
+ *
+ * randAirline({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAirline(
options?: Options
diff --git a/packages/falso/src/lib/airport-code.ts b/packages/falso/src/lib/airport-code.ts
index c3aa0854c..c083277b6 100644
--- a/packages/falso/src/lib/airport-code.ts
+++ b/packages/falso/src/lib/airport-code.ts
@@ -15,6 +15,10 @@ import { rand } from './rand';
*
* randAirportCode({ length: 10 })
*
+ * @example
+ *
+ * randAirportCode({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAirportCode(
options?: Options
diff --git a/packages/falso/src/lib/airport-name.ts b/packages/falso/src/lib/airport-name.ts
index c81461b5c..b8b14be65 100644
--- a/packages/falso/src/lib/airport-name.ts
+++ b/packages/falso/src/lib/airport-name.ts
@@ -15,6 +15,10 @@ import { rand } from './rand';
*
* randAirportName({ length: 10 })
*
+ * @example
+ *
+ * randAirportName({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAirportName(
options?: Options
diff --git a/packages/falso/src/lib/airport.ts b/packages/falso/src/lib/airport.ts
index fac0e177f..143153770 100644
--- a/packages/falso/src/lib/airport.ts
+++ b/packages/falso/src/lib/airport.ts
@@ -21,6 +21,10 @@ export interface Airport {
*
* randAirport({ length: 10 })
*
+ * @example
+ *
+ * randAirport({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAirport(
options?: Options
diff --git a/packages/falso/src/lib/alpha-numeric.ts b/packages/falso/src/lib/alpha-numeric.ts
index c47465624..d2acdba42 100644
--- a/packages/falso/src/lib/alpha-numeric.ts
+++ b/packages/falso/src/lib/alpha-numeric.ts
@@ -16,6 +16,10 @@ import { randNumber } from './number';
*
* randAlphaNumeric({ length: 3 })
*
+ * @example
+ *
+ * randAlphaNumeric({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAlphaNumeric(
options?: Options
diff --git a/packages/falso/src/lib/alpha.ts b/packages/falso/src/lib/alpha.ts
index 30125cca0..972d7113f 100644
--- a/packages/falso/src/lib/alpha.ts
+++ b/packages/falso/src/lib/alpha.ts
@@ -14,6 +14,10 @@ import { alphaChars } from './sequence';
*
* randAlpha({ length: 3 })
*
+ * @example
+ *
+ * randAlpha({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAlpha(
options?: Options
diff --git a/packages/falso/src/lib/american-football-team.ts b/packages/falso/src/lib/american-football-team.ts
index d3aec877f..1dfc10dcd 100644
--- a/packages/falso/src/lib/american-football-team.ts
+++ b/packages/falso/src/lib/american-football-team.ts
@@ -14,6 +14,10 @@ import { data } from './american-football-team.json';
*
* randAmericanFootballTeam({ length: 10 })
*
+ * @example
+ *
+ * randAmericanFootballTeam({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAmericanFootballTeam(
options?: Options
diff --git a/packages/falso/src/lib/animal-type.ts b/packages/falso/src/lib/animal-type.ts
index b08f3ddaf..3e32b16f1 100644
--- a/packages/falso/src/lib/animal-type.ts
+++ b/packages/falso/src/lib/animal-type.ts
@@ -14,6 +14,10 @@ import { data } from './animal-type.json';
*
* randAnimalType({ length: 10 })
*
+ * @example
+ *
+ * randAnimalType({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAnimalType(
options?: Options
diff --git a/packages/falso/src/lib/arn.ts b/packages/falso/src/lib/arn.ts
index 723d4fbb0..f06c448ad 100644
--- a/packages/falso/src/lib/arn.ts
+++ b/packages/falso/src/lib/arn.ts
@@ -35,6 +35,10 @@ const serviceArn: Record string> = {
*
* randArn({ length: 10 })
*
+ * @example
+ *
+ * randArn({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randArn(
options?: Options
diff --git a/packages/falso/src/lib/avatar.ts b/packages/falso/src/lib/avatar.ts
index 04dda6dfd..0aa213369 100644
--- a/packages/falso/src/lib/avatar.ts
+++ b/packages/falso/src/lib/avatar.ts
@@ -15,11 +15,15 @@ interface AvatarOptions extends FakeOptions {
*
* @example
*
+ * randAvatar({ size: 200 }) // default is 100
+ *
+ * @example
+ *
* randAvatar({ length: 10 })
*
* @example
*
- * randAvatar({ size: 200 }) // default is 100
+ * randAvatar({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randAvatar(
diff --git a/packages/falso/src/lib/aws-region.ts b/packages/falso/src/lib/aws-region.ts
index 9998257ad..6368a8e5a 100644
--- a/packages/falso/src/lib/aws-region.ts
+++ b/packages/falso/src/lib/aws-region.ts
@@ -14,6 +14,10 @@ import { data } from './aws-region.json';
*
* randAwsRegion({ length: 10 })
*
+ * @example
+ *
+ * randAwsRegion({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAwsRegion(
options?: Options
diff --git a/packages/falso/src/lib/aws-request-id.ts b/packages/falso/src/lib/aws-request-id.ts
index 3b63608b5..84a674440 100644
--- a/packages/falso/src/lib/aws-request-id.ts
+++ b/packages/falso/src/lib/aws-request-id.ts
@@ -14,6 +14,10 @@ import { fake, FakeOptions } from './core/core';
*
* randAwsRequestId({ length: 10 })
*
+ * @example
+ *
+ * randAwsRequestId({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAwsRequestId(
options?: Options
diff --git a/packages/falso/src/lib/aws-service.ts b/packages/falso/src/lib/aws-service.ts
index c3a8f46bc..30574afdf 100644
--- a/packages/falso/src/lib/aws-service.ts
+++ b/packages/falso/src/lib/aws-service.ts
@@ -14,6 +14,10 @@ import { data } from './aws-service.json';
*
* randAwsService({ length: 10 })
*
+ * @example
+ *
+ * randAwsService({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randAwsService(
options?: Options
diff --git a/packages/falso/src/lib/baseball-team.ts b/packages/falso/src/lib/baseball-team.ts
index 2ab088916..1be7a30b3 100644
--- a/packages/falso/src/lib/baseball-team.ts
+++ b/packages/falso/src/lib/baseball-team.ts
@@ -14,6 +14,10 @@ import { data } from './baseball-team.json';
*
* randBaseballTeam({ length: 10 })
*
+ * @example
+ *
+ * randBaseballTeam({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBaseballTeam(
options?: Options
diff --git a/packages/falso/src/lib/basketball-team.ts b/packages/falso/src/lib/basketball-team.ts
index afcec1f29..b748f5fa3 100644
--- a/packages/falso/src/lib/basketball-team.ts
+++ b/packages/falso/src/lib/basketball-team.ts
@@ -14,6 +14,10 @@ import { data } from './basketball-team.json';
*
* randBasketballTeam({ length: 10 })
*
+ * @example
+ *
+ * randBasketballTeam({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBasketballTeam(
options?: Options
diff --git a/packages/falso/src/lib/bear.ts b/packages/falso/src/lib/bear.ts
index af00eff74..f5a7919af 100644
--- a/packages/falso/src/lib/bear.ts
+++ b/packages/falso/src/lib/bear.ts
@@ -14,6 +14,10 @@ import { data } from './bear.json';
*
* randBear({ length: 10 })
*
+ * @example
+ *
+ * randBear({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBear(
options?: Options
diff --git a/packages/falso/src/lib/between-date.ts b/packages/falso/src/lib/between-date.ts
index baa46a352..0d6f62177 100644
--- a/packages/falso/src/lib/between-date.ts
+++ b/packages/falso/src/lib/between-date.ts
@@ -19,6 +19,10 @@ interface BetweenOptions extends FakeOptions {
*
* randBetweenDate({ from: new Date('10/07/2020'), to: new Date(), length: 10 })
*
+ * @example
+ *
+ * randBetweenDate({ from: new Date('10/07/2020'), to: new Date(), length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBetweenDate(
options: Options
diff --git a/packages/falso/src/lib/binary.ts b/packages/falso/src/lib/binary.ts
index cb44d5d00..0e8d9c36f 100644
--- a/packages/falso/src/lib/binary.ts
+++ b/packages/falso/src/lib/binary.ts
@@ -13,6 +13,10 @@ import { FakeOptions, fake, getRandomInRange } from './core/core';
*
* randBinary({ length: 10 })
*
+ * @example
+ *
+ * randBinary({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBinary(
options?: Options
diff --git a/packages/falso/src/lib/bird.ts b/packages/falso/src/lib/bird.ts
index ba7236b50..96ef1a95c 100644
--- a/packages/falso/src/lib/bird.ts
+++ b/packages/falso/src/lib/bird.ts
@@ -14,6 +14,10 @@ import { data } from './bird.i18n.json';
*
* randBird({ length: 10 })
*
+ * @example
+ *
+ * randBird({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBird(
options?: Options
diff --git a/packages/falso/src/lib/bitcoin-address.ts b/packages/falso/src/lib/bitcoin-address.ts
index 27492d95c..6a150bfff 100644
--- a/packages/falso/src/lib/bitcoin-address.ts
+++ b/packages/falso/src/lib/bitcoin-address.ts
@@ -14,6 +14,10 @@ import { randSequence } from './sequence';
*
* randBitcoinAddress({ length: 10 })
*
+ * @example
+ *
+ * randBitcoinAddress({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBitcoinAddress(
options?: Options
diff --git a/packages/falso/src/lib/book.ts b/packages/falso/src/lib/book.ts
index 2cf35b499..c123ecf7e 100644
--- a/packages/falso/src/lib/book.ts
+++ b/packages/falso/src/lib/book.ts
@@ -29,11 +29,15 @@ export interface Book {
*
* @example
*
+ * randBook({ category: 'Comedy' })
+ *
+ * @example
+ *
* randBook({ length: 10 })
*
* @example
*
- * randBook({ category: 'Comedy' })
+ * randBook({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randBook(
diff --git a/packages/falso/src/lib/boolean.ts b/packages/falso/src/lib/boolean.ts
index fbcaf8c64..c52cf0a59 100644
--- a/packages/falso/src/lib/boolean.ts
+++ b/packages/falso/src/lib/boolean.ts
@@ -13,6 +13,10 @@ import { fake, FakeOptions, randElement } from './core/core';
*
* randBoolean({ length: 10 })
*
+ * @example
+ *
+ * randBoolean({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBoolean(
options?: Options
diff --git a/packages/falso/src/lib/brand.ts b/packages/falso/src/lib/brand.ts
index a295b9c48..a8dedeb54 100644
--- a/packages/falso/src/lib/brand.ts
+++ b/packages/falso/src/lib/brand.ts
@@ -14,6 +14,10 @@ import { data } from './brand.json';
*
* randBrand({ length: 10 })
*
+ * @example
+ *
+ * randBrand({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBrand(
options?: Options
diff --git a/packages/falso/src/lib/browser.ts b/packages/falso/src/lib/browser.ts
index d9a42ad9d..97bc44400 100644
--- a/packages/falso/src/lib/browser.ts
+++ b/packages/falso/src/lib/browser.ts
@@ -14,6 +14,10 @@ import { data } from './browser.json';
*
* randBrowser({ length: 10 })
*
+ * @example
+ *
+ * randBrowser({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randBrowser(
options?: Options
diff --git a/packages/falso/src/lib/cardinal-direction.ts b/packages/falso/src/lib/cardinal-direction.ts
index f83a1e2e4..807cd9bef 100644
--- a/packages/falso/src/lib/cardinal-direction.ts
+++ b/packages/falso/src/lib/cardinal-direction.ts
@@ -14,6 +14,10 @@ import { data } from './cardinal-direction.json';
*
* randCardinalDirection({ length: 10 })
*
+ * @example
+ *
+ * randCardinalDirection({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCardinalDirection(
options?: Options
diff --git a/packages/falso/src/lib/cat.ts b/packages/falso/src/lib/cat.ts
index 5a32318d1..8062416c0 100644
--- a/packages/falso/src/lib/cat.ts
+++ b/packages/falso/src/lib/cat.ts
@@ -14,6 +14,10 @@ import { data } from './cat.json';
*
* randCat({ length: 10 })
*
+ * @example
+ *
+ * randCat({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCat(
options?: Options
diff --git a/packages/falso/src/lib/catch-phrase.ts b/packages/falso/src/lib/catch-phrase.ts
index 38e7e901a..11ba27178 100644
--- a/packages/falso/src/lib/catch-phrase.ts
+++ b/packages/falso/src/lib/catch-phrase.ts
@@ -14,6 +14,10 @@ import { data } from './catch-phrase.json';
*
* randCatchPhrase({ length: 10 })
*
+ * @example
+ *
+ * randCatchPhrase({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCatchPhrase(
options?: Options
diff --git a/packages/falso/src/lib/cetacean.ts b/packages/falso/src/lib/cetacean.ts
index 902a7c74a..f24f4c269 100644
--- a/packages/falso/src/lib/cetacean.ts
+++ b/packages/falso/src/lib/cetacean.ts
@@ -14,6 +14,10 @@ import { data } from './cetacean.json';
*
* randCetacean({ length: 10 })
*
+ * @example
+ *
+ * randCetacean({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCetacean(
options?: Options
diff --git a/packages/falso/src/lib/city.ts b/packages/falso/src/lib/city.ts
index 1f105852d..8d583dcf4 100644
--- a/packages/falso/src/lib/city.ts
+++ b/packages/falso/src/lib/city.ts
@@ -14,6 +14,10 @@ import { data } from './city.json';
*
* randCity({ length: 10 })
*
+ * @example
+ *
+ * randCity({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCity(
options?: Options
diff --git a/packages/falso/src/lib/clothing-size.ts b/packages/falso/src/lib/clothing-size.ts
index f100045b2..db34e3af5 100644
--- a/packages/falso/src/lib/clothing-size.ts
+++ b/packages/falso/src/lib/clothing-size.ts
@@ -14,6 +14,10 @@ import { data } from './clothing-size.json';
*
* randClothingSize({ length: 10 })
*
+ * @example
+ *
+ * randClothingSize({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randClothingSize(
options?: Options
diff --git a/packages/falso/src/lib/code-snippet.ts b/packages/falso/src/lib/code-snippet.ts
index 474d67358..28a105a85 100644
--- a/packages/falso/src/lib/code-snippet.ts
+++ b/packages/falso/src/lib/code-snippet.ts
@@ -34,11 +34,15 @@ interface CodeSnippetOptions extends FakeOptions {
*
* @example
*
+ * randCodeSnippet({ lang: 'html' }) // default is 'javascript'
+ *
+ * @example
+ *
* randCodeSnippet({ length: 10 })
*
* @example
*
- * randCodeSnippet({ lang: 'html' }) // default is 'javascript'
+ * randCodeSnippet({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randCodeSnippet(
diff --git a/packages/falso/src/lib/color.ts b/packages/falso/src/lib/color.ts
index 2239aefeb..cbbfda053 100644
--- a/packages/falso/src/lib/color.ts
+++ b/packages/falso/src/lib/color.ts
@@ -14,6 +14,10 @@ import { data } from './color.json';
*
* randColor({ length: 10 })
*
+ * @example
+ *
+ * randColor({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randColor(
options?: Options
diff --git a/packages/falso/src/lib/company-name.ts b/packages/falso/src/lib/company-name.ts
index 3851917c2..f78b66e75 100644
--- a/packages/falso/src/lib/company-name.ts
+++ b/packages/falso/src/lib/company-name.ts
@@ -14,6 +14,10 @@ import { data } from './company-name.json';
*
* randCompanyName({ length: 10 })
*
+ * @example
+ *
+ * randCompanyName({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCompanyName(
options?: Options
diff --git a/packages/falso/src/lib/country-code.ts b/packages/falso/src/lib/country-code.ts
index 0fa15c097..2841d9453 100644
--- a/packages/falso/src/lib/country-code.ts
+++ b/packages/falso/src/lib/country-code.ts
@@ -14,6 +14,10 @@ import { data } from './country-code.json';
*
* randCountryCode({ length: 10 })
*
+ * @example
+ *
+ * randCountryCode({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCountryCode(
options?: Options
diff --git a/packages/falso/src/lib/country.ts b/packages/falso/src/lib/country.ts
index 838e3e9f7..4c6a2e564 100644
--- a/packages/falso/src/lib/country.ts
+++ b/packages/falso/src/lib/country.ts
@@ -14,6 +14,10 @@ import { data } from './country.json';
*
* randCountry({ length: 10 })
*
+ * @example
+ *
+ * randCountry({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCountry(
options?: Options
diff --git a/packages/falso/src/lib/county.ts b/packages/falso/src/lib/county.ts
index 63b416c7c..f8a0ad66f 100644
--- a/packages/falso/src/lib/county.ts
+++ b/packages/falso/src/lib/county.ts
@@ -14,6 +14,10 @@ import { data } from './county.json';
*
* randCounty({ length: 10 })
*
+ * @example
+ *
+ * randCounty({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCounty(
options?: Options
diff --git a/packages/falso/src/lib/cow.ts b/packages/falso/src/lib/cow.ts
index 159dc5f2b..ca41e3f74 100644
--- a/packages/falso/src/lib/cow.ts
+++ b/packages/falso/src/lib/cow.ts
@@ -14,6 +14,10 @@ import { data } from './cow.json';
*
* randCow({ length: 10 })
*
+ * @example
+ *
+ * randCow({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCow(
options?: Options
diff --git a/packages/falso/src/lib/credit-card-brand.ts b/packages/falso/src/lib/credit-card-brand.ts
index 7bbbe8a19..b2c4720a4 100644
--- a/packages/falso/src/lib/credit-card-brand.ts
+++ b/packages/falso/src/lib/credit-card-brand.ts
@@ -14,6 +14,10 @@ import { data } from './credit-card-brand.json';
*
* randCreditCardBrand({ length: 10 })
*
+ * @example
+ *
+ * randCreditCardBrand({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCreditCardBrand(
options?: Options
diff --git a/packages/falso/src/lib/credit-card-cvv.ts b/packages/falso/src/lib/credit-card-cvv.ts
index bc002ac72..9148216c3 100644
--- a/packages/falso/src/lib/credit-card-cvv.ts
+++ b/packages/falso/src/lib/credit-card-cvv.ts
@@ -13,6 +13,10 @@ import { fake, FakeOptions, getRandomInRange } from './core/core';
*
* randCreditCardCVV({ length: 10 })
*
+ * @example
+ *
+ * randCreditCardCVV({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCreditCardCVV(
options?: Options
diff --git a/packages/falso/src/lib/credit-card-number.ts b/packages/falso/src/lib/credit-card-number.ts
index 8cf4475ff..6f9297ebc 100644
--- a/packages/falso/src/lib/credit-card-number.ts
+++ b/packages/falso/src/lib/credit-card-number.ts
@@ -37,6 +37,10 @@ export type Brand =
*
* randCreditCardNumber({ length: 10 })
*
+ * @example
+ *
+ * randCreditCardNumber({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCreditCardNumber<
Options extends CreditCardNumberOptions = never
diff --git a/packages/falso/src/lib/credit-card.ts b/packages/falso/src/lib/credit-card.ts
index cbba1588c..02cc7158b 100644
--- a/packages/falso/src/lib/credit-card.ts
+++ b/packages/falso/src/lib/credit-card.ts
@@ -8,7 +8,6 @@ import { rand } from './rand';
import { randPastDate } from './past-date';
import { randFutureDate } from './future-date';
import { randPersonTitle } from './person-title';
-import { Address } from './address';
export interface CreditCardOptions extends FakeOptions {
fullName?: string;
@@ -47,6 +46,10 @@ export interface CreditCard {
*
* randCreditCard({ length: 10 })
*
+ * @example
+ *
+ * randCreditCard({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCreditCard(
options?: Options
diff --git a/packages/falso/src/lib/crocodilia.ts b/packages/falso/src/lib/crocodilia.ts
index 7e7c9835c..3cea5e69e 100644
--- a/packages/falso/src/lib/crocodilia.ts
+++ b/packages/falso/src/lib/crocodilia.ts
@@ -14,6 +14,10 @@ import { data } from './crocodilia.json';
*
* randCrocodilia({ length: 10 })
*
+ * @example
+ *
+ * randCrocodilia({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCrocodilia(
options?: Options
diff --git a/packages/falso/src/lib/currency-code.ts b/packages/falso/src/lib/currency-code.ts
index 68b91f82e..6b27c9101 100644
--- a/packages/falso/src/lib/currency-code.ts
+++ b/packages/falso/src/lib/currency-code.ts
@@ -14,6 +14,10 @@ import { data } from './currency-code.json';
*
* randCurrencyCode({ length: 10 })
*
+ * @example
+ *
+ * randCurrencyCode({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCurrencyCode(
options?: Options
diff --git a/packages/falso/src/lib/currency-name.ts b/packages/falso/src/lib/currency-name.ts
index b432c9832..c543be38f 100644
--- a/packages/falso/src/lib/currency-name.ts
+++ b/packages/falso/src/lib/currency-name.ts
@@ -14,6 +14,10 @@ import { data } from './currency-name.json';
*
* randCurrencyName({ length: 10 })
*
+ * @example
+ *
+ * randCurrencyName({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCurrencyName(
options?: Options
diff --git a/packages/falso/src/lib/currency-symbol.ts b/packages/falso/src/lib/currency-symbol.ts
index 57d291789..bd6574198 100644
--- a/packages/falso/src/lib/currency-symbol.ts
+++ b/packages/falso/src/lib/currency-symbol.ts
@@ -14,6 +14,10 @@ import { data } from './currency-symbol.json';
*
* randCurrencySymbol({ length: 10 })
*
+ * @example
+ *
+ * randCurrencySymbol({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randCurrencySymbol(
options?: Options
diff --git a/packages/falso/src/lib/database-collation.ts b/packages/falso/src/lib/database-collation.ts
index d081f50cd..9a99a2db7 100644
--- a/packages/falso/src/lib/database-collation.ts
+++ b/packages/falso/src/lib/database-collation.ts
@@ -14,6 +14,10 @@ import { data } from './database-collation.json';
*
* randDatabaseCollation({ length: 10 })
*
+ * @example
+ *
+ * randDatabaseCollation({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDatabaseCollation(
options?: Options
diff --git a/packages/falso/src/lib/database-column.ts b/packages/falso/src/lib/database-column.ts
index 36ff6c706..3e6795362 100644
--- a/packages/falso/src/lib/database-column.ts
+++ b/packages/falso/src/lib/database-column.ts
@@ -14,6 +14,10 @@ import { data } from './database-column.json';
*
* randDatabaseColumn({ length: 10 })
*
+ * @example
+ *
+ * randDatabaseColumn({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDatabaseColumn(
options?: Options
diff --git a/packages/falso/src/lib/database-engine.ts b/packages/falso/src/lib/database-engine.ts
index 9d36dfd6d..3f8844f7c 100644
--- a/packages/falso/src/lib/database-engine.ts
+++ b/packages/falso/src/lib/database-engine.ts
@@ -14,6 +14,10 @@ import { data } from './database-engine.json';
*
* randDatabaseEngine({ length: 10 })
*
+ * @example
+ *
+ * randDatabaseEngine({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDatabaseEngine(
options?: Options
diff --git a/packages/falso/src/lib/database-type.ts b/packages/falso/src/lib/database-type.ts
index ca85e1e36..8a569dccd 100644
--- a/packages/falso/src/lib/database-type.ts
+++ b/packages/falso/src/lib/database-type.ts
@@ -14,6 +14,10 @@ import { data } from './database-type.json';
*
* randDatabaseType({ length: 10 })
*
+ * @example
+ *
+ * randDatabaseType({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDatabaseType(
options?: Options
diff --git a/packages/falso/src/lib/department.ts b/packages/falso/src/lib/department.ts
index 2ea8f12bc..7344ccfb7 100644
--- a/packages/falso/src/lib/department.ts
+++ b/packages/falso/src/lib/department.ts
@@ -14,6 +14,10 @@ import { data } from './department.json';
*
* randDepartment({ length: 10 })
*
+ * @example
+ *
+ * randDepartment({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDepartment(
options?: Options
diff --git a/packages/falso/src/lib/direction.ts b/packages/falso/src/lib/direction.ts
index c28c5cbe4..693796a90 100644
--- a/packages/falso/src/lib/direction.ts
+++ b/packages/falso/src/lib/direction.ts
@@ -14,6 +14,10 @@ import { data } from './direction.json';
*
* randDirection({ length: 10 })
*
+ * @example
+ *
+ * randDirection({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDirection(
options?: Options
diff --git a/packages/falso/src/lib/directory-path.ts b/packages/falso/src/lib/directory-path.ts
index be4f9bf0b..0f1630f0f 100644
--- a/packages/falso/src/lib/directory-path.ts
+++ b/packages/falso/src/lib/directory-path.ts
@@ -14,6 +14,10 @@ import { data } from './directory-path.json';
*
* randDirectoryPath({ length: 10 })
*
+ * @example
+ *
+ * randDirectoryPath({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDirectoryPath(
options?: Options
diff --git a/packages/falso/src/lib/dog.ts b/packages/falso/src/lib/dog.ts
index c05c9314a..c586721d1 100644
--- a/packages/falso/src/lib/dog.ts
+++ b/packages/falso/src/lib/dog.ts
@@ -14,6 +14,10 @@ import { data } from './dog.json';
*
* randDog({ length: 10 })
*
+ * @example
+ *
+ * randDog({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDog(
options?: Options
diff --git a/packages/falso/src/lib/domain-name.ts b/packages/falso/src/lib/domain-name.ts
index 675804e97..dade3ec30 100644
--- a/packages/falso/src/lib/domain-name.ts
+++ b/packages/falso/src/lib/domain-name.ts
@@ -15,6 +15,10 @@ import { randWord } from './word';
*
* randDomainName({ length: 10 })
*
+ * @example
+ *
+ * randDomainName({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDomainName(
options?: Options
diff --git a/packages/falso/src/lib/domain-suffix.ts b/packages/falso/src/lib/domain-suffix.ts
index 06efa2467..7e3a4e1d1 100644
--- a/packages/falso/src/lib/domain-suffix.ts
+++ b/packages/falso/src/lib/domain-suffix.ts
@@ -14,6 +14,10 @@ import { data } from './domain-suffix.json';
*
* randDomainSuffix({ length: 10 })
*
+ * @example
+ *
+ * randDomainSuffix({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDomainSuffix(
options?: Options
diff --git a/packages/falso/src/lib/drinks.ts b/packages/falso/src/lib/drinks.ts
index f60c59fa0..9a26b676a 100644
--- a/packages/falso/src/lib/drinks.ts
+++ b/packages/falso/src/lib/drinks.ts
@@ -14,6 +14,10 @@ import { data } from './drinks.json';
*
* randDrinks({ length: 10 })
*
+ * @example
+ *
+ * randDrinks({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randDrinks(
options?: Options
diff --git a/packages/falso/src/lib/email-provider.ts b/packages/falso/src/lib/email-provider.ts
index 42bdb1f93..9427c7df8 100644
--- a/packages/falso/src/lib/email-provider.ts
+++ b/packages/falso/src/lib/email-provider.ts
@@ -14,6 +14,10 @@ import { data } from './email-provider.json';
*
* randEmailProvider({ length: 10 })
*
+ * @example
+ *
+ * randEmailProvider({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randEmailProvider(
options?: Options
diff --git a/packages/falso/src/lib/email.ts b/packages/falso/src/lib/email.ts
index 6ade3cedf..ca456c076 100644
--- a/packages/falso/src/lib/email.ts
+++ b/packages/falso/src/lib/email.ts
@@ -49,10 +49,6 @@ function randFormattedName(
*
* @example
*
- * randEmail({ length: 10 })
- *
- * @example
- *
* randEmail({ firstName: 'Netanel' })
*
* @example
@@ -71,6 +67,13 @@ function randFormattedName(
*
* randEmail({ suffix: 'com' })
*
+ * @example
+ *
+ * randEmail({ length: 10 })
+ *
+ * @example
+ *
+ * randEmail({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randEmail(
diff --git a/packages/falso/src/lib/emoji.ts b/packages/falso/src/lib/emoji.ts
index 37b82d8ef..9a5e6cf91 100644
--- a/packages/falso/src/lib/emoji.ts
+++ b/packages/falso/src/lib/emoji.ts
@@ -14,6 +14,10 @@ import { data } from './emoji.json';
*
* randEmoji({ length: 10 })
*
+ * @example
+ *
+ * randEmoji({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randEmoji(
options?: Options
diff --git a/packages/falso/src/lib/ethereum-address.ts b/packages/falso/src/lib/ethereum-address.ts
index 71a4132b0..cdd22ec4f 100644
--- a/packages/falso/src/lib/ethereum-address.ts
+++ b/packages/falso/src/lib/ethereum-address.ts
@@ -14,6 +14,10 @@ import { data } from './ethereum-address.json';
*
* randEthereumAddress({ length: 10 })
*
+ * @example
+ *
+ * randEthereumAddress({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randEthereumAddress(
options?: Options
diff --git a/packages/falso/src/lib/file-ext.ts b/packages/falso/src/lib/file-ext.ts
index a973d8143..71db4f60e 100644
--- a/packages/falso/src/lib/file-ext.ts
+++ b/packages/falso/src/lib/file-ext.ts
@@ -14,6 +14,10 @@ import { data } from './file-ext.json';
*
* randFileExt({ length: 10 })
*
+ * @example
+ *
+ * randFileExt({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFileExt(
options?: Options
diff --git a/packages/falso/src/lib/file-name.ts b/packages/falso/src/lib/file-name.ts
index d14b87234..83910523b 100644
--- a/packages/falso/src/lib/file-name.ts
+++ b/packages/falso/src/lib/file-name.ts
@@ -14,6 +14,10 @@ import { data } from './file-name.json';
*
* randFileName({ length: 10 })
*
+ * @example
+ *
+ * randFileName({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFileName<
Options extends FakeOptions & { extension?: string } = never
diff --git a/packages/falso/src/lib/file-path.ts b/packages/falso/src/lib/file-path.ts
index 703111b91..3043e485b 100644
--- a/packages/falso/src/lib/file-path.ts
+++ b/packages/falso/src/lib/file-path.ts
@@ -14,6 +14,10 @@ import { data } from './file-path.json';
*
* randFilePath({ length: 10 })
*
+ * @example
+ *
+ * randFilePath({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFilePath(
options?: Options
diff --git a/packages/falso/src/lib/file-type.ts b/packages/falso/src/lib/file-type.ts
index 414ca4d9e..bc0957ab9 100644
--- a/packages/falso/src/lib/file-type.ts
+++ b/packages/falso/src/lib/file-type.ts
@@ -14,6 +14,10 @@ import { data } from './file-type.json';
*
* randFileType({ length: 10 })
*
+ * @example
+ *
+ * randFileType({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFileType(
options?: Options
diff --git a/packages/falso/src/lib/first-name.ts b/packages/falso/src/lib/first-name.ts
index 69a95d694..fdac1c00e 100644
--- a/packages/falso/src/lib/first-name.ts
+++ b/packages/falso/src/lib/first-name.ts
@@ -20,6 +20,10 @@ import { randBoolean } from './boolean';
*
* randFirstName({ length: 10 })
*
+ * @example
+ *
+ * randFirstName({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFirstName(
options?: Options
diff --git a/packages/falso/src/lib/fish.ts b/packages/falso/src/lib/fish.ts
index f7a2e4f51..a73bb71a2 100644
--- a/packages/falso/src/lib/fish.ts
+++ b/packages/falso/src/lib/fish.ts
@@ -14,6 +14,10 @@ import { data } from './fish.json';
*
* randFish({ length: 10 })
*
+ * @example
+ *
+ * randFish({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFish(
options?: Options
diff --git a/packages/falso/src/lib/flight-details.ts b/packages/falso/src/lib/flight-details.ts
index 300aa1bb7..b42a6c509 100644
--- a/packages/falso/src/lib/flight-details.ts
+++ b/packages/falso/src/lib/flight-details.ts
@@ -10,7 +10,6 @@ import { Airline, randFlightNumber } from './flight-number';
import { randFullName } from './full-name';
import { randSeatNumber } from './seat-number';
import { Airport, randAirport } from './airport';
-import { CreditCard } from './credit-card';
export interface FlightDetailsOptions extends FakeOptions {
airline?: Airline;
@@ -55,6 +54,10 @@ function generateFlightLength(): number {
*
* randFlightDetails({ length: 10 })
*
+ * @example
+ *
+ * randFlightDetails({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFlightDetails(
options?: Options
diff --git a/packages/falso/src/lib/flight-number.ts b/packages/falso/src/lib/flight-number.ts
index ec3b43ac1..d527cccff 100644
--- a/packages/falso/src/lib/flight-number.ts
+++ b/packages/falso/src/lib/flight-number.ts
@@ -74,6 +74,10 @@ function generateStandardFlightNumber({
*
* randFlightNumber({ length: 10 })
*
+ * @example
+ *
+ * randFlightNumber({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFlightNumber(
options?: Options
diff --git a/packages/falso/src/lib/float.ts b/packages/falso/src/lib/float.ts
index e4793adc1..571713c27 100644
--- a/packages/falso/src/lib/float.ts
+++ b/packages/falso/src/lib/float.ts
@@ -18,15 +18,20 @@ export interface RandomFloatOptions extends RandomInRangeOptions, FakeOptions {}
*
* @example
*
- * randFloat({ length: 10 })
+ * randFloat({ min: 10, max: 20, fraction: 1 }) // 12.5
*
* @example
*
- * randFloat({ min: 10, max: 20, fraction: 1 }) // 12.5
+ * randFloat({ min: 10, max: 20, fraction: 2 }) // 12.52
*
* @example
*
- * randFloat({ min: 10, max: 20, fraction: 2 }) // 12.52
+ * randFloat({ length: 10 })
+ *
+ * @example
+ *
+ * randFloat({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFloat(
options?: Options
diff --git a/packages/falso/src/lib/font-family.ts b/packages/falso/src/lib/font-family.ts
index 9cc60407a..5046b2104 100644
--- a/packages/falso/src/lib/font-family.ts
+++ b/packages/falso/src/lib/font-family.ts
@@ -14,6 +14,10 @@ import { data } from './font-family.json';
*
* randFontFamily({ length: 10 })
*
+ * @example
+ *
+ * randFontFamily({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFontFamily(
options?: Options
diff --git a/packages/falso/src/lib/font-size.ts b/packages/falso/src/lib/font-size.ts
index a0319d7f9..da9cdd773 100644
--- a/packages/falso/src/lib/font-size.ts
+++ b/packages/falso/src/lib/font-size.ts
@@ -28,6 +28,10 @@ export interface FontSizeOptions extends FakeOptions {
*
* randFontSize({ length: 10 })
*
+ * @example
+ *
+ * randFontSize({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFontSize(
options?: Options
diff --git a/packages/falso/src/lib/food.ts b/packages/falso/src/lib/food.ts
index 015e7a0f7..2e13b9835 100644
--- a/packages/falso/src/lib/food.ts
+++ b/packages/falso/src/lib/food.ts
@@ -44,6 +44,10 @@ const totalOrigins = Object.keys(data)?.length;
*
* randFood({ length: 10 })
*
+ * @example
+ *
+ * randFood({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFood(
options?: Options
diff --git a/packages/falso/src/lib/football-team.ts b/packages/falso/src/lib/football-team.ts
index 5aab7e0a1..0ed179b02 100644
--- a/packages/falso/src/lib/football-team.ts
+++ b/packages/falso/src/lib/football-team.ts
@@ -14,6 +14,10 @@ import { data } from './football-team.json';
*
* randFootballTeam({ length: 10 })
*
+ * @example
+ *
+ * randFootballTeam({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFootballTeam(
options?: Options
diff --git a/packages/falso/src/lib/frequency.ts b/packages/falso/src/lib/frequency.ts
index 4f4742373..1a59a1892 100644
--- a/packages/falso/src/lib/frequency.ts
+++ b/packages/falso/src/lib/frequency.ts
@@ -14,6 +14,10 @@ import { data } from './frequency.json';
*
* randFrequency({ length: 10 })
*
+ * @example
+ *
+ * randFrequency({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFrequency(
options?: Options
diff --git a/packages/falso/src/lib/full-address.ts b/packages/falso/src/lib/full-address.ts
index 905b180dc..aa1888010 100644
--- a/packages/falso/src/lib/full-address.ts
+++ b/packages/falso/src/lib/full-address.ts
@@ -22,6 +22,10 @@ import { AddressOptions, randAddress } from './address';
*
* randFullAddress({ length: 10 })
*
+ * @example
+ *
+ * randFullAddress({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFullAddress(
options?: Options
diff --git a/packages/falso/src/lib/full-name.ts b/packages/falso/src/lib/full-name.ts
index 6d0c8bb3a..60a75da0e 100644
--- a/packages/falso/src/lib/full-name.ts
+++ b/packages/falso/src/lib/full-name.ts
@@ -23,6 +23,10 @@ export interface NameOptions extends FakeOptions {
*
* randFullName({ length: 10 })
*
+ * @example
+ *
+ * randFullName({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randFullName(
options?: Options
diff --git a/packages/falso/src/lib/future-date.ts b/packages/falso/src/lib/future-date.ts
index 83218892b..242e30a80 100644
--- a/packages/falso/src/lib/future-date.ts
+++ b/packages/falso/src/lib/future-date.ts
@@ -16,11 +16,15 @@ interface FutureOptions extends FakeOptions {
*
* @example
*
+ * randFutureDate({ years: 10 }) // default is 1
+ *
+ * @example
+ *
* randFutureDate({ length: 10 })
*
* @example
*
- * randFutureDate({ years: 10 }) // default is 1
+ * randFutureDate({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randFutureDate(
diff --git a/packages/falso/src/lib/gender.ts b/packages/falso/src/lib/gender.ts
index ac1ac55dc..ad4be2bdb 100644
--- a/packages/falso/src/lib/gender.ts
+++ b/packages/falso/src/lib/gender.ts
@@ -17,11 +17,15 @@ interface GenderOptions extends FakeOptions {
*
* @example
*
+ * randGender({ code: true }) // default is false
+ *
+ * @example
+ *
* randGender({ length: 10 })
*
* @example
*
- * randGender({ code: true }) // default is false
+ * randGender({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randGender(
diff --git a/packages/falso/src/lib/git-branch.ts b/packages/falso/src/lib/git-branch.ts
index 0e43a4df7..243d86be7 100644
--- a/packages/falso/src/lib/git-branch.ts
+++ b/packages/falso/src/lib/git-branch.ts
@@ -14,6 +14,10 @@ import { data } from './git-branch.json';
*
* randGitBranch({ length: 10 })
*
+ * @example
+ *
+ * randGitBranch({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randGitBranch(
options?: Options
diff --git a/packages/falso/src/lib/git-commit-entry.ts b/packages/falso/src/lib/git-commit-entry.ts
index 22c7573db..4f5d64d73 100644
--- a/packages/falso/src/lib/git-commit-entry.ts
+++ b/packages/falso/src/lib/git-commit-entry.ts
@@ -17,6 +17,10 @@ import { randGitCommitMessage } from './git-commit-message';
*
* randGitCommitEntry({ length: 10 })
*
+ * @example
+ *
+ * randGitCommitEntry({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randGitCommitEntry(
options?: Options
diff --git a/packages/falso/src/lib/git-commit-message.ts b/packages/falso/src/lib/git-commit-message.ts
index da6b0cb60..f9071833b 100644
--- a/packages/falso/src/lib/git-commit-message.ts
+++ b/packages/falso/src/lib/git-commit-message.ts
@@ -15,6 +15,10 @@ import { randWord } from './word';
*
* randGitCommitMessage({ length: 10 })
*
+ * @example
+ *
+ * randGitCommitMessage({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randGitCommitMessage(
options?: Options
diff --git a/packages/falso/src/lib/git-commit-sha.ts b/packages/falso/src/lib/git-commit-sha.ts
index f87de7ce7..032041451 100644
--- a/packages/falso/src/lib/git-commit-sha.ts
+++ b/packages/falso/src/lib/git-commit-sha.ts
@@ -16,6 +16,10 @@ const commitShaLen = 40;
*
* randGitCommitSha({ length: 10 })
*
+ * @example
+ *
+ * randGitCommitSha({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randGitCommitSha(
options?: Options
diff --git a/packages/falso/src/lib/git-short-sha.ts b/packages/falso/src/lib/git-short-sha.ts
index 911f8e299..d09ae7d95 100644
--- a/packages/falso/src/lib/git-short-sha.ts
+++ b/packages/falso/src/lib/git-short-sha.ts
@@ -16,6 +16,10 @@ const commitShortShaLen = 7;
*
* randGitShortSha({ length: 10 })
*
+ * @example
+ *
+ * randGitShortSha({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randGitShortSha(
options?: Options
diff --git a/packages/falso/src/lib/hex.ts b/packages/falso/src/lib/hex.ts
index 08441917b..8e97cc812 100644
--- a/packages/falso/src/lib/hex.ts
+++ b/packages/falso/src/lib/hex.ts
@@ -14,6 +14,10 @@ import { random } from './random';
*
* randHex({ length: 10 })
*
+ * @example
+ *
+ * randHex({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randHex(
options?: Options
diff --git a/packages/falso/src/lib/hexa-decimal.ts b/packages/falso/src/lib/hexa-decimal.ts
index c4ec80721..8f7ba9a38 100644
--- a/packages/falso/src/lib/hexa-decimal.ts
+++ b/packages/falso/src/lib/hexa-decimal.ts
@@ -21,6 +21,10 @@ function generator() {
*
* randHexaDecimal({ length: 10 })
*
+ * @example
+ *
+ * randHexaDecimal({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randHexaDecimal(
options?: Options
diff --git a/packages/falso/src/lib/horse.ts b/packages/falso/src/lib/horse.ts
index 2cf31fe95..63ba364a0 100644
--- a/packages/falso/src/lib/horse.ts
+++ b/packages/falso/src/lib/horse.ts
@@ -14,6 +14,10 @@ import { data } from './horse.json';
*
* randHorse({ length: 10 })
*
+ * @example
+ *
+ * randHorse({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randHorse(
options?: Options
diff --git a/packages/falso/src/lib/hsl.ts b/packages/falso/src/lib/hsl.ts
index b880fa9ba..66e45cb9e 100644
--- a/packages/falso/src/lib/hsl.ts
+++ b/packages/falso/src/lib/hsl.ts
@@ -16,11 +16,15 @@ export interface HSLOptions extends FakeOptions {
*
* @example
*
+ * randHsl({ alpha: true }) // default is false
+ *
+ * @example
+ *
* randHsl({ length: 3 })
*
* @example
*
- * randHsl({ alpha: true }) // default is false
+ * randHsl({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randHsl(options?: Options) {
diff --git a/packages/falso/src/lib/http-method.ts b/packages/falso/src/lib/http-method.ts
index a57a0202e..2b289b15d 100644
--- a/packages/falso/src/lib/http-method.ts
+++ b/packages/falso/src/lib/http-method.ts
@@ -14,6 +14,10 @@ import { data } from './http-method.json';
*
* randHttpMethod({ length: 10 })
*
+ * @example
+ *
+ * randHttpMethod({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randHttpMethod(
options?: Options
diff --git a/packages/falso/src/lib/iban.ts b/packages/falso/src/lib/iban.ts
index 0b12d6104..43cbd6fa5 100644
--- a/packages/falso/src/lib/iban.ts
+++ b/packages/falso/src/lib/iban.ts
@@ -16,6 +16,10 @@ import { randAlphaNumeric } from './alpha-numeric';
*
* randIban({ length: 10 })
*
+ * @example
+ *
+ * randIban({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randIban(
options?: Options
diff --git a/packages/falso/src/lib/ice-hockey-team.ts b/packages/falso/src/lib/ice-hockey-team.ts
index 415e3a46e..40b3894c5 100644
--- a/packages/falso/src/lib/ice-hockey-team.ts
+++ b/packages/falso/src/lib/ice-hockey-team.ts
@@ -14,6 +14,10 @@ import { data } from './ice-hockey-team.json';
*
* randIceHockeyTeam({ length: 10 })
*
+ * @example
+ *
+ * randIceHockeyTeam({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randIceHockeyTeam(
options?: Options
diff --git a/packages/falso/src/lib/img.ts b/packages/falso/src/lib/img.ts
index 550576e15..103efb054 100644
--- a/packages/falso/src/lib/img.ts
+++ b/packages/falso/src/lib/img.ts
@@ -15,6 +15,10 @@ type Category = 'animals' | 'arch' | 'nature' | 'people' | 'tech';
*
* randImg({ length: 10 })
*
+ * @example
+ *
+ * randImg({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randImg<
Options extends FakeOptions & {
diff --git a/packages/falso/src/lib/integration.ts b/packages/falso/src/lib/integration.ts
index 1d8ec9df5..e97ccd034 100644
--- a/packages/falso/src/lib/integration.ts
+++ b/packages/falso/src/lib/integration.ts
@@ -14,6 +14,10 @@ import { data } from './integration.json';
*
* randIntegrations({ length: 10 })
*
+ * @example
+ *
+ * randIntegrations({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randIntegration(
options?: Options
diff --git a/packages/falso/src/lib/ip.ts b/packages/falso/src/lib/ip.ts
index 3d9a10990..f34c37b3b 100644
--- a/packages/falso/src/lib/ip.ts
+++ b/packages/falso/src/lib/ip.ts
@@ -16,6 +16,10 @@ const ipRange = { min: 0, max: 255 };
*
* randIp({ length: 10 })
*
+ * @example
+ *
+ * randIp({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randIp(options?: Options) {
return fake(
diff --git a/packages/falso/src/lib/ipv6.ts b/packages/falso/src/lib/ipv6.ts
index dfaebfbc7..5326442bf 100644
--- a/packages/falso/src/lib/ipv6.ts
+++ b/packages/falso/src/lib/ipv6.ts
@@ -14,6 +14,10 @@ import { randHexaDecimal } from './hexa-decimal';
*
* randIpv6({ length: 10 })
*
+ * @example
+ *
+ * randIpv6({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randIpv6(
options?: Options
diff --git a/packages/falso/src/lib/job-area.ts b/packages/falso/src/lib/job-area.ts
index 99d566e6d..d089b5b44 100644
--- a/packages/falso/src/lib/job-area.ts
+++ b/packages/falso/src/lib/job-area.ts
@@ -14,6 +14,10 @@ import { data } from './job-area.json';
*
* randJobArea({ length: 10 })
*
+ * @example
+ *
+ * randJobArea({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randJobArea(
options?: Options
diff --git a/packages/falso/src/lib/job-descriptor.ts b/packages/falso/src/lib/job-descriptor.ts
index 053e67021..032be83db 100644
--- a/packages/falso/src/lib/job-descriptor.ts
+++ b/packages/falso/src/lib/job-descriptor.ts
@@ -14,6 +14,10 @@ import { data } from './job-descriptor.json';
*
* randJobDescriptor({ length: 10 })
*
+ * @example
+ *
+ * randJobDescriptor({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randJobDescriptor(
options?: Options
diff --git a/packages/falso/src/lib/job-title.ts b/packages/falso/src/lib/job-title.ts
index c0553878b..c292dc95e 100644
--- a/packages/falso/src/lib/job-title.ts
+++ b/packages/falso/src/lib/job-title.ts
@@ -14,6 +14,10 @@ import { data } from './job-title.json';
*
* randJobTitle({ length: 10 })
*
+ * @example
+ *
+ * randJobTitle({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randJobTitle(
options?: Options
diff --git a/packages/falso/src/lib/job-type.ts b/packages/falso/src/lib/job-type.ts
index 7907de9a1..592d415c6 100644
--- a/packages/falso/src/lib/job-type.ts
+++ b/packages/falso/src/lib/job-type.ts
@@ -14,6 +14,10 @@ import { data } from './job-type.json';
*
* randJobType({ length: 10 })
*
+ * @example
+ *
+ * randJobType({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randJobType(
options?: Options
diff --git a/packages/falso/src/lib/json.ts b/packages/falso/src/lib/json.ts
index 8b9bbc75c..0053dd783 100644
--- a/packages/falso/src/lib/json.ts
+++ b/packages/falso/src/lib/json.ts
@@ -73,7 +73,7 @@ const generateRandomValue = (): any => {
*
* @example
*
- * randJSON({ length: 10, priority: 'length' })
+ * randJSON({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randJSON(
diff --git a/packages/falso/src/lib/language.ts b/packages/falso/src/lib/language.ts
index e32436fb8..21894f786 100644
--- a/packages/falso/src/lib/language.ts
+++ b/packages/falso/src/lib/language.ts
@@ -17,11 +17,15 @@ interface LanguageOptions extends FakeOptions {
*
* @example
*
+ * randLanguage({ code: true }) // default is false
+ *
+ * @example
+ *
* randLanguage({ length: 10 })
*
* @example
*
- * randLanguage({ code: true }) // default is false
+ * randLanguage({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randLanguage(
diff --git a/packages/falso/src/lib/last-name.ts b/packages/falso/src/lib/last-name.ts
index 0ff755d50..d7398d6bb 100644
--- a/packages/falso/src/lib/last-name.ts
+++ b/packages/falso/src/lib/last-name.ts
@@ -20,6 +20,10 @@ import { NameOptions } from './full-name';
*
* randLastName({ length: 10 })
*
+ * @example
+ *
+ * randLastName({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randLastName(
options?: Options
diff --git a/packages/falso/src/lib/latitude.ts b/packages/falso/src/lib/latitude.ts
index 16411fd26..93e5bf272 100644
--- a/packages/falso/src/lib/latitude.ts
+++ b/packages/falso/src/lib/latitude.ts
@@ -13,6 +13,10 @@ import { FakeOptions, fake, getRandomInRange } from './core/core';
*
* randLatitude({ length: 10 })
*
+ * @example
+ *
+ * randLatitude({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randLatitude(
options?: Options
diff --git a/packages/falso/src/lib/line.ts b/packages/falso/src/lib/line.ts
index c214c256a..e3902d197 100644
--- a/packages/falso/src/lib/line.ts
+++ b/packages/falso/src/lib/line.ts
@@ -18,6 +18,10 @@ export interface LineOptions extends FakeOptions {
*
* randLine({ lineCount: 10 }) // default is 5
*
+ * @example
+ *
+ * randLine({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randLine(
options?: Options
diff --git a/packages/falso/src/lib/lines.ts b/packages/falso/src/lib/lines.ts
index a09bc6705..eb18c5e70 100644
--- a/packages/falso/src/lib/lines.ts
+++ b/packages/falso/src/lib/lines.ts
@@ -14,6 +14,10 @@ import { data } from './lines.json';
*
* randLines({ length: 10 })
*
+ * @example
+ *
+ * randLines({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randLines(
options?: Options
diff --git a/packages/falso/src/lib/lion.ts b/packages/falso/src/lib/lion.ts
index 791099481..89bbbae82 100644
--- a/packages/falso/src/lib/lion.ts
+++ b/packages/falso/src/lib/lion.ts
@@ -14,6 +14,10 @@ import { data } from './lion.json';
*
* randLion({ length: 10 })
*
+ * @example
+ *
+ * randLion({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randLion(
options?: Options
diff --git a/packages/falso/src/lib/locale.ts b/packages/falso/src/lib/locale.ts
index 481e5f084..bc2677896 100644
--- a/packages/falso/src/lib/locale.ts
+++ b/packages/falso/src/lib/locale.ts
@@ -14,6 +14,10 @@ import { data } from './locale.json';
*
* randLocale({ length: 10 })
*
+ * @example
+ *
+ * randLocale({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randLocale(
options?: Options
diff --git a/packages/falso/src/lib/longitude.ts b/packages/falso/src/lib/longitude.ts
index e9802e30c..115f9aede 100644
--- a/packages/falso/src/lib/longitude.ts
+++ b/packages/falso/src/lib/longitude.ts
@@ -13,6 +13,10 @@ import { FakeOptions, fake, getRandomInRange } from './core/core';
*
* randLongitude({ length: 10 })
*
+ * @example
+ *
+ * randLongitude({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randLongitude(
options?: Options
diff --git a/packages/falso/src/lib/mac.ts b/packages/falso/src/lib/mac.ts
index bd2d33d49..a7c3d4f10 100644
--- a/packages/falso/src/lib/mac.ts
+++ b/packages/falso/src/lib/mac.ts
@@ -14,6 +14,10 @@ import { randHexaDecimal } from './hexa-decimal';
*
* randMac({ length: 10 })
*
+ * @example
+ *
+ * randMac({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randMac(
options?: Options
diff --git a/packages/falso/src/lib/mask.ts b/packages/falso/src/lib/mask.ts
index 1c1f7102c..7086efd78 100644
--- a/packages/falso/src/lib/mask.ts
+++ b/packages/falso/src/lib/mask.ts
@@ -18,6 +18,10 @@ import { randAlpha } from './alpha';
*
* randMask({ length: 10 })
*
+ * @example
+ *
+ * randMask({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randMask<
Options extends FakeOptions & {
diff --git a/packages/falso/src/lib/mime-type.ts b/packages/falso/src/lib/mime-type.ts
index ced906cbe..8eed816e9 100644
--- a/packages/falso/src/lib/mime-type.ts
+++ b/packages/falso/src/lib/mime-type.ts
@@ -14,6 +14,10 @@ import { data } from './mime-type.json';
*
* randMimeType({ length: 10 })
*
+ * @example
+ *
+ * randMimeType({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randMimeType(
options?: Options
diff --git a/packages/falso/src/lib/month.ts b/packages/falso/src/lib/month.ts
index 9ab5d9f76..05acd5112 100644
--- a/packages/falso/src/lib/month.ts
+++ b/packages/falso/src/lib/month.ts
@@ -22,6 +22,10 @@ export interface MonthOptions extends FakeOptions {
*
* randMonth({ length: 10 })
*
+ * @example
+ *
+ * randMonth({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randMonth(
options?: Options
diff --git a/packages/falso/src/lib/movie-character.ts b/packages/falso/src/lib/movie-character.ts
index 13de7a6ad..24a2859d2 100644
--- a/packages/falso/src/lib/movie-character.ts
+++ b/packages/falso/src/lib/movie-character.ts
@@ -13,6 +13,10 @@ import { data } from './movie-character.json';
*
* randMovieCharacter({ length: 10 })
*
+ * @example
+ *
+ * randMovieCharacter({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randMovieCharacter(
options?: Options
diff --git a/packages/falso/src/lib/movie.ts b/packages/falso/src/lib/movie.ts
index 89a0e1e31..de9390e03 100644
--- a/packages/falso/src/lib/movie.ts
+++ b/packages/falso/src/lib/movie.ts
@@ -13,6 +13,10 @@ import { data } from './movie.json';
*
* randMovie({ length: 10 })
*
+ * @example
+ *
+ * randMovie({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randMovie(
options?: Options
diff --git a/packages/falso/src/lib/music-genre.ts b/packages/falso/src/lib/music-genre.ts
index a2ce1ef8f..908f3356b 100644
--- a/packages/falso/src/lib/music-genre.ts
+++ b/packages/falso/src/lib/music-genre.ts
@@ -14,6 +14,10 @@ import { data } from './music-genre.json';
*
* randMusicGenre({ length: 10 })
*
+ * @example
+ *
+ * randMusicGenre({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randMusicGenre(
options?: Options
diff --git a/packages/falso/src/lib/nearby-gpscoordinate.ts b/packages/falso/src/lib/nearby-gpscoordinate.ts
index c5f7671cb..0d3a883bf 100644
--- a/packages/falso/src/lib/nearby-gpscoordinate.ts
+++ b/packages/falso/src/lib/nearby-gpscoordinate.ts
@@ -15,6 +15,10 @@ import { randLongitude } from './longitude';
*
* randNearbyGPSCoordinate({ length: 10 })
*
+ * @example
+ *
+ * randNearbyGPSCoordinate({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randNearbyGPSCoordinate(
options?: Options
diff --git a/packages/falso/src/lib/number.ts b/packages/falso/src/lib/number.ts
index ca91d706e..1195355eb 100644
--- a/packages/falso/src/lib/number.ts
+++ b/packages/falso/src/lib/number.ts
@@ -20,10 +20,6 @@ export interface RandomNumberOptions extends RandomInRangeOptions, FakeOptions {
*
* @example
*
- * randNumber({ length: 10 })
- *
- * @example
- *
* randNumber({ min: 10, max: 1000 }) // default is 'min': 0, 'max': 999_999
*
* @example
@@ -37,6 +33,15 @@ export interface RandomNumberOptions extends RandomInRangeOptions, FakeOptions {
* @example
*
* randNumber({ min: 1000, max: 2000, precision: 10 }) // 1250
+ *
+ * @example
+ *
+ * randNumber({ length: 10 })
+ *
+ * @example
+ *
+ * randNumber({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randNumber(
options?: Options
diff --git a/packages/falso/src/lib/oauth-provider.ts b/packages/falso/src/lib/oauth-provider.ts
index e6eca46fa..e3159c3d4 100644
--- a/packages/falso/src/lib/oauth-provider.ts
+++ b/packages/falso/src/lib/oauth-provider.ts
@@ -14,6 +14,10 @@ import { data } from './oauth-provider.json';
*
* randOAuthProvider({ length: 10 })
*
+ * @example
+ *
+ * randOAuthProvider({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randOAuthProvider(
options?: Options
diff --git a/packages/falso/src/lib/octal.ts b/packages/falso/src/lib/octal.ts
index 145c97c80..9264ae41b 100644
--- a/packages/falso/src/lib/octal.ts
+++ b/packages/falso/src/lib/octal.ts
@@ -1,4 +1,4 @@
-import { FakeOptions, fake } from './core/core';
+import { FakeOptions } from './core/core';
/**
* Generate a random octal.
@@ -13,6 +13,10 @@ import { FakeOptions, fake } from './core/core';
*
* randOctal({ length: 10 })
*
+ * @example
+ *
+ * randOctal({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randOctal(
options?: Options
diff --git a/packages/falso/src/lib/ordinal-direction.ts b/packages/falso/src/lib/ordinal-direction.ts
index 0db1a03da..7cdf23895 100644
--- a/packages/falso/src/lib/ordinal-direction.ts
+++ b/packages/falso/src/lib/ordinal-direction.ts
@@ -14,6 +14,10 @@ import { data } from './ordinal-direction.json';
*
* randOrdinalDirection({ length: 10 })
*
+ * @example
+ *
+ * randOrdinalDirection({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randOrdinalDirection(
options?: Options
diff --git a/packages/falso/src/lib/paragraph.ts b/packages/falso/src/lib/paragraph.ts
index 1c2a4f6a6..3483d1821 100644
--- a/packages/falso/src/lib/paragraph.ts
+++ b/packages/falso/src/lib/paragraph.ts
@@ -8,11 +8,15 @@ import { data } from './paragraph.json';
*
* @example
*
- * randJobTitle()
+ * randParagraph()
*
* @example
*
- * randJobTitle({ length: 10 })
+ * randParagraph({ length: 10 })
+ *
+ * @example
+ *
+ * randParagraph({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randParagraph(
diff --git a/packages/falso/src/lib/password.ts b/packages/falso/src/lib/password.ts
index 8120cfa8b..5a0a81914 100644
--- a/packages/falso/src/lib/password.ts
+++ b/packages/falso/src/lib/password.ts
@@ -16,11 +16,15 @@ export interface PasswordOptions extends FakeOptions {
*
* @example
*
+ * randPassword({ size: 10 }) // default is 15
+ *
+ * @example
+ *
* randPassword({ length: 10 })
*
* @example
*
- * randPassword({ size: 10 }) // default is 15
+ * randPassword({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randPassword(
diff --git a/packages/falso/src/lib/past-date.ts b/packages/falso/src/lib/past-date.ts
index ae168b160..ac690cdca 100644
--- a/packages/falso/src/lib/past-date.ts
+++ b/packages/falso/src/lib/past-date.ts
@@ -16,11 +16,15 @@ interface PastOptions extends FakeOptions {
*
* @example
*
+ * randPastDate({ years: 2 }) // default is 1
+ *
+ * @example
+ *
* randPastDate({ length: 10 })
*
* @example
*
- * randPastDate({ years: 2 }) // default is 1
+ * randPastDate({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randPastDate(
diff --git a/packages/falso/src/lib/permission.ts b/packages/falso/src/lib/permission.ts
index fb64021ca..ccde37ca8 100644
--- a/packages/falso/src/lib/permission.ts
+++ b/packages/falso/src/lib/permission.ts
@@ -16,11 +16,15 @@ interface PermissionOptions extends FakeOptions {
*
* @example
*
+ * randPermission({ numeric: true })
+ *
+ * @example
+ *
* randPermission({ length: 10 })
*
* @example
*
- * randPermission({ numeric: true })
+ * randPermission({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
*
*/
export function randPermission(
diff --git a/packages/falso/src/lib/person-title.ts b/packages/falso/src/lib/person-title.ts
index 0a7b4be26..420b4ddfc 100644
--- a/packages/falso/src/lib/person-title.ts
+++ b/packages/falso/src/lib/person-title.ts
@@ -14,6 +14,10 @@ import { data } from './person-title.json';
*
* randPersonTitle({ length: 10 })
*
+ * @example
+ *
+ * randPersonTitle({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randPersonTitle(
options?: Options
diff --git a/packages/falso/src/lib/phone-number.ts b/packages/falso/src/lib/phone-number.ts
index 981089078..55086f6c7 100644
--- a/packages/falso/src/lib/phone-number.ts
+++ b/packages/falso/src/lib/phone-number.ts
@@ -252,6 +252,10 @@ type CountryCode =
*
* randPhoneNumber({ length: 10 })
*
+ * @example
+ *
+ * randPhoneNumber({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randPhoneNumber<
Options extends FakeOptions & {
diff --git a/packages/falso/src/lib/phrase.ts b/packages/falso/src/lib/phrase.ts
index 620e2f778..963b9d1db 100644
--- a/packages/falso/src/lib/phrase.ts
+++ b/packages/falso/src/lib/phrase.ts
@@ -14,6 +14,10 @@ import { data } from './phrase.json';
*
* randPhrase({ length: 10 })
*
+ * @example
+ *
+ * randPhrase({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randPhrase(
options?: Options
diff --git a/packages/falso/src/lib/port.ts b/packages/falso/src/lib/port.ts
index c6fef25f0..1dd582626 100644
--- a/packages/falso/src/lib/port.ts
+++ b/packages/falso/src/lib/port.ts
@@ -14,6 +14,10 @@ import { randNumber } from './number';
*
* randPort({ length: 10 })
*
+ * @example
+ *
+ * randPort({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randPort(
options?: Options
diff --git a/packages/falso/src/lib/post.ts b/packages/falso/src/lib/post.ts
index a9a706dbb..f698bc89c 100644
--- a/packages/falso/src/lib/post.ts
+++ b/packages/falso/src/lib/post.ts
@@ -24,6 +24,10 @@ export interface Post {
*
* randPost({ length: 10 })
*
+ * @example
+ *
+ * randPost({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randPost(
options?: Options
diff --git a/packages/falso/src/lib/priority.ts b/packages/falso/src/lib/priority.ts
index 467ce7fcd..64dc4d555 100644
--- a/packages/falso/src/lib/priority.ts
+++ b/packages/falso/src/lib/priority.ts
@@ -14,6 +14,10 @@ import { data } from './priority.json';
*
* randPriority({ length: 10 })
*
+ * @example
+ *
+ * randPriority({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randPriority(
options?: Options
diff --git a/packages/falso/src/lib/product-adjective.ts b/packages/falso/src/lib/product-adjective.ts
index d457afc31..e42616958 100644
--- a/packages/falso/src/lib/product-adjective.ts
+++ b/packages/falso/src/lib/product-adjective.ts
@@ -14,6 +14,10 @@ import { data } from './product-adjective.json';
*
* randProductAdjective({ length: 10 })
*
+ * @example
+ *
+ * randProductAdjective({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randProductAdjective(
options?: Options
diff --git a/packages/falso/src/lib/product-category.ts b/packages/falso/src/lib/product-category.ts
index 15c2fa446..b6bbd3445 100644
--- a/packages/falso/src/lib/product-category.ts
+++ b/packages/falso/src/lib/product-category.ts
@@ -14,6 +14,10 @@ import { data } from './product-category.json';
*
* randProductCategory({ length: 10 })
*
+ * @example
+ *
+ * randProductCategory({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randProductCategory(
options?: Options
diff --git a/packages/falso/src/lib/product-description.ts b/packages/falso/src/lib/product-description.ts
index 8e9b8dc50..40bf22220 100644
--- a/packages/falso/src/lib/product-description.ts
+++ b/packages/falso/src/lib/product-description.ts
@@ -14,6 +14,10 @@ import { data } from './product-description.json';
*
* randProductDescription({ length: 10 })
*
+ * @example
+ *
+ * randProductDescription({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randProductDescription(
options?: Options
diff --git a/packages/falso/src/lib/product-material.ts b/packages/falso/src/lib/product-material.ts
index 2faca0141..d2c5268d8 100644
--- a/packages/falso/src/lib/product-material.ts
+++ b/packages/falso/src/lib/product-material.ts
@@ -14,6 +14,10 @@ import { data } from './product-material.json';
*
* randProductMaterial({ length: 10 })
*
+ * @example
+ *
+ * randProductMaterial({ length: 10, priority: 'unique' }) // default is 'length' ('length' | 'unique')
+ *
*/
export function randProductMaterial