Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

commonjs modules detection

  • Loading branch information...
commit 3f8c10bf24a1b37ac105a7e5197d0c8482075e7b 1 parent a65639b
Azer Koculu authored
Showing with 10 additions and 0 deletions.
  1. +3 −0  README.markdown
  2. +5 −0 lib/environ.js
  3. +2 −0  test/tests.js
View
3  README.markdown
@@ -23,6 +23,8 @@ On Browsers:
On a CommonJS compliant platform:
> var environ = require('environ');
+ > environ.packages()
+ true
> environ.node()
true
> environ.dom()
@@ -42,6 +44,7 @@ Available Methods
* ie
* kindle
* linux
+* modules
* navigator
* node
* mobile
View
5 lib/environ.js
@@ -20,6 +20,10 @@ var environ = (function(exports, undefined){
return /linux/i.test(node() && process.platform || navigator.userAgent);
}
+ function modules(){
+ return typeof module !== 'undefined' && typeof module.exports !== 'undefined';
+ }
+
function navigator(){
return typeof window != 'undefined' && window.navigator != undefined;
}
@@ -47,6 +51,7 @@ var environ = (function(exports, undefined){
'kindle':newRegexTest(/Kindle/),
'ie':newRegexTest(/msie/i),
'linux':linux,
+ 'modules':modules,
'navigator':navigator,
'node':node,
'mobile':newRegexTest(/mobile/i),
View
2  test/tests.js
@@ -4,6 +4,7 @@ if(typeof require!='undefined'){
}
var node = typeof process != 'undefined' && process.EventEmitter != undefined,
+ modules = node || (typeof module !== 'undefined' || module.exports),
nav = typeof window != 'undefined' && window.navigator != undefined;
function test_browsers(){
@@ -30,6 +31,7 @@ function test_engines(){
function test_platform(){
assert.equal(environ.node(), node);
+ assert.equal(environ.modules(), modules);
}
var tests = {
Please sign in to comment.
Something went wrong with that request. Please try again.