Files
supabase/apps/temp-docs/components/CustomMDX/CustomMDX.utils.ts
2022-10-26 17:35:53 +07:00

18 lines
475 B
TypeScript

export const getAnchor = (text: any): string | undefined => {
if (typeof text !== 'string') {
return undefined
} else {
const [anchor] = text.match(/{#[a-z-]*}/g) || []
return anchor !== undefined ? anchor.slice(2, anchor.length - 1) : undefined
}
}
export const removeAnchor = (text: any) => {
if (typeof text !== 'string') {
return text
} else {
if (text.indexOf('{#') > 0) return text.slice(0, text.indexOf('{#'))
else return text
}
}