Skip to content

lostfictions/masto.js

 
 

Repository files navigation

Mastodon API client for JavaScript, TypeScript, Node.js, browsers

npm
Mastodon

Installation

npm i masto --save

Become a patron

Basic Usage

This is a simple example which creates a new status:

import Masto from 'masto';

(async () => {
  const masto = await Masto.login({
    uri: 'https://example.com', // URL of your instance
    accessToken: 'YOUR TOKEN',  // Your access token (optional)
  });

  const data = await masto.createStatus({
    status: 'Hello Mastodon!',
    visibility: 'direct',
  });

  console.log(data);
})()

All of available methods / interfaces are described in the documentation. You can also refer the examples on this repository.

FAQ

Q. What is the deference between Masto.js and the others?

  • Browsers and Node.js are both supported
  • TypeScript powers static typing.
  • You don't need to type API URLs because each endpoints have their own function
  • Detailed docs and rich hovering menu for IDE, provided by TSDoc
  • AsyncIterator makes timeline pagination easier.

Q. I got an error Symbol.asyncIterator is not defined

A. Masto.js using AsyncIterator which is very new JS feature and it may not be supported in particular environments. So in browsers, you need to use a polyfill like Babel's. In Node.js, it is supported on v10 so you can update and use it.

If you're using Masto.js with TypeScript, you need to add the following config to tsconfig.json for static typing.

{
  "compilerOptions": {
    "lib": [
+      "esnext.asynciterable"
      ...

License

License: AGPL v3

About

Mastodon API client for JavaScript, TypeScript, Node.js, browsers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.7%
  • JavaScript 1.3%