{"version":3,"file":"asText.cjs","names":["baseAsText"],"sources":["../../src/helpers/asText.ts"],"sourcesContent":["import { asText as baseAsText } from \"../richtext/asText\"\nimport type { RichTextField } from \"../types/value/richText\"\n\n/** Configuration that determines the output of `asText()`. */\ntype AsTextConfig = {\n\t/**\n\t * Separator used to join each element.\n\t *\n\t * @defaultValue ` ` (a space)\n\t */\n\tseparator?: string\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/** @deprecated Use object-style configuration instead. */\ntype AsTextDeprecatedTupleConfig = [separator?: string]\n\n/** The return type of `asText()`. */\ntype AsTextReturnType<Field extends RichTextField | null | undefined> = Field extends RichTextField\n\t? string\n\t: null\n\nexport const asText: {\n\t/**\n\t * Converts a rich text field to a plain text string.\n\t *\n\t * @example\n\t * \t;```ts\n\t * \tconst text = asText(document.data.content)\n\t * \t// => \"Hello world\"\n\t * \t```\n\t *\n\t * @param richTextField - A rich text field from Prismic.\n\t * @param config - Configuration that determines the output of `asText()`.\n\t * @returns Plain text equivalent of the rich text field, or `null` if the\n\t * field is empty.\n\t * @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsTextConfig,\n\t): AsTextReturnType<Field>\n\n\t/**\n\t * Converts a rich text field to a plain text string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t * @param richTextField - A rich text field from Prismic.\n\t * @param separator - Separator used to join each element. Defaults to a space.\n\t * @returns Plain text equivalent of the rich text field, or `null` if the\n\t * field is empty.\n\t * @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsTextDeprecatedTupleConfig\n\t): AsTextReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsTextConfig] | AsTextDeprecatedTupleConfig\n): AsTextReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrSeparator] = configObjectOrTuple\n\t\tlet config: AsTextConfig\n\t\tif (typeof configObjectOrSeparator === \"string\") {\n\t\t\tconfig = {\n\t\t\t\tseparator: configObjectOrSeparator,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrSeparator }\n\t\t}\n\n\t\treturn baseAsText(richTextField, config.separator) as AsTextReturnType<Field>\n\t} else {\n\t\treturn null as AsTextReturnType<Field>\n\t}\n}\n"],"mappings":";;AAsBA,MAAa,UAoCZ,eAEA,GAAG,wBAC0B;AAC7B,KAAI,eAAe;EAElB,MAAM,CAAC,2BAA2B;EAClC,IAAI;AACJ,MAAI,OAAO,4BAA4B,SACtC,UAAS,EACR,WAAW,yBACX;MAED,UAAS,EAAE,GAAG,yBAAyB;AAGxC,SAAOA,eAAAA,OAAW,eAAe,OAAO,UAAU;OAElD,QAAO"}