Permalink
Browse files

v1.3.0

  • Loading branch information...
1 parent e274fb0 commit 5df528376e5b8aaaca8915f4f69dfc1bfb74b245 @azer committed Nov 29, 2011
Showing with 50 additions and 27 deletions.
  1. +10 −0 README.markdown → README.md
  2. +37 −24 lib/environ.js
  3. +1 −1 package.json
  4. +2 −2 test/tests.js
View
10 README.markdown → README.md
@@ -11,6 +11,8 @@ On Browsers:
<script src="environ.js"></script>
+ > environ()
+ { chrome: true, dom: true, gecko: true, navigator: true, safari: true, v8: true, webkit: true }
> environ.node()
false
> environ.dom()
@@ -23,6 +25,9 @@ On Browsers:
On a CommonJS compliant platform:
> var environ = require('environ');
+
+ > environ()
+ { linux: true, modules: true, node: true, v8: true }
> environ.packages()
true
> environ.node()
@@ -42,6 +47,11 @@ Available Methods
* gecko
* jsc
* ie
+* ie6
+* ie7
+* ie8
+* ie9
+* ie10
* kindle
* linux
* modules
View
61 lib/environ.js
@@ -1,13 +1,21 @@
-/*
- * environ.js
- * wtf public license
- */
-var environ = (function(exports, undefined){
+var environ = (function(undefined){
function dom(){
return typeof document != 'undefined' && document.documentElement != undefined;
}
+ function detect(){
+ var result = {};
+
+ for(var key in environ){
+ if(environ[key]()){
+ result[key] = true;
+ }
+ }
+
+ return result;
+ }
+
function jsc(){
try {
throw new Error;
@@ -39,27 +47,32 @@ var environ = (function(exports, undefined){
}
function v8(){
- return node() || ( exports.webkit() && !jsc() );
+ return node() || ( detect.webkit() && !jsc() );
}
- return (exports = {
- 'dom':dom,
- 'chrome':newRegexTest(/chrome/i),
- 'firefox':newRegexTest(/firefox/i),
- 'gecko':newRegexTest(/gecko/i),
- 'jsc':jsc,
- 'kindle':newRegexTest(/Kindle/),
- 'ie':newRegexTest(/msie/i),
- 'linux':linux,
- 'modules':modules,
- 'navigator':navigator,
- 'node':node,
- 'mobile':newRegexTest(/mobile/i),
- 'opera':newRegexTest(/opera/i),
- 'safari':newRegexTest(/safari/i),
- 'webkit':newRegexTest(/webkit/i),
- 'v8':v8
- });
+ detect.dom = dom;
+ detect.chrome = newRegexTest(/chrome/i);
+ detect.firefox = newRegexTest(/firefox/i);
+ detect.gecko = newRegexTest(/gecko/i);
+ detect.jsc = jsc;
+ detect.kindle = newRegexTest(/kindle/i);
+ detect.ie = newRegexTest(/msie/i);
+ detect.ie6 = newRegexTest(/msie 6/i);
+ detect.ie7 = newRegexTest(/msie 7/i);
+ detect.ie8 = newRegexTest(/msie 8/i);
+ detect.ie9 = newRegexTest(/msie 9/i);
+ detect.ie10 = newRegexTest(/msie 10/i);
+ detect.linux = linux;
+ detect.modules = modules;
+ detect.navigator = navigator;
+ detect.node = node;
+ detect.mobile = newRegexTest(/mobile/i);
+ detect.opera = newRegexTest(/opera/i);
+ detect.safari = newRegexTest(/safari/i);
+ detect.webkit = newRegexTest(/webkit/i);
+ detect.v8 = v8;
+
+ return detect;
})();
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "environ",
- "version": "1.2",
+ "version": "1.3.0",
"description": "Cross-platform environment detection library for JavaScript",
"author": "Azer Koculu <azer@kodfabrik.com> (http://azer.kodfabrik.com)",
"keywords": [
View
4 test/tests.js
@@ -4,7 +4,7 @@ if(typeof require!='undefined'){
}
var node = typeof process != 'undefined' && process.EventEmitter != undefined,
- modules = node || (typeof module !== 'undefined' || module.exports),
+ modules = node || (typeof module !== 'undefined' && module.exports),
nav = typeof window != 'undefined' && window.navigator != undefined;
function test_browsers(){
@@ -22,7 +22,7 @@ function test_dom(){
function test_engines(){
var jsc = false;
- try { err++ } catch(exc){ jsc = exc.sourceId != undefined }
+ try { err++ } catch(exc){ jsc = exc.sourceId != undefined; }
assert.equal(environ.jsc(), jsc);
assert.equal(environ.v8(), node || ( environ.webkit() && !jsc ) );
assert.equal(environ.gecko(), nav && /gecko/i.test(navigator.userAgent));

0 comments on commit 5df5283

Please sign in to comment.