-
-
Save bclinkinbeard/6445373 to your computer and use it in GitHub Desktop.
CommonJS format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var supplant = require('utils/supplant'); | |
| function rhex(n) { | |
| var s = '', j = 0; | |
| for (; j < 4; j++) { | |
| s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F]; | |
| } | |
| return s; | |
| } | |
| function hex(x) { | |
| for (var i = 0; i < x.length; i++) { | |
| x[i] = rhex(x[i]); | |
| } | |
| return x.join(''); | |
| } | |
| module.exports = function () { | |
| // Build an instance of the md5 object with encrypt() features only... | |
| return { | |
| encrypt: function (s) { | |
| var results = hex(s); | |
| console.log(supplant('md5::encrypt({0}) = {1}', [ s, results])); | |
| return results; | |
| } | |
| }; | |
| }; |
Author
Nope, Browserify wraps the file's contents in an IIFE and only module.exports gets exposed.
Seems like they wouldn't be if this is loaded into a node-style context, right? That's the point of the "module.exports" object. All of this stays encapsulated, if I understand correctly.
If you just include this via a <script> tag, of course, then it would be global. But Browserify, as I understand it, basically uses node-style module loading to compile this before you include it, right?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But aren't the functions
hex()andrhex()global; with this implementation ?