{"version":3,"file":"isFilled.cjs","sources":["../../src/isFilled.ts"],"sourcesContent":["import type {\n\tAnyOEmbed,\n\tAnyRegularField,\n\tColorField,\n\tDateField,\n\tEmbedField,\n\tGeoPointField,\n\tGroupField,\n\tImageField,\n\tImageFieldImage,\n\tIntegrationFields,\n\tKeyTextField,\n\tLinkField,\n\tLinkToMediaField,\n\tNumberField,\n\tRelationField,\n\tRichTextField,\n\tSelectField,\n\tSharedSlice,\n\tSlice,\n\tSliceZone,\n\tTimestampField,\n\tTitleField,\n} from \"@prismicio/types\";\n\n/**\n * Determines if a value is not nullish (i.e. not `null` or `undefined`). This\n * is used to check if nullable field values are filled.\n *\n * @param input - The value to check.\n *\n * @returns `true` if `input` is not nullish, `false` otherwise.\n */\nconst isNonNullish = <T>(input: T): input is NonNullable<T> => {\n\treturn input != null;\n};\n\n/**\n * Determines if an array is not empty. This is used to check if array-based\n * fields are filled.\n *\n * @param input - The array to check.\n *\n * @returns `true` if `input` has at least one element, `false` otherwise.\n */\nconst isNonEmptyArray = <T>(input: T[]): input is [T, ...T[]] => {\n\treturn !!input.length;\n};\n\n/**\n * Determines if a Rich Text field is filled.\n *\n * @param field - Rich Text field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const richText = (\n\tfield: RichTextField | null | undefined,\n): field is RichTextField<\"filled\"> => {\n\tif (!isNonNullish(field)) {\n\t\treturn false;\n\t} else if (field.length === 1 && \"text\" in field[0]) {\n\t\treturn !!field[0].text;\n\t} else {\n\t\treturn !!field.length;\n\t}\n};\n\n/**\n * Determines if a Title field is filled.\n *\n * @param field - Title field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const title = richText as (\n\tfield: TitleField | null | undefined,\n) => field is TitleField<\"filled\">;\n\n/**\n * Determines if an Image thumbnail is filled.\n *\n * @param thumbnail - Image thumbnail to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const imageThumbnail = (\n\tthumbnail: ImageFieldImage | null | undefined,\n): thumbnail is ImageFieldImage<\"filled\"> => {\n\treturn isNonNullish(thumbnail) && !!thumbnail.url;\n};\n\n/**\n * Determines if an Image field is filled.\n *\n * @param field - Image field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const image = imageThumbnail as <\n\tThumbnailNames extends string | null = never,\n>(\n\tfield: ImageField<ThumbnailNames> | null | undefined,\n) => field is ImageField<ThumbnailNames, \"filled\">;\n\n/**\n * Determines if a Link field is filled.\n *\n * @param field - Link field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const link = <\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n>(\n\tfield: LinkField<TypeEnum, LangEnum, DataInterface> | null | undefined,\n): field is LinkField<TypeEnum, LangEnum, DataInterface, \"filled\"> => {\n\treturn isNonNullish(field) && (\"id\" in field || \"url\" in field);\n};\n\n/**\n * Determines if a Link to Media field is filled.\n *\n * @param field - Link to Media field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const linkToMedia = link as (\n\tfield: LinkToMediaField | null | undefined,\n) => field is LinkToMediaField<\"filled\">;\n\n/**\n * Determines if a Content Relationship field is filled.\n *\n * @param field - Content Relationship field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const contentRelationship = link as <\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n>(\n\tfield: RelationField<TypeEnum, LangEnum, DataInterface> | null | undefined,\n) => field is RelationField<TypeEnum, LangEnum, DataInterface, \"filled\">;\n\n/**\n * Determines if a Date field is filled.\n *\n * @param field - Date field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const date = isNonNullish as (\n\tfield: DateField | null | undefined,\n) => field is DateField<\"filled\">;\n\n/**\n * Determines if a Timestamp field is filled.\n *\n * @param field - Timestamp field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const timestamp = isNonNullish as (\n\tfield: TimestampField | null | undefined,\n) => field is TimestampField<\"filled\">;\n\n/**\n * Determines if a Color field is filled.\n *\n * @param field - Color field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const color = isNonNullish as (\n\tfield: ColorField | null | undefined,\n) => field is ColorField<\"filled\">;\n\n/**\n * Determines if a Number field is filled.\n *\n * @param field - Number field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const number = isNonNullish as (\n\tfield: NumberField | null | undefined,\n) => field is NumberField<\"filled\">;\n\n/**\n * Determines if a Key Text field is filled.\n *\n * @param field - Key Text field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const keyText = (\n\tfield: KeyTextField | null | undefined,\n): field is KeyTextField<\"filled\"> => {\n\treturn isNonNullish(keyText) && !!field;\n};\n\n/**\n * Determines if a Select field is filled.\n *\n * @param field - Select field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const select = isNonNullish as <Enum extends string>(\n\tfield: SelectField<Enum> | null | undefined,\n) => field is SelectField<Enum, \"filled\">;\n\n/**\n * Determines if an Embed field is filled.\n *\n * @param field - Embed field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const embed = <Field extends EmbedField<AnyOEmbed>>(\n\tfield: Field | null | undefined,\n): field is Extract<Field, EmbedField<AnyOEmbed, \"filled\">> => {\n\treturn isNonNullish(field) && !!field.embed_url;\n};\n\n/**\n * Determines if a GeoPoint field is filled.\n *\n * @param field - GeoPoint field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const geoPoint = (\n\tfield: GeoPointField | null | undefined,\n): field is GeoPointField<\"filled\"> => {\n\treturn isNonNullish(field) && \"longitude\" in field;\n};\n\n/**\n * Determines if an Integration Fields field is filled.\n *\n * @param field - Integration Fields field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const integrationFields = isNonNullish as <\n\tData extends Record<string, unknown>,\n>(\n\tfield: IntegrationFields<Data> | null | undefined,\n) => field is IntegrationFields<Data, \"filled\">;\n\n/**\n * Determines if a Group has at least one item.\n *\n * @param group - Group to check.\n *\n * @returns `true` if `group` contains at least one item, `false` otherwise.\n */\nexport const group = <Fields extends Record<string, AnyRegularField>>(\n\tgroup: GroupField<Fields> | null | undefined,\n): group is GroupField<Fields, \"filled\"> => {\n\treturn isNonNullish(group) && isNonEmptyArray(group);\n};\n\n/**\n * Determines if a Slice Zone has at least one Slice.\n *\n * @param slices - Slice Zone to check.\n *\n * @returns `true` if `slices` contains at least one Slice, `false` otherwise.\n */\nexport const sliceZone = <Slices extends Slice | SharedSlice>(\n\tslices: SliceZone<Slices> | null | undefined,\n): slices is SliceZone<Slices, \"filled\"> => {\n\treturn isNonNullish(slices) && isNonEmptyArray(slices);\n};\n"],"names":["group"],"mappings":";;AAiCA,MAAM,eAAe,CAAI,UAAqC;AAC7D,SAAO,SAAS;AACjB;AAUA,MAAM,kBAAkB,CAAI,UAAoC;AACxD,SAAA,CAAC,CAAC,MAAM;AAChB;AASa,MAAA,WAAW,CACvB,UACqC;AACjC,MAAA,CAAC,aAAa,KAAK,GAAG;AAClB,WAAA;AAAA,EAAA,WACG,MAAM,WAAW,KAAK,UAAU,MAAM,CAAC,GAAG;AACpD,WAAO,CAAC,CAAC,MAAM,CAAC,EAAE;AAAA,EAAA,OACZ;AACC,WAAA,CAAC,CAAC,MAAM;AAAA,EACf;AACF;AASO,MAAM,QAAQ;AAWR,MAAA,iBAAiB,CAC7B,cAC2C;AAC3C,SAAO,aAAa,SAAS,KAAK,CAAC,CAAC,UAAU;AAC/C;AASO,MAAM,QAAQ;AAaR,MAAA,OAAO,CAOnB,UACoE;AACpE,SAAO,aAAa,KAAK,MAAM,QAAQ,SAAS,SAAS;AAC1D;AASO,MAAM,cAAc;AAWpB,MAAM,sBAAsB;AAiB5B,MAAM,OAAO;AAWb,MAAM,YAAY;AAWlB,MAAM,QAAQ;AAWd,MAAM,SAAS;AAWT,MAAA,UAAU,CACtB,UACoC;AACpC,SAAO,aAAa,OAAO,KAAK,CAAC,CAAC;AACnC;AASO,MAAM,SAAS;AAWT,MAAA,QAAQ,CACpB,UAC6D;AAC7D,SAAO,aAAa,KAAK,KAAK,CAAC,CAAC,MAAM;AACvC;AASa,MAAA,WAAW,CACvB,UACqC;AAC9B,SAAA,aAAa,KAAK,KAAK,eAAe;AAC9C;AASO,MAAM,oBAAoB;AAapB,MAAA,QAAQ,CACpBA,WAC0C;AAC1C,SAAO,aAAaA,MAAK,KAAK,gBAAgBA,MAAK;AACpD;AASa,MAAA,YAAY,CACxB,WAC0C;AAC1C,SAAO,aAAa,MAAM,KAAK,gBAAgB,MAAM;AACtD;;;;;;;;;;;;;;;;;;;"}