1.0.1-1-autogenerate-documentation-252961413-5ff8b2b44227d8ed10a8911777f81683f7d90f29 • Published 7 years ago

webmen v1.0.1-1-autogenerate-documentation-252961413-5ff8b2b44227d8ed10a8911777f81683f7d90f29

Weekly downloads
4
License
MIT
Repository
gitlab
Last release
7 years ago

webmen

A small module to send WebMentions. Should work in both Node and the browser, although you might want to include polyfills for Array.from, Promise and fetch for the latter.

This project also includes TypeScript type definitions.

Installation

npm install webmen --save

Usage

import { webmention } from 'webmen';

webmention('https://webmention.rocks/test/1', 'http://poop.bike')
.then((success) => console.log('Did the target accept the WebMention?', success))
.catch((error) => console.error('Something went wrong sending a WebMention:', error));

Changelog

See CHANGELOG.md.

License

MIT © Vincent Tunru

API

Index

Functions

Functions

discover

discover(target: string): Promise<string | null>

Defined in src/discover.ts:13

Given a target that is linked to, finds that page's associated WebMention endpoint, if any.

Parameters:

NameTypeDescription
targetstringThe web page that is mentioned. If the page supports WebMentions, it will include a reference to an endpoint (e.g. <link rel="webmention" href="https://endpoint.example">) that a WebMention should be sent to.

Returns: Promise<string | null>

A Promise that is either rejected, e.g. when the network is down, or resolved. If it is resolved, it will either return the endpoint referred to in the target page, or null if it did not refer to an endpoint.


send

send(endpoint: string, source: string, target: string): Promise<Response>

Defined in src/send.ts:12

Given an endpoint (see discover), send it a WebMention.

Parameters:

NameTypeDescription
endpointstringAn endpoint that is set up to receive WebMentions for a given target.
sourcestringThe page that links to target.
targetstringA page whose WebMention endpoint is endpoint, and which is linked to from source.

Returns: Promise<Response>


webmention

webmention(source: string, target: string): Promise<boolean>

Defined in index.ts:15

Notify target that source links to it. You will usually use this method.

This should be called when the link to target is added, and again every time source is updated, or if/when it eventually is deleted.

Parameters:

NameTypeDescription
sourcestringThe web page that mentions target; it should actually include a link to target to be a valid WebMention, or have included one at some point of time in the past.
targetstringThe web page that is mentioned by source. webmen will attempt to find a reference to the WebMention endpoint there, to which the actual WebMention will be sent.

Returns: Promise<boolean>

A Promise that is either rejected, e.g. when the network is down, or resolved with either true (target accepted the WebMention) or false (e.g. target does not support WebMentions).