-
Notifications
You must be signed in to change notification settings - Fork 2
/
brnfckr.js
54 lines (44 loc) · 1.42 KB
/
brnfckr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*! https://mths.be/brnfckr v0.1.1 by @mathias */
;(function(root) {
// Detect free variables `exports`
var freeExports = typeof exports == 'object' && exports;
// Detect free variable `module`
var freeModule = typeof module == 'object' && module &&
module.exports == freeExports && module;
// Detect free variable `global` and use it as `root`
var freeGlobal = typeof global == 'object' && global;
if (freeGlobal.global === freeGlobal) {
root = freeGlobal;
}
/*--------------------------------------------------------------------------*/
var regexNotBrainfuck = /[^\x2B-\x2E\x3C\x3E\x5B\x5D]/g;
var minify = function(code) {
return code.replace(regexNotBrainfuck, '');
};
/*--------------------------------------------------------------------------*/
var brnfckr = {
'version': '0.1.1',
'minify': minify
};
// Some AMD build optimizers, like r.js, check for specific condition patterns
// like the following:
if (
typeof define == 'function' &&
typeof define.amd == 'object' &&
define.amd
) {
define(function() {
return brnfckr;
});
} else if (freeExports && !freeExports.nodeType) {
if (freeModule) { // in Node.js or RingoJS v0.8.0+
freeModule.exports = brnfckr;
} else { // in Narwhal or RingoJS v0.7.0-
for (var key in brnfckr) {
brnfckr.hasOwnProperty(key) && (freeExports[key] = brnfckr[key]);
}
}
} else { // in Rhino or a web browser
root.brnfckr = brnfckr;
}
}(this));