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

modulizer

v2.0.9

Published

A Node.js package used to bundle a group of files into a module object.

Downloads

11

Readme

#Modulizer

npm Build Status Coverage Status npm npm

A Node.js package used to bundle a group of files into a module object.

Modulizer is used to specify a directory of files to be executed (iteratively) in one batch via Modulizer.executeAll(), or to be used individually via Modulizer.execute('myFileName'). Each file represents a module or group of modules. Originally this was created for a routing architecture under frameworks like Express, so that each route or set of routes would have their own file. Data can be passed into a wrapping function within each file via an options object.

Modulizer accepts two arguments - the directory path, and an options object. Calling Modulizer.executeAll() will loop through code from all files, passing in the options object. This is best for modules that execute code without returning values. Modulizer.execute('myFileName') will execute code from only myFileName.js, and Modulizer.execute('myFileName', moreOptions) will extend the options Modulizer was instantiated with uniquely. See below for a more elaborate example.

Installation

$ npm install modulizer --save

Example Usage

In this case, our modules are routes. For each file in our routes directory we have routing logic.

######/server.js

const express = require('express');
const app = express();
const Modulizer = require('modulizer');
const CONFIG = require('./config/main');

let routes = new Modulizer(__dirname + '/routes', {
  'app' : app,
  'CONFIG' : CONFIG
});

routes.executeAll();

Otherwise, if we only wanted to execute the code within index.js, we could do this:

routes.execute('index');

To take that even further, we could extend the options object uniquely for this module like so:

let moreOptions = {
  'foo' : 'bar',
  'hello' : 'world'
}
routes.execute('index', moreOptions);

######/routes/index.js

module.exports = function(options){
  const app = options.app;
  const CONFIG = options.CONFIG;

  app.get('/', function(req, res) {
    res.send('Hello, ' + CONFIG.name);
  });
}

Important Usage Notes

  • This package uses ES2015, so Node.js v4.4.1+ is required.
  • Files within the specified directory need to have '.js' extensions. Other file types will be ignored.
  • Files within the specified directory need to export a function, otherwise they will be ignored.

Methods

constructor(directory [,options])

Called upon instantiation. This represents the class constructor method.

  • @param {string} directory - String path to module directory. Required.
  • @param {object} options - Object for options to be used for all modules. Optional.

execute(moduleName [,options])

Execute a specific module identified by the file name (without ".js")... the moduleName argument.

  • @param {string} moduleName - Name of module to be executed. The file name from where the code originated. Optional.
  • @param {object} options - Object to extend object for all modules uniquely. Optional.

executeAll()

Execute all modules.

Properties

methodObject

An object containing all module functions with keys of the pertaining file name (without ".js").

methodArray

An array containing all module functions.