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 🙏

© 2026 – Pkg Stats / Ryan Hefner

packagefy

v0.1.0

Published

A NodeJS library for grouping modules from a given directory into package objects

Downloads

5

Readme

packagefy

A NodeJS library for grouping modules from a given directory into a package object.

Overview

Packagefy makes easier the process of grouping related modules from a given directory into package objects that can be exported from a index.js file. For example, supose the following directory structure within a my-package folder:

  • |- my-package
  • | |- helpers.js
  • | |- index.js
  • | |- module-a.js
  • | |- module-b.js
  • | |- private-module.js

After requiring the packagefy module within index.js and calling the packagefy exposed function, the library will scan the folder, load all modules (except the index itself) and expose them as properties of an immutable plain JavaScript object. Additionally, you may exclude "private" modules from the created package. For example:

// index.js
const packagefy = require('packagefy');

module.exports = packagefy(__dirname, {
  exclude: /private/
});

The code above will export the following object:

{
  helpers: [Object],
  moduleA: [Object],
  moduleB: [Object]
  }

Documentation

Installation

npm install packagefy

packagefy(baseDir, [options]) -> Object

Scan the directory, load modules and expose them into an immutable (frozen) object.

  • baseDir (String) directory where the modules should be loaded from (required). Generally __dirname.
  • options (Object) non-mandatory set of options accepted by packagefy (see bellow).
  • return value (Object) an immutable (frozen) hash containing the modules to be exposed.

options

exclude (RegExp|String|Function|Array)

A RegExp, String or Function used for determining which files should be excluded from the "package". Alternatively, can receive an array of these types (RegExp, String or Function). In that case, a logical disjunction between its values will be applied. If defined as a String, perform an equality comparison between the value and the names of the files present at the directory. If defined as a Function, receive the file name (without the extension) as its first parameter. In that case, this function should acts as a predicate returning a Boolean equivalent value indicating whether the file should be excluded.

// Defining a RegExp

module.exports = packagefy(__dirname, {
  exclude: /private/
});
// Defining a simple String

module.exports = packagefy(__dirname, {
  exclude: 'private-module'
});
// Using a predicate Function

module.exports = packagefy(__dirname, {
  exclude: (fileName) -> fileName.indexOf('private') >= 0
});
// Finally, defining an array

module.exports = packagefy(__dirname, {
  exclude: [/private/, 'foo']
});

Note: the index.js and non-JavaScript files (obviously) are always excluded from the package object.

onLoad (Function)

A Function invoked after each module being loaded. Receive the module name (the original file name without its extension) as the first parameter and the own module as the second one. It can be seen as a hook for executing some logic when the module is ready.

module.exports = packagefy(__dirname, {
  onLoad(moduleName, module) {
    console.log('Loading %s', moduleName);
    doSomethingWith(module);
  }
});
transform (Function)

A function invoked for transforming the module name into a key of the package object. By default, the module name is converted to a camel case representation. Receive the module name and return the key as a string.

module.exports = packagefy(__dirname, {
  transform(moduleName) {
    if(moduleName === 'some-class') {
      return 'SomeClass';
    }
    return _.camelCase(moduleName);
  }
});

License

Copyright (c) 2016 Alan Ghelardi.

Licensed under the MIT license.