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

@beyonk/load-all

v0.3.0

Published

Loads all files from within a directory

Downloads

71

Readme

Load All

js-standard-style CircleCI

Loads the contents of sub-directories of a specified directory into an object or an array, suitable for mass loading of small modules from a filesystem.

This library is used extensively at Beyonk for loading route mappings, validations, error objects, and anywhere where a large number of small modules needs to be loaded.

Installation

npm i -D @beyonk/load-all

Usage

The library only has two methods, both of which amalgamate all exported items from a list of files.

exportDir

exportDir which results in a hash of export name -> function (), so that a directory structured thusly:

/my-dir
|-- library1
|   `-- index.js
|-- library2and3
|   `-- index.js
| ...

can be imported with:

const exported = exportDir('/my-dir')

// {
// library1: (exported as `library` from library1.js),
// library2: (exported as `library2` from library2and3.js),
// library3: (exported as `library3` from library2and3.js)
// }

includeDir

includeDir results in a concatenated array of the contents of files (which should export an array themselves), so that a directory structured thusly:

/routes
|-- routes1
|   `-- index.js
|-- routes2and3
|   `-- index.js
| ...

can be imported with:

const routes = includeDir('/my-dir')

// [ route1, route2, route3 ]

Advanced usage

Logging

The library will let you know every file it is loading, if you specify the second parameter to any method:

includeDir('/some-dir', 'route')

will result in log messages similar to the following:

// Adding route from ./some-dir/my-route

Modifying file content

You can modify the content of the files you load before it is put into the final hash or array, if you, for instance, would like to capitalise the key names, or add metadata or similar.

const { capitalize } = require('lodash')

includeDir('/some-dir', 'some-label', exported => {
  return Object.keys(exported).reduce((acc, exportName) {
    acc[capitalize(exportName)] = exported[exportName]
    return acc
  }, {})
})

Developing

You can run the suite of unit tests with

npm run test

code is linted according to @beyonk/eslint-config