Code Monkey home page Code Monkey logo

masto.js's Introduction

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

npm

Examples | Read the Docs | Releases | Issues

Installation

npm i masto

Requirements

  • Node.js: >= 10.x
  • TypeScript (optional peer dependency): >= 3.6.0

Features

  • ๐ŸŒŽ Isomorphic which means browsers and Node.js are both supported
  • โŒจ๏ธ TypeScript powers static typing. And of course there's no any!
  • ๐Ÿ’ช You don't need to type URLs because each endpoints have their own function
  • ๐Ÿ“„ Detailed docs and rich hovering menu for IDE, provided by TSDoc

Basic Usage

First, open /settings/applications/new of your instance on your browser and create new application.

Create New App

Then, here's a simple example that creates a toot. Replace TOKEN to your own access token.

import { login } from 'masto';

async function main() {
  const masto = await login({
    url: 'https://example.com',
    accessToken: 'TOKEN',
  });

  await masto.statuses.create({
    status: 'Hello Mastodon!',
    visibility: 'direct',
  });
}

main().catch((error) => {
  console.error(error);
});

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

FAQ

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

A. Masto.js is 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"
      ...

Contribution

See CONTRIBUTING.md

License

GNU Affero General Public License v3

masto.js's People

Contributors

neet avatar dependabot-preview[bot] avatar dependabot[bot] avatar semantic-release-bot avatar lostfictions avatar josephkreydt avatar darnfish avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.