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

easy-dependency-loader

v1.1.1

Published

A simple way to manage your dependencies and use "require" with no problems with relative paths. It is very useful to complex project structures and when it is needed to change some file from it's place.

Downloads

3

Readme

Easy Dependency Loader 1.1.0

A simple way to manage your dependencies and use "require" with no problems with relative paths. It is very useful to complex project structures and when it is needed to change some file from it's place.

Change Log

[FEATURE] Migration to ES6 sintax!
[FEATURE] Refactoring (finally I had time to)!
[FEATURE] Unit tests!
[FEATURE] Add example folder
[FIX] Some fixes in Readme

Installation

EDL requires Node.js v6+ to run.

$ npm install --save easy-dependency-loader

Usage

Make sure you have a dependencies list in the following format:

{
...
    "dependency1": "path/to/dependency1",
    "dependency2": "path/to/dependency2",
    "dependency3": "path/to/dependency3",
...
}

It can be described in a JSON file or in a object. The EDL works exactly in the same way of require, so, every load that works with require also works with EDL.

EDL.setDependencies(dependencies) //As an object descriptor
EDL.setDependencies('./path/from/project/root/to/dependencies.json') //Path to dependencies file

const myDependencies = require('./path/to/dependencies.json')
EDL.setDependencies(myDependencies) //Using an JSON module with require

//Then, you just need to call the name of module using the load() method. Is no necessary to use the relative path.
const Module = EDL.load('moduleName')
Module.doSomething()

Example

const EDL = require('easy-dependency-loader')

//Passing a JSON path
EDL.setDependencies('./path/to/jsonfile/dependencies.json')

//Or passing a JSON module with require
const myDependencies = require('./configs/confgis.json')
EDL.setDependencies(myDependencies)

//Or passing an object
EDL.setDependencies({
  "Dog": "./models/Dog.js",
  "Falcon": "./models/birds/Falcon.js",
  "Chicken": "./models/birds/Chicken.js",
  "Worm": "./models/birds/insects/Worm.js"
})

//Finally, you can call the module in other place of project
const EDL = require('easy-dependency-loader')
const Dog = EDL.load('Dog')
Dog.bark()

Note: You also can use EDL to load native modules and modules in package.json if you want. Example:

//Lets suppose that async module is already installed
const EDL = require('easy-depenency-loader')
const async = EDL.load('async') // the same of const async = require('async');
const os = EDL.load('os') // the same of const os = require('os');

async.eachOf(os.cpus(), (cpu, key, next) => {
    console.log('CPU [%s] PROPS: %j', key, cpu)
    return next()
})

/*
Logs something like
CPU [0] PROPS: {"model":"Intel(R) Core(TM) ... }}
CPU [1] PROPS: {"model":"Intel(R) Core(TM) ... }}
...
*/

Contributions

Pull requests are welcome!

Errors

In general, problems with using this module maybe are problems with require, such:

  • Wrong relative path
  • Non-requireble file (empty, not exported, not supported extension, wrong path, wrong file name...);
  • "Cyclic" requires (module1 requires module2, that requires module1).

Todos

  • Using other types of config files, such xml (does make sense?)
  • Feature sugestions also are welcome

License

MIT