1.2.1 • Published 7 years ago

cjs-expose v1.2.1

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

cjs-expose Build Status

cjs-expose is a simple utility tool for exposing private variables and functions from within a commonJS module.

installation

npm install --save cjs-expose

or

npm install --save-dev cjs-expose

depending on use case.

usage

    //====== MODULE mymodule.js ======

    const myPrivateVar = 1;


    function myPrivateFunction() {

    }

    let myOtherPrivateFunction = function() {

    }
    
    //==========END MODULE================

    //====== MODULE myothermodule.js ======

    const expose = require('cjs-expose');
    const myAccessor = expose('./mymodule.js');

    console.log(myAccessor('myPrivateFunction'));
    //output: [function myPrivateFunction]

    console.log(myAccessor('myOtherPrivateFunction'));
    //output: [function myOtherPrivateFunction]

    console.log(myAccessor('myPrivateVar'));
    //output: 1

    console.log(myAccessor(['myOtherPrivateFunction']));
    //output: [function myOtherPrivateFunction]

    console.log(['myPrivateFunction','myOtherPrivateFunction'])
    /*
        output: {
            myPrivateFunction:[function myPrivateFunction],
            myOtherPrivateFunction:[function myOtherPrivateFunction]
        }
    */

   //==========END MODULE================