personal-website/lib/notion/utils/richTextToPlainText.ts
Filipe Medeiros 9a9638237f
feat: initial commit
Signed-off-by: Filipe Medeiros <hello@filipesm.eu>
2023-12-03 12:25:52 +01:00

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