@prismicio/mock
Version:
Generate mock Prismic documents, fields, Slices, and models for development and testing environments
69 lines (68 loc) • 2.34 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const prismic = require("@prismicio/client");
const changeCase = require("../lib/changeCase.cjs");
const createFaker = require("../lib/createFaker.cjs");
const contentRelationship = require("./contentRelationship.cjs");
const linkToMedia = require("./linkToMedia.cjs");
const link$1 = require("../model/link.cjs");
function _interopNamespaceDefault(e) {
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
if (e) {
for (const k in e) {
if (k !== "default") {
const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: () => e[k]
});
}
}
}
n.default = e;
return Object.freeze(n);
}
const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic);
const link = (config) => {
var _a, _b;
const faker = config.faker || createFaker.createFaker(config.seed);
const type = config.type || faker.randomElement([
prismic__namespace.LinkType.Web,
prismic__namespace.LinkType.Document,
prismic__namespace.LinkType.Media
]);
if (config.state === "empty") {
return {
link_type: type
};
} else {
switch (type) {
case prismic__namespace.LinkType.Document: {
return contentRelationship.contentRelationship({
faker,
state: config.state,
linkableDocuments: config.linkableDocuments
});
}
case prismic__namespace.LinkType.Media: {
return linkToMedia.linkToMedia({
faker,
state: config.state,
withText: config.withText
});
}
case prismic__namespace.LinkType.Web:
default: {
const model = config.model || link$1.link({ faker });
return {
link_type: prismic__namespace.LinkType.Web,
url: faker.url(),
target: config.withTargetBlank ?? (((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && faker.boolean()) ? "_blank" : void 0,
...config.withText ?? (((_b = model.config) == null ? void 0 : _b.allowText) && faker.boolean()) ? { text: changeCase.sentenceCase(faker.words(2)) } : {}
};
}
}
}
};
exports.link = link;
//# sourceMappingURL=link.cjs.map