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

@zenozaga/local-modules

v1.0.9

Published

Register modules, functions, classes and objects locally and use them anywhere through aliases

Downloads

22

Readme

@zenozaga/local-modules

Build Status

Register modules, functions and objects locally for use anywhere via aliases

I'm new to this, so hello everyone. I have created this package for personal use. If this can help you in something, I will be happy if I did something wrong > I will be happy to help me solve it and learn. Thank you.

Usage Examples

Register a function without execute

const localModules = require("@zenozaga/local-modules");

//To register a function you need to add the name $Export
localModules.register('@randomNumber',function $Export( length ){

    if(!length) length = 10;

    var numbers = "0123456789";
    var array_numbers = numbers.split("");
    var returner = "";

    for( var t = length; t > 0; t--){

        var rand_index = Math.floor(Math.random() * array_numbers.length)
        returner += array_numbers[rand_index];

    }

    return returner;

});

// random numbers
console.log(localModules.require('@randomNumber')(15));
Register a class

const localModules = require("@zenozaga/local-modules");

localModules.register('@Person', class Person{

	talk(){
		console.log("Hello world!");
	}

});

var person = new (localModules.require('@Person')) ;
person.talk();

// Output
//Hello world!
Register an Object or Array

const localModules = require("@zenozaga/local-modules");

// register object
localModules.register('@configuration',{

    port: 8080,
    host: "example.com",
    getSize: function(size){

        return size * 24;
    }

});


// get object
var config = localModules.require('@configuration');


// use
console.log(`
  Host: ${config.host},
  Port: ${config.port},
`);

console.log("Size: ",config.getSize(10));


 // Output


/*

Host: example.com,
Port: 8080,

Size:  240

 */

Register a module function

const localModules = require("@zenozaga/local-modules");

// register a source module
localModules.register('@Helpers',function(){

    const fs = require('path');


    module.exports.isString = function (str){

        return ( str && str.constructor == String ) || false;

    };


    module.exports.isFunction = function(fn){

        return ( fn && fn.constructor == Function ) || false;

    };

    module.exports.path_join = function ( path1, path2){
        
        return path.join(path1,path2);

    };


    

});


// get module
var Helpers = localModules.require('@Helpers');

// string validation
console.log( "valdiate:string ", Helpers.isString("hello"));
console.log( "valdiate:string ", Helpers.isString(13434));

//function validation

function functionExample (){

};

console.log('\n')
console.log( "valdiate:function ",  Helpers.isFunction(13434) );
console.log( "valdiate:function ", Helpers.isFunction( functionExample ) );


//join path
console.log('\n')
console.log( Helpers.path_join(__dirname, "example.js") );


 // Output


/*

valdiate:string  true
valdiate:string  false


valdiate:function  false
valdiate:function  true

[path joined]

 */
Register a custom module file

moduleExample.js

const fs = require('fs');

function FileExist(path_file){

    return fs.existsSync(path_file);

};

module.exports = FileExist;

index.js


const localModules = require("@zenozaga/local-modules");
const path = require("path");

// register a custom module
localModules.register('@moduleExample',  path.join( __dirname, './moduleExample') );


// get module
var moduleExample = localModules.require('@moduleExample');

console.log( "File exist" , moduleExample(  path.join(__dirname, "file_is_no_exist.js")  ));
console.log( "File exist" , moduleExample( __filename ));

 // Output


/*

File exist false
File exist true

 */
Register a remote string source module using axios

remote file moduleExample.js

const fs = require('fs');

function FileExist(path_file){
    return fs.existsSync(path_file);
};

module.exports = FileExist;

index.js



const axios = require("axios");
const localModules = require("@zenozaga/local-modules");

(async function(){

	const  { data } = await axios.get("http://example.com/moduleExample.js");
	ocalModules.register( '@moduleExample' , data );

	const moduleExample = localModules.require("@moduleExample");

	console.log( "File exist" , moduleExample(  path.join(__dirname, "file_is_no_exist.js")  ));
	console.log( "File exist" , moduleExample( __filename ));


	// Output
	/*
		File exist false
		File exist true
	 */


})();