UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

243 lines (241 loc) 6.05 kB
import { __export } from "../_virtual/rolldown_runtime.js"; //#region src/helpers/isFilled.ts var isFilled_exports = /* @__PURE__ */ __export({ color: () => color, contentRelationship: () => contentRelationship, date: () => date, embed: () => embed, geoPoint: () => geoPoint, group: () => group, image: () => image, imageThumbnail: () => imageThumbnail, integration: () => integration, integrationField: () => integrationField, integrationFields: () => integrationFields, keyText: () => keyText, link: () => link, linkToMedia: () => linkToMedia, number: () => number, repeatable: () => repeatable, richText: () => richText, select: () => select, sliceZone: () => sliceZone, table: () => table, timestamp: () => timestamp, title: () => title }); /** * Determines if a value is not nullish (i.e. not `null` or `undefined`). This * is used to check if nullable field values are filled. * * @param input - The value to check. * * @returns `true` if `input` is not nullish, `false` otherwise. */ const isNonNullish = (input) => { return input != null; }; /** * Determines if an array is not empty. This is used to check if array-based * fields are filled. * * @param input - The array to check. * * @returns `true` if `input` has at least one element, `false` otherwise. */ const isNonEmptyArray = (input) => { return !!input.length; }; /** * Determines if a rich text field is filled. * * @param field - rich text field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const richText = (field) => { if (!isNonNullish(field)) return false; else if (field.length === 1 && "text" in field[0]) return !!field[0].text; else return !!field.length; }; /** * Determines if a title field is filled. * * @param field - Title field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const title = richText; /** * Determines if an image thumbnail is filled. * * @param thumbnail - Image thumbnail to check. * * @returns `true` if the thumbnail is filled, `false` otherwise. */ const imageThumbnail = (thumbnail) => { return isNonNullish(thumbnail) && !!thumbnail.url; }; /** * Determines if an image field is filled. * * @param field - Image field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const image = imageThumbnail; /** * Determines if a link field is filled. * * @param field - Link field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const link = (field) => { return isNonNullish(field) && ("id" in field || "url" in field); }; /** * Determines if a link to media field is filled. * * @param field - Link to media field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const linkToMedia = link; /** * Determines if a content relationship field is filled. * * @param field - Content relationship field to check. * * @returns `true` if the field is filled, `false` otherwise. */ const contentRelationship = link; /** * Determines if a date field is filled. * * @param field - Date field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const date = isNonNullish; /** * Determines if a timestamp field is filled. * * @param field - Timestamp field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const timestamp = isNonNullish; /** * Determines if a color field is filled. * * @param field - Color field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const color = isNonNullish; /** * Determines if a number field is filled. * * @param field - Number field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const number = isNonNullish; /** * Determines if a key text field is filled. * * @param field - Key text field to check. * * @returns `true` if the field is filled, `false` otherwise. */ const keyText = (field) => { return !!field; }; /** * Determines if a select field is filled. * * @param field - Select field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const select = isNonNullish; /** * Determines if an embed field is filled. * * @param field - Embed field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const embed = (field) => { return isNonNullish(field) && !!field.embed_url; }; /** * Determines if a geopoint field is filled. * * @param field - Geopoint field to check. * * @returns `true` if the field is filled, `false` otherwise. */ const geoPoint = (field) => { return isNonNullish(field) && "longitude" in field; }; /** * Determines if a table field is filled. * * @param field - Table field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const table = isNonNullish; /** * Determines if an integration field is filled. * * @param field - Integration field to check. * * @returns `true` if `field` is filled, `false` otherwise. */ const integration = isNonNullish; /** * @deprecated Renamed to `integration`. */ const integrationField = integration; /** * @deprecated Renamed to `integrationField`. */ const integrationFields = integration; /** * Determines if a repeatable field has at least one item. * * @param repeatable - Repeatable to check. * * @returns `true` if `repeatable` contains at least one item, `false` * otherwise. */ const repeatable = (repeatable$1) => { return isNonNullish(repeatable$1) && isNonEmptyArray(repeatable$1); }; /** * Determines if a group has at least one item. * * @param group - Group to check. * * @returns `true` if the group contains at least one item, `false` otherwise. */ const group = (group$1) => { return isNonNullish(group$1) && isNonEmptyArray(group$1); }; /** * Determines if a slice zone has at least one slice. * * @param slices - Slice zone to check. * * @returns `true` if the slice zone contains at least one slice, `false` * otherwise. */ const sliceZone = (slices) => { return isNonNullish(slices) && isNonEmptyArray(slices); }; //#endregion export { imageThumbnail, isFilled_exports, link }; //# sourceMappingURL=isFilled.js.map