UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

18 lines (14 loc) 605 B
import {isPortableTextSpan, isPortableTextTextBlock, type PortableTextBlock} from '@sanity/types' export function isPortableTextPreviewValue(value: unknown): value is PortableTextBlock[] { return Array.isArray(value) && (value.length === 0 || value.some(isPortableTextTextBlock)) } export function extractTextFromBlocks(blocks: unknown): string { const firstBlock = Array.isArray(blocks) && blocks.find(isPortableTextTextBlock) if (!firstBlock || !firstBlock.children) { return '' } return firstBlock.children .filter(isPortableTextSpan) .map((span) => span.text) .join('') }