JSPM

telegraph-wrapper

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q32086F
  • License MIT

Telegra.ph API wrapper with docs and files upload

Package Exports

  • telegraph-wrapper
  • telegraph-wrapper/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (telegraph-wrapper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Help

Rate me

telegraph-wrapper

Telegra.ph API wrapper

Official docs - https://telegra.ph/api

Features

  • files upload (local and remote by url)
  • all types included
  • full docs included
  • proxy for upload (TODO)

Install

npm i telegraph-wrapper

or

yarn add telegraph-wrapper

Usage

Import

CommonJS

const Telegraph from 'telegraph-wrapper'

or

const { createAccount, upload } from 'telegraph-wrapper'

Modules

import * as Telegraph from 'telegraph-wrapper'

or

import { createAccount, upload } from 'telegraph-wrapper'

Methods

All methods presented in official docs:

https://telegra.ph/api#Available-methods

Methods returns Promise with api response.

Hover any method and property to preview JSDocs.

Examples:

import * as Telegraph from 'telegraph-wrapper';

Telegraph.createAccount({
  short_name: 'acc',
})
  .then(console.log)
  .catch(err => { /* ... */ });
import { getAccountInfo } from 'telegraph-wrapper';

getAccountInfo({
  access_token: '...',
})
  .then(console.log)
  .catch(err => { /* ... */ });
import { createAccount } from 'telegraph-wrapper';

try {
  const acc = await createAccount({
    short_name: 'acc',
  });
} catch (err) {
  /* ... */
}

Upload

Allows upload local files and remote (by url) to telegra.ph servers. Returns Promise<TelegraphOK | TelegraphError> (see #Types).

⚠️ Do not mix local and remote URLs! ⚠️

upload([
  './meme.png',
  './meme2.png',
])

or 

upload('./meme.png')

Types

All types also included + upload responses.

Names are the same with official docs.

JSDocs included. You can import any type and see docs by hovering it.

Upload types

TelegraphOK - Telegra.ph success response

TelegraphOK[].src - Telegra.ph file link. Example: /file/123abc123abc123abc123.ext

type TelegraphOK = Array<{
  src: string,
}>;

TelegraphError - Telegra.ph error response

TelegraphOK.error - Error body

type TelegraphError = {
  error: string,
};