@prismicio/mock 0.0.6 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/api/index.cjs +242 -122
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +669 -0
- package/dist/api/index.js.map +1 -0
- package/dist/index.cjs +581 -571
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +155 -247
- package/dist/{index.mjs → index.js} +574 -561
- package/dist/index.js.map +1 -0
- package/dist/model/index.cjs +294 -257
- package/dist/model/index.cjs.map +1 -0
- package/dist/model/index.d.ts +72 -106
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +556 -0
- package/dist/model/index.js.map +1 -0
- package/dist/value/index.cjs +500 -647
- package/dist/value/index.cjs.map +1 -0
- package/dist/value/index.d.ts +71 -129
- package/dist/value/index.d.ts.map +1 -0
- package/dist/value/index.js +1461 -0
- package/dist/value/index.js.map +1 -0
- package/package.json +30 -27
- package/src/api/query.ts +2 -2
- package/src/api/ref.ts +3 -3
- package/src/api/repository.ts +5 -5
- package/src/lib/buildContentRelationshipField.ts +6 -1
- package/src/lib/buildEmbedField.ts +16 -27
- package/src/lib/buildImageFieldImage.ts +49 -0
- package/src/lib/createFaker.ts +98 -20
- package/src/lib/generateCustomTypeId.ts +1 -1
- package/src/lib/generateFieldId.ts +1 -3
- package/src/lib/generateTags.ts +4 -12
- package/src/lib/getMockEmbedData.ts +33 -12
- package/src/lib/getMockImageData.ts +1 -1
- package/src/lib/lorem.ts +112 -0
- package/src/model/boolean.ts +1 -1
- package/src/model/buildMockGroupFieldMap.ts +65 -0
- package/src/model/color.ts +2 -2
- package/src/model/contentRelationship.ts +16 -23
- package/src/model/customType.ts +49 -48
- package/src/model/date.ts +2 -2
- package/src/model/embed.ts +2 -2
- package/src/model/geoPoint.ts +1 -1
- package/src/model/group.ts +9 -16
- package/src/model/image.ts +16 -20
- package/src/model/index.ts +2 -0
- package/src/model/integrationFields.ts +5 -3
- package/src/model/keyText.ts +2 -2
- package/src/model/link.ts +3 -3
- package/src/model/linkToMedia.ts +2 -2
- package/src/model/number.ts +2 -2
- package/src/model/richText.ts +6 -6
- package/src/model/select.ts +13 -18
- package/src/model/sharedSlice.ts +15 -42
- package/src/model/sharedSliceVariation.ts +36 -24
- package/src/model/slice.ts +19 -23
- package/src/model/sliceZone.ts +23 -59
- package/src/model/timestamp.ts +2 -2
- package/src/model/title.ts +5 -5
- package/src/model/uid.ts +2 -2
- package/src/types.ts +130 -88
- package/src/value/boolean.ts +1 -1
- package/src/value/color.ts +16 -6
- package/src/value/contentRelationship.ts +54 -39
- package/src/value/customType.ts +5 -5
- package/src/value/date.ts +25 -9
- package/src/value/embed.ts +32 -7
- package/src/value/geoPoint.ts +21 -11
- package/src/value/group.ts +31 -45
- package/src/value/image.ts +22 -9
- package/src/value/integrationFields.ts +26 -14
- package/src/value/keyText.ts +16 -6
- package/src/value/link.ts +36 -37
- package/src/value/linkToMedia.ts +19 -23
- package/src/value/number.ts +16 -6
- package/src/value/richText/embed.ts +2 -2
- package/src/value/richText/heading.ts +10 -17
- package/src/value/richText/image.ts +8 -6
- package/src/value/richText/index.ts +4 -9
- package/src/value/richText/list.ts +4 -8
- package/src/value/richText/oList.ts +4 -8
- package/src/value/richText/paragraph.ts +8 -4
- package/src/value/richText/preformatted.ts +9 -5
- package/src/value/select.ts +23 -8
- package/src/value/sharedSlice.ts +3 -3
- package/src/value/sharedSliceVariation.ts +4 -36
- package/src/value/slice.ts +3 -32
- package/src/value/sliceZone.ts +54 -69
- package/src/value/timestamp.ts +42 -16
- package/src/value/title.ts +26 -13
- package/src/value/uid.ts +2 -2
- package/dist/api/index.mjs +0 -515
- package/dist/model/index.mjs +0 -465
- package/dist/value/index.mjs +0 -1554
- package/src/lib/buildImageField.ts +0 -34
- package/src/lib/buildMockGroupFieldMap.ts +0 -84
package/src/lib/createFaker.ts
CHANGED
|
@@ -1,31 +1,109 @@
|
|
|
1
|
-
import
|
|
2
|
-
// @ts-expect-error - Missing .d.ts
|
|
3
|
-
import * as fakerLocaleEN from "faker/lib/locales/en/index.js";
|
|
4
|
-
// @ts-expect-error - Missing .d.ts
|
|
5
|
-
import Faker from "faker/lib/index.js";
|
|
1
|
+
import Rand from "rand-seed";
|
|
6
2
|
|
|
3
|
+
import { Seed } from "../types";
|
|
7
4
|
import { FAKER_SEED } from "../constants";
|
|
5
|
+
import { lorem, loremWords } from "./lorem";
|
|
8
6
|
|
|
9
|
-
export const createFaker = (seed = FAKER_SEED)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export const createFaker = (seed: Seed = FAKER_SEED) => {
|
|
8
|
+
const normalizedSeed = seed.toString();
|
|
9
|
+
|
|
10
|
+
if (createFaker.cache[normalizedSeed]) {
|
|
11
|
+
return createFaker.cache[normalizedSeed];
|
|
13
12
|
} else {
|
|
14
|
-
|
|
13
|
+
const faker = new Faker(normalizedSeed);
|
|
14
|
+
|
|
15
|
+
return (createFaker.cache[normalizedSeed] = faker);
|
|
15
16
|
}
|
|
17
|
+
};
|
|
18
|
+
createFaker.cache = {} as Record<string, Faker>;
|
|
19
|
+
|
|
20
|
+
const DAY_MS = 1000 * 60 * 60 * 24;
|
|
21
|
+
const YEAR_MS = DAY_MS * 365;
|
|
22
|
+
const YEAR_2022_MS = 52 * (YEAR_MS + DAY_MS / 4);
|
|
23
|
+
|
|
24
|
+
export class Faker {
|
|
25
|
+
private rand: Rand;
|
|
16
26
|
|
|
17
|
-
|
|
27
|
+
constructor(seed: string) {
|
|
28
|
+
this.rand = new Rand(seed);
|
|
29
|
+
}
|
|
18
30
|
|
|
19
|
-
|
|
20
|
-
return
|
|
31
|
+
boolean(): boolean {
|
|
32
|
+
return this.random() >= 0.5;
|
|
21
33
|
}
|
|
22
34
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
random(): number {
|
|
36
|
+
return this.rand.next();
|
|
37
|
+
}
|
|
26
38
|
|
|
27
|
-
|
|
39
|
+
randomElement<T>(elements: readonly T[]): T {
|
|
40
|
+
return elements[this.range(0, elements.length)];
|
|
41
|
+
}
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
randomElements<T>(elements: readonly T[]): T[] {
|
|
44
|
+
return elements.filter(() => this.boolean());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
range(min: number, max: number): number {
|
|
48
|
+
return Math.floor(this.rangeFloat(Math.ceil(min), Math.floor(max)));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
rangeFloat(min: number, max: number): number {
|
|
52
|
+
return this.random() * (max - min) + min;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
words(length: number, wordOffset = this.range(0, loremWords.length)): string {
|
|
56
|
+
return lorem(`${length}w`, wordOffset);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
word(): string {
|
|
60
|
+
return this.randomElement(loremWords);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
lorem(
|
|
64
|
+
length: Parameters<typeof lorem>[0],
|
|
65
|
+
wordOffset = this.range(0, loremWords.length),
|
|
66
|
+
): string {
|
|
67
|
+
return lorem(length, wordOffset);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
url(): string {
|
|
71
|
+
return `https://${this.word()}.example`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
hexColor(): string {
|
|
75
|
+
return `#${this.hash(6)}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
hash(length: number): string {
|
|
79
|
+
let hash = "";
|
|
80
|
+
|
|
81
|
+
for (let i = 0; i < length; i++) {
|
|
82
|
+
const chars = this.boolean() ? "abcdef" : "0123456789";
|
|
83
|
+
|
|
84
|
+
hash += chars[this.range(0, chars.length)];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return hash;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
date(): Date {
|
|
91
|
+
return new Date(YEAR_2022_MS + this.range(-YEAR_MS * 3, YEAR_MS * 3));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
dateAfter(date: Date): Date {
|
|
95
|
+
const timestamp = date.getTime();
|
|
96
|
+
|
|
97
|
+
return new Date(this.range(timestamp, timestamp + YEAR_MS * 3));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
dateBefore(date: Date): Date {
|
|
101
|
+
const timestamp = date.getTime();
|
|
102
|
+
|
|
103
|
+
return new Date(this.range(timestamp - YEAR_MS * 3, timestamp));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
dateBetween(min: Date, max: Date): Date {
|
|
107
|
+
return new Date(this.range(min.getTime(), max.getTime()));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -9,5 +9,5 @@ type GenerateFieldIdConfig = Pick<MockModelConfig, "seed">;
|
|
|
9
9
|
export const generateCustomTypeId = (config: GenerateFieldIdConfig): string => {
|
|
10
10
|
const faker = createFaker(config.seed);
|
|
11
11
|
|
|
12
|
-
return changeCase.snakeCase(faker.
|
|
12
|
+
return changeCase.snakeCase(faker.words(faker.range(1, 3)));
|
|
13
13
|
};
|
|
@@ -9,7 +9,5 @@ type GenerateFieldIdConfig = Pick<MockModelConfig, "seed">;
|
|
|
9
9
|
export const generateFieldId = (config: GenerateFieldIdConfig): string => {
|
|
10
10
|
const faker = createFaker(config.seed);
|
|
11
11
|
|
|
12
|
-
return changeCase.snakeCase(
|
|
13
|
-
faker.lorem.words(faker.datatype.number({ min: 1, max: 3 })),
|
|
14
|
-
);
|
|
12
|
+
return changeCase.snakeCase(faker.words(faker.range(1, 3)));
|
|
15
13
|
};
|
package/src/lib/generateTags.ts
CHANGED
|
@@ -12,16 +12,8 @@ type GenerateTagsConfig = {
|
|
|
12
12
|
export const generateTags = (config: GenerateTagsConfig): string[] => {
|
|
13
13
|
const faker = createFaker(config.seed);
|
|
14
14
|
|
|
15
|
-
return Array(
|
|
16
|
-
faker.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}),
|
|
20
|
-
)
|
|
21
|
-
.fill(undefined)
|
|
22
|
-
.map(() =>
|
|
23
|
-
changeCase.capitalCase(
|
|
24
|
-
faker.lorem.words(faker.datatype.number({ min: 1, max: 3 })),
|
|
25
|
-
),
|
|
26
|
-
);
|
|
15
|
+
return Array.from(
|
|
16
|
+
{ length: faker.range(config.min ?? 0, config.max ?? 2) },
|
|
17
|
+
() => changeCase.capitalCase(faker.words(faker.range(1, 3))),
|
|
18
|
+
);
|
|
27
19
|
};
|
|
@@ -4,60 +4,81 @@ import { MockEmbedData, MockValueConfig } from "../types";
|
|
|
4
4
|
|
|
5
5
|
const dataSet: MockEmbedData[] = [
|
|
6
6
|
{
|
|
7
|
-
|
|
7
|
+
version: "1.0",
|
|
8
|
+
type: "video",
|
|
8
9
|
embed_url: "https://www.youtube.com/embed/fiOwHYFkUz0",
|
|
9
10
|
thumbnail_url: "https://i.ytimg.com/vi/fiOwHYFkUz0/hqdefault.jpg",
|
|
10
11
|
thumbnail_height: 360,
|
|
11
12
|
thumbnail_width: 480,
|
|
12
13
|
html: '<iframe width="200" height="113" src="https://www.youtube.com/embed/fiOwHYFkUz0?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
|
|
14
|
+
width: 200,
|
|
15
|
+
height: 113,
|
|
13
16
|
},
|
|
14
17
|
{
|
|
15
|
-
|
|
18
|
+
version: "1.0",
|
|
19
|
+
type: "video",
|
|
16
20
|
embed_url: "https://www.youtube.com/embed/c-ATzcy6VkI",
|
|
17
21
|
thumbnail_url: "https://i.ytimg.com/vi/c-ATzcy6VkI/hqdefault.jpg",
|
|
18
22
|
thumbnail_height: 360,
|
|
19
23
|
thumbnail_width: 480,
|
|
20
24
|
html: '<iframe width="200" height="113" src="https://www.youtube.com/embed/c-ATzcy6VkI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
|
|
25
|
+
width: 200,
|
|
26
|
+
height: 113,
|
|
21
27
|
},
|
|
22
28
|
{
|
|
23
|
-
|
|
29
|
+
version: "1.0",
|
|
30
|
+
type: "video",
|
|
24
31
|
embed_url: "https://www.youtube.com/watch?v=fiOwHYFkUz0",
|
|
25
32
|
thumbnail_url: "https://i.ytimg.com/vi/iewZXv94XGY/hqdefault.jpg",
|
|
26
33
|
thumbnail_height: 360,
|
|
27
34
|
thumbnail_width: 480,
|
|
28
35
|
html: '<iframe width="200" height="113" src="https://www.youtube.com/embed/iewZXv94XGY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
|
|
36
|
+
width: 200,
|
|
37
|
+
height: 113,
|
|
29
38
|
},
|
|
30
39
|
{
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
version: "1.0",
|
|
41
|
+
type: "rich",
|
|
42
|
+
embed_url: "https://twitter.com/prismicio/status/1356293316158095361",
|
|
33
43
|
thumbnail_url: null,
|
|
34
44
|
thumbnail_height: null,
|
|
35
45
|
thumbnail_width: null,
|
|
36
46
|
html: '<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Gatsby is a popular choice for Prismic users and we work hard on delivering a CMS that plays to its strengths.<br><br>But, what makes <a href="https://twitter.com/GatsbyJS?ref_src=twsrc%5Etfw">@GatsbyJS</a> so popular?<br><br>Here are some of <a href="https://twitter.com/mxstbr?ref_src=twsrc%5Etfw">@mxstbr</a>'s thoughts on Gatsby's success and how they're improving developer experience.<a href="https://t.co/ZjCPvsWWUD">https://t.co/ZjCPvsWWUD</a> <a href="https://t.co/EQqzJpeNKl">pic.twitter.com/EQqzJpeNKl</a></p>— Prismic (@prismicio) <a href="https://twitter.com/prismicio/status/1356293316158095361?ref_src=twsrc%5Etfw">February 1, 2021</a></blockquote>\n<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>\n',
|
|
47
|
+
width: 200,
|
|
48
|
+
height: 113,
|
|
37
49
|
},
|
|
38
50
|
{
|
|
39
|
-
|
|
51
|
+
type: "rich",
|
|
52
|
+
version: "1.0",
|
|
53
|
+
embed_url: "https://twitter.com/timbenniks/status/1304146886832594944",
|
|
40
54
|
thumbnail_url: null,
|
|
41
55
|
thumbnail_width: null,
|
|
42
56
|
thumbnail_height: null,
|
|
43
|
-
embed_url: "https://twitter.com/timbenniks/status/1304146886832594944",
|
|
44
57
|
html: '<blockquote class="twitter-tweet"><p lang="en" dir="ltr">I’ve been diving deep on <a href="https://twitter.com/prismicio?ref_src=twsrc%5Etfw">@prismicio</a> <a href="https://twitter.com/hashtag/slicemachine?src=hash&ref_src=twsrc%5Etfw">#slicemachine</a> today. I made all my own components and I used custom slices. It works like a charm with <a href="https://twitter.com/nuxt_js?ref_src=twsrc%5Etfw">@nuxt_js</a>. Also: I’m coding with this view. <a href="https://t.co/F0I8X9gz39">pic.twitter.com/F0I8X9gz39</a></p>— Tim Benniks (@timbenniks) <a href="https://twitter.com/timbenniks/status/1304146886832594944?ref_src=twsrc%5Etfw">September 10, 2020</a></blockquote>\n<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>\n',
|
|
58
|
+
width: 200,
|
|
59
|
+
height: 113,
|
|
45
60
|
},
|
|
46
61
|
{
|
|
47
|
-
|
|
62
|
+
version: "1.0",
|
|
63
|
+
type: "rich",
|
|
64
|
+
embed_url: "https://twitter.com/prismicio/status/1354112310252630016",
|
|
48
65
|
thumbnail_url: null,
|
|
49
66
|
thumbnail_width: null,
|
|
50
67
|
thumbnail_height: null,
|
|
51
|
-
embed_url: "https://twitter.com/prismicio/status/1354112310252630016",
|
|
52
68
|
html: '<blockquote class="twitter-tweet"><p lang="en" dir="ltr">We're launching a new <a href="https://twitter.com/hashtag/SliceContest?src=hash&ref_src=twsrc%5Etfw">#SliceContest</a> tomorrow along with Slice Machine upgrades.<br><br>Want to know more? Join us at tomorrow's Product Meet-up👇<a href="https://t.co/prYSypiAvB">https://t.co/prYSypiAvB</a><br><br>We can't tell you any further details for now, but here's a sneak peek at the prizes👀 <a href="https://t.co/fV1eoGlEBh">pic.twitter.com/fV1eoGlEBh</a></p>— Prismic (@prismicio) <a href="https://twitter.com/prismicio/status/1354112310252630016?ref_src=twsrc%5Etfw">January 26, 2021</a></blockquote>\n<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>\n',
|
|
69
|
+
width: 200,
|
|
70
|
+
height: 113,
|
|
53
71
|
},
|
|
54
72
|
{
|
|
55
|
-
|
|
73
|
+
version: "1.0",
|
|
74
|
+
type: "rich",
|
|
75
|
+
embed_url: "https://twitter.com/prismicio/status/1354835716430319617",
|
|
56
76
|
thumbnail_url: null,
|
|
57
77
|
thumbnail_width: null,
|
|
58
78
|
thumbnail_height: null,
|
|
59
|
-
embed_url: "https://twitter.com/prismicio/status/1354835716430319617",
|
|
60
79
|
html: '<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Does anyone want to create a wildly popular website for discussing 'Wall Street Bets' using Prismic?<br><br>It may or may not have to look a lot like <a href="https://twitter.com/hashtag/reddit?src=hash&ref_src=twsrc%5Etfw">#reddit</a> and we won't make it private.<br><br>Just asking for some friends...</p>— Prismic (@prismicio) <a href="https://twitter.com/prismicio/status/1354835716430319617?ref_src=twsrc%5Etfw">January 28, 2021</a></blockquote>\n<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>\n',
|
|
80
|
+
width: 200,
|
|
81
|
+
height: 113,
|
|
61
82
|
},
|
|
62
83
|
];
|
|
63
84
|
type GetMockEmbedDataConfig = Pick<MockValueConfig, "seed">;
|
|
@@ -67,5 +88,5 @@ export const getMockEmbedData = (
|
|
|
67
88
|
): MockEmbedData => {
|
|
68
89
|
const faker = createFaker(config.seed);
|
|
69
90
|
|
|
70
|
-
return faker.
|
|
91
|
+
return faker.randomElement(dataSet);
|
|
71
92
|
};
|
package/src/lib/lorem.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is a modified version of fast-lorem-ipsum from Amit Gupta.
|
|
3
|
+
* The changes are made to support starting the return value from a configurable
|
|
4
|
+
* word offset.
|
|
5
|
+
*
|
|
6
|
+
* https://github.com/amitguptagwl/fast-lorem-ipsum/tree/7f836ee59a23cc75e7ca5b1a1747ea888eab31c7
|
|
7
|
+
*
|
|
8
|
+
* MIT License
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2017 Amit Gupta
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in
|
|
20
|
+
* all copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const wordsString =
|
|
32
|
+
"lorem ipsum dolor sit amet, consectetur adipiscing elit ut aliquam, purus sit amet luctus venenatis, lectus magna fringilla urna, porttitor rhoncus dolor purus non enim praesent elementum facilisis leo, vel fringilla est ullamcorper eget nulla facilisi etiam dignissim diam quis enim lobortis scelerisque fermentum dui faucibus in ornare quam viverra orci sagittis eu volutpat odio facilisis mauris sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac odio tempor orci dapibus ultrices in iaculis nunc sed augue lacus, viverra vitae congue eu, consequat ac felis donec et odio pellentesque diam volutpat commodo sed egestas egestas fringilla phasellus faucibus scelerisque eleifend donec pretium vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit dignissim sodales ut eu sem integer vitae justo eget magna fermentum iaculis eu non diam phasellus vestibulum lorem sed risus ultricies tristique nulla aliquet enim tortor, at auctor urna nunc id cursus metus aliquam eleifend mi in nulla posuere sollicitudin aliquam ultrices sagittis orci, a scelerisque purus semper eget duis at tellus at urna condimentum mattis pellentesque id nibh tortor, id aliquet lectus proin nibh nisl, condimentum id venenatis a, condimentum vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas sed tempus, urna et pharetra pharetra, massa massa ultricies mi, quis hendrerit dolor magna eget est lorem ipsum dolor sit amet, consectetur adipiscing elit pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas integer eget aliquet nibh praesent tristique magna sit amet purus gravida quis blandit turpis cursus in hac habitasse platea dictumst quisque sagittis, purus sit amet volutpat consequat, mauris nunc congue nisi, vitae suscipit tellus mauris a diam maecenas sed enim ut sem viverra aliquet eget sit amet tellus cras adipiscing enim eu turpis egestas pretium aenean pharetra, magna ac placerat vestibulum, lectus mauris ultrices eros, in cursus turpis massa tincidunt dui ut ornare lectus sit amet est placerat in egestas erat imperdiet sed euismod nisi porta lorem mollis aliquam ut porttitor leo a diam sollicitudin tempor id eu nisl nunc mi ipsum, faucibus vitae aliquet nec, ullamcorper sit amet risus nullam eget felis eget nunc lobortis mattis aliquam faucibus purus in massa tempor nec feugiat nisl pretium fusce id velit ut tortor pretium viverra suspendisse potenti nullam ac tortor vitae purus faucibus ornare suspendisse sed nisi lacus, sed viverra tellus in hac habitasse platea dictumst vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue eget arcu dictum varius duis at consectetur lorem donec massa sapien, faucibus et molestie ac, feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi tincidunt ornare massa, eget egestas purus viverra accumsan in nisl nisi, scelerisque eu ultrices vitae, auctor eu augue ut lectus arcu, bibendum at varius vel, pharetra vel turpis nunc eget lorem dolor, sed viverra ipsum nunc aliquet bibendum enim, facilisis gravida neque convallis a cras semper auctor neque, vitae tempus quam pellentesque nec nam aliquam sem et tortor consequat id porta nibh venenatis cras sed felis eget velit aliquet sagittis id consectetur purus ut faucibus pulvinar elementum integer enim neque, volutpat ac tincidunt vitae, semper quis lectus nulla at volutpat diam ut venenatis tellus in metus vulputate eu scelerisque felis imperdiet proin fermentum leo vel orci porta non pulvinar neque laoreet suspendisse interdum consectetur libero, id faucibus nisl tincidunt eget nullam non nisi est, sit amet facilisis magna etiam tempor, orci eu lobortis elementum, nibh tellus molestie nunc, non blandit massa enim nec dui nunc mattis enim ut tellus elementum sagittis vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum morbi blandit cursus risus, at ultrices mi tempus imperdiet nulla malesuada pellentesque elit eget gravida cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus mauris vitae ultricies leo integer malesuada nunc vel risus commodo viverra maecenas accumsan, lacus vel facilisis volutpat, est velit egestas dui, id ornare arcu odio ut sem nulla pharetra diam sit amet nisl suscipit adipiscing bibendum est ultricies integer quis auctor elit sed vulputate mi sit amet mauris commodo quis imperdiet massa tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc, consequat interdum varius sit amet, mattis vulputate enim nulla aliquet porttitor lacus, luctus accumsan tortor posuere ac ut consequat semper viverra nam libero justo, laoreet sit amet cursus sit amet, dictum sit amet justo donec enim diam, vulputate ut pharetra sit amet, aliquam id diam maecenas ultricies mi eget mauris pharetra et ultrices neque ornare aenean euismod elementum nisi, quis eleifend quam adipiscing vitae proin sagittis, nisl rhoncus mattis rhoncus, urna neque viverra justo, nec ultrices dui sapien eget mi proin sed libero enim, sed faucibus turpis in eu mi bibendum neque egestas congue quisque egestas diam in arcu cursus euismod quis viverra nibh cras pulvinar mattis nunc, sed blandit libero volutpat sed cras ornare arcu dui vivamus arcu felis, bibendum ut tristique et, egestas quis ipsum suspendisse ultrices gravida dictum fusce ut placerat orci nulla pellentesque dignissim enim, sit amet venenatis urna cursus eget nunc scelerisque viverra mauris, in aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod in pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id aliquet risus feugiat in ante metus, dictum at tempor commodo, ullamcorper a lacus vestibulum sed arcu non odio euismod lacinia at quis risus sed vulputate odio ut enim blandit volutpat maecenas volutpat blandit aliquam etiam erat velit, scelerisque in dictum non, consectetur a erat nam at lectus urna duis convallis convallis tellus, id interdum velit laoreet id donec ultrices tincidunt arcu, non sodales neque sodales ut etiam sit amet nisl purus, in mollis nunc sed id semper risus in hendrerit gravida rutrum quisque non tellus orci, ac auctor augue mauris augue neque, gravida in fermentum et, sollicitudin ac orci phasellus egestas tellus rutrum tellus pellentesque eu tincidunt tortor aliquam nulla facilisi cras fermentum, odio eu feugiat pretium, nibh ipsum consequat nisl, vel pretium lectus quam id leo in vitae turpis massa sed elementum tempus egestas sed sed risus pretium quam vulputate dignissim suspendisse in est ante in nibh mauris, cursus mattis molestie a, iaculis at erat pellentesque adipiscing commodo elit, at imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis urna, id volutpat lacus laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean et tortor at risus viverra adipiscing at in tellus integer feugiat scelerisque varius morbi enim nunc, faucibus a pellentesque sit amet, porttitor eget dolor morbi non arcu risus, quis varius quam quisque id diam vel quam elementum pulvinar etiam non quam lacus suspendisse faucibus interdum posuere lorem ipsum dolor sit amet, consectetur adipiscing elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi nullam vehicula ipsum a arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque mauris pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas maecenas pharetra convallis posuere morbi leo urna, molestie at elementum eu, facilisis sed odio morbi quis commodo odio aenean sed adipiscing diam donec adipiscing tristique risus nec feugiat in fermentum posuere urna nec tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit lectus a molestie";
|
|
33
|
+
|
|
34
|
+
export const loremWords = wordsString.split(" ");
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns "Lorem ipsum" text of a specified length.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* lorem("100w"); // 100 words
|
|
43
|
+
* lorem("200c"); // 200 characters
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @param length - Length of the returned text in the form of `${number}w` or
|
|
47
|
+
* `${number}c`. `w` means words, `c` means characters.
|
|
48
|
+
*
|
|
49
|
+
* @returns Lorem ipsum text.
|
|
50
|
+
*/
|
|
51
|
+
export const lorem = (length: `${number}w` | `${number}c`, wordOffset = 0) => {
|
|
52
|
+
const count = parseInt(length.substring(0, length.length - 1));
|
|
53
|
+
const countType = length.charAt(length.length - 1);
|
|
54
|
+
|
|
55
|
+
if (!isNaN(count) && (countType === "w" || countType === "c")) {
|
|
56
|
+
// Build a list of indicies for each space in the list of
|
|
57
|
+
// words. Only do this on the first call of `lorem`. The list
|
|
58
|
+
// is cached to a property on `lorem` itself.
|
|
59
|
+
if (!lorem.spaceIndices.length) {
|
|
60
|
+
let startIndex = -1;
|
|
61
|
+
do {
|
|
62
|
+
const index = wordsString.indexOf(" ", startIndex + 1);
|
|
63
|
+
|
|
64
|
+
lorem.spaceIndices.push(index);
|
|
65
|
+
|
|
66
|
+
startIndex = index;
|
|
67
|
+
} while (startIndex !== -1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (countType === "c") {
|
|
71
|
+
return wordsString.substring(0, count);
|
|
72
|
+
} else {
|
|
73
|
+
let sentence = "";
|
|
74
|
+
|
|
75
|
+
const startSpaceIndex =
|
|
76
|
+
lorem.spaceIndices[(wordOffset % lorem.spaceIndices.length) - 1];
|
|
77
|
+
|
|
78
|
+
const endSpaceIndex =
|
|
79
|
+
lorem.spaceIndices[
|
|
80
|
+
(((wordOffset % lorem.spaceIndices.length) + count) %
|
|
81
|
+
lorem.spaceIndices.length) -
|
|
82
|
+
1
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
if (
|
|
86
|
+
count + (wordOffset % lorem.spaceIndices.length) >
|
|
87
|
+
lorem.spaceIndices.length
|
|
88
|
+
) {
|
|
89
|
+
sentence += wordsString.substring(startSpaceIndex + 1) + " ";
|
|
90
|
+
|
|
91
|
+
const wraparoundCounts =
|
|
92
|
+
Math.floor(count / lorem.spaceIndices.length) - 1;
|
|
93
|
+
for (let i = 0; i < wraparoundCounts; i++) {
|
|
94
|
+
sentence += wordsString + " ";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
sentence += wordsString.substring(0, endSpaceIndex);
|
|
98
|
+
} else {
|
|
99
|
+
sentence = wordsString.substring(startSpaceIndex + 1, endSpaceIndex);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (sentence.charAt(sentence.length - 1) === ",") {
|
|
103
|
+
return sentence.substring(0, sentence.length - 1);
|
|
104
|
+
} else {
|
|
105
|
+
return sentence.substring(0, sentence.length);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
throw new Error("Length must be of the form `${number}w` or `${number}c`");
|
|
111
|
+
};
|
|
112
|
+
lorem.spaceIndices = [] as number[];
|
package/src/model/boolean.ts
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GroupFieldModelMap, MockModelConfig, ValueOf } from "../types";
|
|
2
|
+
|
|
3
|
+
import { boolean } from "../model/boolean";
|
|
4
|
+
import { color } from "../model/color";
|
|
5
|
+
import { contentRelationship } from "../model/contentRelationship";
|
|
6
|
+
import { date } from "../model/date";
|
|
7
|
+
import { embed } from "../model/embed";
|
|
8
|
+
import { geoPoint } from "../model/geoPoint";
|
|
9
|
+
import { image } from "../model/image";
|
|
10
|
+
import { integrationFields } from "../model/integrationFields";
|
|
11
|
+
import { keyText } from "../model/keyText";
|
|
12
|
+
import { link } from "../model/link";
|
|
13
|
+
import { linkToMedia } from "../model/linkToMedia";
|
|
14
|
+
import { number } from "../model/number";
|
|
15
|
+
import { richText } from "../model/richText";
|
|
16
|
+
import { select } from "../model/select";
|
|
17
|
+
import { timestamp } from "../model/timestamp";
|
|
18
|
+
import { title } from "../model/title";
|
|
19
|
+
|
|
20
|
+
import { createFaker } from "../lib/createFaker";
|
|
21
|
+
import { generateFieldId } from "../lib/generateFieldId";
|
|
22
|
+
|
|
23
|
+
const mockModelFns = {
|
|
24
|
+
boolean,
|
|
25
|
+
color,
|
|
26
|
+
contentRelationship,
|
|
27
|
+
date,
|
|
28
|
+
embed,
|
|
29
|
+
geoPoint,
|
|
30
|
+
image,
|
|
31
|
+
integrationFields,
|
|
32
|
+
keyText,
|
|
33
|
+
link,
|
|
34
|
+
linkToMedia,
|
|
35
|
+
number,
|
|
36
|
+
richText,
|
|
37
|
+
select,
|
|
38
|
+
timestamp,
|
|
39
|
+
title,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type BuildMockGroupFieldMapConfig = MockModelConfig;
|
|
43
|
+
|
|
44
|
+
export const buildMockGroupFieldMap = (
|
|
45
|
+
config: BuildMockGroupFieldMapConfig = {},
|
|
46
|
+
): GroupFieldModelMap => {
|
|
47
|
+
const faker = createFaker(config.seed);
|
|
48
|
+
|
|
49
|
+
const fields: GroupFieldModelMap = {};
|
|
50
|
+
|
|
51
|
+
const fieldTypes = faker.randomElements(
|
|
52
|
+
Object.keys(mockModelFns) as (keyof typeof mockModelFns)[],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
for (const fieldType of fieldTypes) {
|
|
56
|
+
const fieldId = generateFieldId({ seed: config.seed });
|
|
57
|
+
const mockModelFn = mockModelFns[fieldType] as (
|
|
58
|
+
config: MockModelConfig,
|
|
59
|
+
) => ValueOf<GroupFieldModelMap>;
|
|
60
|
+
|
|
61
|
+
fields[fieldId] = mockModelFn({ seed: config.seed });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return fields;
|
|
65
|
+
};
|
package/src/model/color.ts
CHANGED
|
@@ -15,8 +15,8 @@ export const color = (
|
|
|
15
15
|
return {
|
|
16
16
|
type: prismicT.CustomTypeModelFieldType.Color,
|
|
17
17
|
config: {
|
|
18
|
-
label: changeCase.capitalCase(faker.
|
|
19
|
-
placeholder: changeCase.sentenceCase(faker.
|
|
18
|
+
label: changeCase.capitalCase(faker.word()),
|
|
19
|
+
placeholder: changeCase.sentenceCase(faker.words(3)),
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
};
|
|
@@ -2,40 +2,33 @@ import * as prismicT from "@prismicio/types";
|
|
|
2
2
|
import * as changeCase from "change-case";
|
|
3
3
|
|
|
4
4
|
import { createFaker } from "../lib/createFaker";
|
|
5
|
-
import { generateCustomTypeId } from "../lib/generateCustomTypeId";
|
|
6
5
|
|
|
7
6
|
import { MockModelConfig } from "../types";
|
|
8
7
|
|
|
9
|
-
export type MockContentRelationshipModelConfig
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export type MockContentRelationshipModelConfig<
|
|
9
|
+
CustomTypeIDs extends string = string,
|
|
10
|
+
Tags extends string = string,
|
|
11
|
+
> = {
|
|
12
|
+
customTypeIDs?: readonly CustomTypeIDs[];
|
|
13
|
+
tags?: readonly Tags[];
|
|
12
14
|
} & MockModelConfig;
|
|
13
15
|
|
|
14
|
-
export const contentRelationship =
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
export const contentRelationship = <
|
|
17
|
+
CustomTypeIDs extends string,
|
|
18
|
+
Tags extends string,
|
|
19
|
+
>(
|
|
20
|
+
config: MockContentRelationshipModelConfig<CustomTypeIDs, Tags> = {},
|
|
21
|
+
): prismicT.CustomTypeModelContentRelationshipField<CustomTypeIDs, Tags> => {
|
|
17
22
|
const faker = createFaker(config.seed);
|
|
18
23
|
|
|
19
24
|
return {
|
|
20
25
|
type: prismicT.CustomTypeModelFieldType.Link,
|
|
21
26
|
config: {
|
|
22
|
-
label: changeCase.capitalCase(faker.
|
|
23
|
-
placeholder: changeCase.sentenceCase(faker.
|
|
27
|
+
label: changeCase.capitalCase(faker.word()),
|
|
28
|
+
placeholder: changeCase.sentenceCase(faker.words(3)),
|
|
24
29
|
select: prismicT.CustomTypeModelLinkSelectType.Document,
|
|
25
|
-
customtypes: config.
|
|
26
|
-
|
|
27
|
-
.fill(undefined)
|
|
28
|
-
.map(() => generateCustomTypeId({ seed: config.seed }))
|
|
29
|
-
: undefined,
|
|
30
|
-
tags: config.constrainTags
|
|
31
|
-
? Array(faker.datatype.number({ min: 1, max: 3 }))
|
|
32
|
-
.fill(undefined)
|
|
33
|
-
.map(() =>
|
|
34
|
-
changeCase.capitalCase(
|
|
35
|
-
faker.lorem.words(faker.datatype.number({ min: 1, max: 3 })),
|
|
36
|
-
),
|
|
37
|
-
)
|
|
38
|
-
: undefined,
|
|
30
|
+
customtypes: config.customTypeIDs,
|
|
31
|
+
tags: config.tags,
|
|
39
32
|
},
|
|
40
33
|
};
|
|
41
34
|
};
|