cjs-expose

1.2.1 • Public • Published

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================

Package Sidebar

Install

npm i cjs-expose

Weekly Downloads

1

Version

1.2.1

License

ISC

Last publish

Collaborators

  • blackjem