1.1.0 • Published 3 years ago

hexnut-handle v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

hexnut-handle

hexnut-handle is a hexnut middleware for creating simple message and connection handlers. It can also be used with hexnut-client.

Installing

npm i hexnut-handle

Usage

Handling a connection

handle.connect(middlewareFunction)

const handle = require('hexnut-handle');

app.use(handle.connect(ctx => {
  ctx.send('Welcome!');
}));

Handling a message

handle.message(middlewareFunction)

const handle = require('hexnut-handle');

app.use(handle.message(ctx => {
  ctx.send(`You sent: ${ctx.message}`);
}));

Handling a message with a specific format

handle.matchMessage(messageRecogniserFunction, middlewareFunction)

const handle = require('hexnut-handle');

const messageRecogniser = msg => msg === 'Hello world';

app.use(handle.matchMessage(messageRecogniser, ctx => {
  ctx.send('Hello to you too!');
}));

Handling a connection closing

handle.closing(middlewareFunction)

const handle = require('hexnut-handle');

app.use(handle.closing(ctx => {
  // Do some cleanup here if necessary.
}));
1.1.0

3 years ago

1.0.0

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago