Use the generator and detector functions to handle multiple SNS
masterMegalodon v3.0.0 uses a generator function as the default export to create Client API instances for specific SNS platforms (mastodon, pleroma, or misskey). To handle multiple SNS types dynamically, use the detector function to identify the SNS type from a URL, then pass that type to the generator.
detector(url): Returns the SNS name ('mastodon','pleroma', or'misskey') based on the provided URL.generator(sns_name, url, access_token): Generates a Client API instance for the specified SNS.
import generator, { detector } from 'megalodon'
// 1. Detect the SNS type from the URL
const sns = await detector(url)
// 2. Generate the client using the detected SNS type
const client = generator(sns, url, access_token)
// 3. Use the client
client.getHomeTimeline()