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

lmao

v2.3.0

Published

Load modules in an object

Downloads

38

Readme

lmao

lmao (load modules in an object) helps you load modules into an object with a specific structure.

Imagine you have a project with the following structure:

.__ client/
|  |__ netsuite/
|  |  |__ modules/
|  |  |   |__ stores.js
|  |  |__ index.js
|  |__ sap/
|  |  |__ modules/
|  |  |   |__ products.js
|  |  |   |__ recipes.js
|  |  |__ index.js
|  |__ rest.js
|  |__ soap.js
|__ public/
|  |__ json
|     |__ disclaimer.json
|     |__ privacy.json
|__ service/
|  |__ product.js
|  |__ recipe.js
|  |__ store.js
|__ transformation/
|  |__ product.js
|  |__ recipe.js
|  |__ store.js
|__util.js

And now you want to:

  • Import all these modules into a single object -we will call it "API" from now on-
  • Have total control over the structure of the resulting API object
  • Not worry to manually add, for instance, a new file you created inside service/
  • Not worry about circular dependencies while loading all these modules

With lmao you can load all those modules directly into an object with a specific structure. lmao only needs what we call a descriptor, which defines:

  • The structure of the API object (using dot notation à la keypather)
  • What files will be loaded (using glob path notation)

Example:

var lmao = require('lmao');

var api = module.exports = {
    version: '0.1.0'
};

lmao(api, {
    _root: ['example/util.js', 'example/metrics.js' ], // Root level, multiple paths
    client: 'example/client/*.js',
    'client.sap': {
        _root: 'example/client/sap/index.js',
        _children: 'example/client/sap/modules/*.js'
    },
    'client.netsuite': {
        _root: 'example/client/netsuite/index.js',
        _children: 'example/client/netsuite/modules/*.js'
    },
    static: 'example/public/**/*.json',
    transformation: 'example/transformation/*.js',
    service: 'example/service/*.js'
});

//
// console.log output
//
 version: '0.1.0',
  util: { log: [Function: bound ] },
  client:
   { rest: [Function: rest],
     soap: [Function: soap],
     sap:
      { request: [Function],
        options: { remoteUri: 'http://my-sap.com/my-api' },
        products: { search: [Function], details: [Function] },
        recipes: { search: [Function], details: [Function] } },
     netsuite:
      { request: [Function],
        options: { remoteUri: 'http://my-netsuite.com/my-api' },
        stores: { search: [Function], details: [Function] } } },
  static:
   { disclaimer:
      { title: 'Disclaimer',
        description: 'Lorem ipsum dolor sit amet' },
     privacy: { title: 'Privacy', description: 'Lorem ipsum dolor sit amet' } },
  transformation:
   { product:
      { transformProductList: [Function],
        transformProductDetails: [Function] },
     recipe:
      { transformRecipeList: [Function],
        transformRecipeDetails: [Function] },
     store:
      { transformStoreList: [Function],
        transformStoreDetails: [Function] } },
  service:
   { product: { search: [Function], details: [Function] },
     recipe: { search: [Function], details: [Function] },
     store: { search: [Function], details: [Function] } } }

Now you can start using your API!

api.service.product.search(...);
api.service.recipe.transformRecipList(...);
api.client.rest(...);

Installation

You can install lmao with npm:

npm install lmao

Usage

You can see a full-fledged example, which includes circular dependencies, in the example folder.

lmao([target,] descriptor)

Loads modules into an object as defined by descriptor, optionally merging them into the existing target object.

Arguments

  • target - Optional object where the modules will be loaded into. Existing properties will be overwritten.
  • descriptor - An object that describes what modules will be loaded, and in what path they'll be placed.
    • The keys of the descriptor are object paths in dot notation, like those of keypather.
    • The values of the descriptor are glob paths
      • You can provide multiple paths with an array of strings
      • If you want to have more control over the destination, you can wrap the values in an object with properties _root and _children. Root modules will not use the file name as property name; children will.

Example

Builds an object loaded with modules in a specific structure.

lmao(api, {
    _root: ['example/util.js', 'example/metrics.js' ], // Root level, multiple paths
    client: 'example/client/*.js',
    'client.sap': {
        _root: 'example/client/sap/index.js', // Root level modules (client.sap.*)
        _children: 'example/client/sap/modules/*.js' // Children modules (client.sap.<filename>.*)
    },
    'client.netsuite': {
        _root: 'example/client/netsuite/index.js',
        _children: 'example/client/netsuite/modules/*.js'
    },
    static: 'example/public/**/*.json',
    transformation: 'example/transformation/*.js',
    service: 'example/service/*.js'
});

Development

  • Linting: gulp lint
  • Testing and coverage: gulp test
  • Generate JSDoc files: gulp jsdoc

License

MIT

Ayy?

Lmao