Skip to content

Tool for exposing private variables and functions from within a commonJs module

Notifications You must be signed in to change notification settings

outofthisworld/cjs-expose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Tool for exposing private variables and functions from within a commonJs module

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published