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

hapi-plugins-dir

v1.0.2

Published

Traverse directory recursively and get array of Hapi plugins ready to feed Hapi's server.register(plugins, [options]) function.

Downloads

9

Readme

hapi-plugins-dir

Description

Traverse directory recursively and get array of Hapi plugins ready to feed Hapi's server.register(plugins, [options]) function.

Synopsis

Plugins in same directory with file

const getHapiPlugins = require("hapi-plugins-dir");
const plugins = getHapiPlugins();
await server.register(plugins); // Hapi server object...

Custom directory

const getHapiPlugins = require("hapi-plugins-dir");
const plugins = getHapiPlugins({ dir: "plugins" }); // Dir may be relative or absolute
await server.register(plugins); // Hapi server object...

With haute-couture: plugins/index.js

module.exports = require("hapi-plugins-dir")();

Details

  • Traverses recursively given directory. (Defaults to caller file's directory)
  • If a plugin isn't specified in plugins key, it will be required using filename.
  • If a directory name starts with @, it is treated as package scope. (i.e. plugins/@name/some-plugin.js -> @name/some-plugin)
  • Files can be ordered using number prefixes appended dot or dash (. or -). Numbers are stripped when requesting plugin. (i.e. plugins/001-hapi-auth-basic requires hapi-auth-basic).
  • Scope directory names can be prefixed with numbers too. (i.e. plugins/001-@scope/001-module.js requires @scope/module).
  • Result array must be registered using server.register(plugins, [options]). It is not automatically registered.

API

Functions

Typedefs

getHapiPlugins([options]) ⇒ Array.<Object>

Traverses given direcotry (absolute or relative to caller file) for hapi plugins options file and returns them ready to feed Hapi's server.register(plugins, [options]) function.

Kind: global function
Returns: Array.<Object> - - Array of objects to feed Hapi's server.register(plugins, [options]) function.

| Param | Type | Default | Description | | --- | --- | --- | --- | | [options] | Object | | Options | | [options.dir] | dir | __dirname | Directory to look plugins. Can be relative or absolute. Default is current file's directory. | | [options.recursive] | boolean | true | Traverse directory recursively. | | [options.stripNumberPrefix] | boolean | true | Strip number prefixes from beginnings. (Numbers appended by dash or dot (. or -)) | | [options.filter] | FilterFunction | Array.<FilterFunction> | | Optional extra filter funtion or functions to exclude some files. (They are applied before builtin number filter) |

Example

const plugins = getHapiPluginsFromDir();
// ./001-a.js        -> a
// ./002-@scope/b.js -> scope/b
// ./@other/c.js     -> other/c
await server.register(plugins)

File : Object

File object.

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | path | string | Absolute path of the file. | | stats | fs.stats | fs.stats object of the file. |

FilterFunction : function

Filter function to exclude files.

Kind: global typedef

| Type | Description | | --- | --- | | Array.<File> | Array of klaw result items. Path of file and fs.stats object. |