Ninja Programmers Mindmeld

    vanilla-require

    1.0.2 • Public • Published

    vanilla-require

    GPLv3 license Codacy Badge

    Links: npm and Github.


    The Node and npm have an incredible system for the inclusion of packages, made by require. However, to use packages one must export their modules, through module.exports. Yet, it is not possible to use these packages on simple web pages because the web browser does not recognize the module.exports.

    This package allows you to develop simple classes to the web and export them to Node script as a module. In this sense, you can use your classes in the web browser and in the Node script, using the vanilla-require package.

    Vanilla JS: pure Javascript.


    Installation

    npm install --save vanilla-require

    Example

    See test/test.js for another example.

    A Vanilla class (Calculator.js):

    class Calculator {
     
        sum(num1, num2){
            return num1+num2;
        }
    }

    Your Node code:

    /* Include */
    const vr = require('vanilla-require')(__dirname);
    // Instance a Vanilla Class
    const Calculator = vr.require('Calculator.js');
     
    // Enjoy the Class!
    let myCalc = new Calculator(),
        a = 2, b = 3;
     
    console.log('a:'+a+' b:'+b)
    console.log('sum:'+myCalc.sum(a, b));

    Also look ~

    Install

    npm i vanilla-require

    DownloadsWeekly Downloads

    13

    Version

    1.0.2

    License

    GPL-3.0-only

    Unpacked Size

    40.6 kB

    Total Files

    6

    Last publish

    Collaborators

    • leomaurodesenv