npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@magneds/hapi-plugin

v1.0.4

Published

Hapi plugin wrapper

Downloads

5

Readme

HapiPlugin

A convenience layer to easily create plugins for the Hapi ecosystem

Installation

The HapiPlugin package is a scoped packages, which means you'll have to include the scope during installation.

$ npm install --save @magneds/hapi-plugin

Usage

As with the installation, the scope is required to use the package as well.

const HapiPlugin = require('@magneds/hapi-plugin');

const plugin = new HapiPlugin(require('./package.json'));

module.exports = plugin.export;

API

The HapiPlugin module consist of getter and setter functions, so the API is mostly configurable setting properties.

constructor([{object}])

A HapiPlugin instance can easily be bootstrapped using a predefined object, this will allow for quick creation aswel as provide consistency by allowing the use of your module package json for the name and/or version information.

Any value can still be overwritten.

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

module.exports = plugin.exports;

name

Set the name for the plugin. There are no enforced limitations, though it is probably wise to adhere to the Hapi implied standards of using names consisting of lowercase characters separated by a dash, as this helps configuring dependencies.

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

plugin.name = 'my-plugin';

module.exports = plugin.exports;

version

Set the version for the plugin.

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

plugin.version = 'my-plugin';

module.exports = plugin.exports;

register

Set the register method for the plugin. This method is what Hapi will invoke when registering your plugin. When this method is invoced, you can be certain all dependencies are already loaded and ready.

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

plugin.register = async(server, options) {
	await server.route({
		method: 'GET',
		path: '/my-plugin-route',
		handler(request, h) {
			return h.response('my-plugin response');
		},
	});
};

module.exports = plugin.exports;

dependencies

Declare plugin dependencies to other plugins.

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

plugin.dependencies.push('my-other-plugin');

// or overwrite the dependencies entirely

plugin.dependencies = ['my-other-plugin'];

module.exports = plugin.exports;

options

Configure (default) options to be provided to the plugin on registration by Hapi. Upon setting new options, the previous values are not removed but instead the new values are added to the existing ones.

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

plugin.options = { foo: 'bar' };
plugin.options = { baz: 'qux' };

console.log(plugin.options); //  { foo: 'bar', baz: 'qux' }

module.exports = plugin.exports;

routes

Hapi allows for specification of vhost and prefix in a routes settings. HapiPlugin lets you prepare either one using the routes property (or simply set the vhost and/or prefix property);

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

plugin.routes = { prefix: '/my-prefix' };

console.log(plugin.routes); //  { prefix: '/my-prefix' }

module.exports = plugin.exports;

prefix

Specify the prefix to use for all plugin registered routes. This is a very nice way to allow for modification to the routes registered by your plugin. HapiPlugin will take care of putting the prefix into the routes object.

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

plugin.prefix = '/my-prefix';

console.log(plugin.prefix); //  '/my-prefix'
console.log(plugin.routes); //  { prefix: '/my-prefix' }

module.exports = plugin.exports;

vhost

Specify the vhost to use for all plugin registered routes. This is a convenient way to ensure the plugin routes exist only for specific vhosts.

const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));

plugin.vhost = 'my-vhost.example.com';

console.log(plugin.vhost); //  'my-vhost.example.com'
console.log(plugin.routes); //  { vhost: 'my-vhost.example.com' }

module.exports = plugin.exports;

exports

Exporting the plugin is one of the most important steps to successfully register a plugin to Hapi. It may be cumbersome to get right, so HapiPlugin takes care of the differences in syntax you can have in case there are routes or options involved.

config

If there is a need/desire to modify the collected configuration, it is stored in the config (readonly) property. Read-only in this case prevent from overwriting the config property entirely, but as objects are by reference in javascript, it will allow for direct manipulation, even though we don't particularly encourage this approach.

Change log

Please see Changelog

Testing

$ npm test

Contributing

Please see Contributing

Credits

License

The MIT License (MIT). Please see License File for more information.