mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
15 lines
365 B
TypeScript
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
|
|
}
|
|
|
|
|