0.0.6 • Published 4 years ago

tinyfakenode v0.0.6

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
4 years ago

tinyfakenode

Minimalistic Node.js API for the browser (currently less than 4 kiB).

Implemented Functions of the Node.js API

  • assert.ok(value [, message])
  • assert.deepStrictEqual(actual, expected [, message])
  • fs.readFileSync(path [, options])
  • fs.writeFileSync(file, data [, options])
  • fs.existsSync(path)
  • os.endianess()
  • os.platform()
  • os.EOL
  • path.basename(path [, exp])
  • path.dirname(path)
  • process.exitCode
  • process.exit()

Installation

$npm install tinyfakenode

Usage

  • File: index.html:
<html>
    <head>
        <!-- include tinyfakenode library -->
        <script src="node_modules/tinyfakenode/tinyfakenode.min.js"></script>
        <script>
            // set used Node.js API modules to global scope
            var os = tinyfakenode.os;
            var assert = tinyfakenode.assert;
            var process = tinyfakenode.process;
        </script>
        <!-- include custom code that makes use of the Node.API -->
        <script src="example.js"></script>
    </head>
    <body>
    </body>
    <script>
        // run function main of custom code. Put arguments in array.
        let exitCode = tinyfakenode.run(example_node_lib.main, [3.14]);
        console.log("exit code is " + exitCode);
        // get output (console.log in custom code is redirected)
        console.log("log: " + tinyfakenode.getLog());
    </script>
</html>
  • Example code example.js that normally runs via Node.js. Note that is must have IIFE (Immediately Invoked Function Expression) style:

// export all Node.js API modules (here: os, assert, process)
var example_node_lib = (function (exports, os, assert, process) {
    function main(x) {
        console.log(x);
        console.log(os.platform());
        assert.ok(3 == 4, "assertion failed");
    }
    exports.main = main;
    return exports;
})({}, os, assert, process);

The example can be found in directory example/ of the repository.

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago