Files
obsidian-to-NotionNext/upload.ts
2022-05-23 17:52:33 +08:00

15 lines
365 B
TypeScript

export const getTweetID = (src: string): string => {
// Create a URL object with the source. If it fails, it's not a URL.
const url = new URL(src)
const id = url.pathname
.split('/')
.filter(piece => !!piece) // remove empty strings from array
.slice(-1)[0]
if (!id) {
throw new Error('URL does not seem to be a tweet.')
}
return id
}