UNPKG

@prismicio/mock

Version:

Generate mock Prismic documents, fields, Slices, and models for development and testing environments

31 lines (26 loc) 987 B
import * as prismic from "@prismicio/client" import { capitalCase, sentenceCase } from "../lib/changeCase" import { createFaker } from "../lib/createFaker" import type { MockModelConfig } from "../types" export type MockContentRelationshipModelConfig< CustomTypeIDs extends string = string, Tags extends string = string, > = { customTypeIDs?: readonly CustomTypeIDs[] tags?: readonly Tags[] } & MockModelConfig export const contentRelationship = <CustomTypeIDs extends string, Tags extends string>( config: MockContentRelationshipModelConfig<CustomTypeIDs, Tags>, ): prismic.CustomTypeModelContentRelationshipField<CustomTypeIDs, Tags> => { const faker = config.faker || createFaker(config.seed) return { type: prismic.CustomTypeModelFieldType.Link, config: { label: capitalCase(faker.word()), placeholder: sentenceCase(faker.words(3)), select: prismic.CustomTypeModelLinkSelectType.Document, customtypes: config.customTypeIDs, tags: config.tags, }, } }