22 lines
541 B
TypeScript
22 lines
541 B
TypeScript
// This version was taken from https://github.com/justjake/monorepo/blob/d1e87174827005fa7fd6d158a0a1d7e86dd2a396/packages/notion-api/src/lib/notion-api.ts#L455
|
|
import { type RichText } from '../types'
|
|
|
|
/**
|
|
* @returns Plaintext string of rich text.
|
|
*/
|
|
const richTextAsPlainText = (
|
|
richText: string | RichText | undefined,
|
|
): string => {
|
|
if (!richText) {
|
|
return ''
|
|
}
|
|
|
|
if (typeof richText === 'string') {
|
|
return richText
|
|
}
|
|
|
|
return richText.map((token) => token.plain_text).join('')
|
|
}
|
|
|
|
export default richTextAsPlainText
|