├── .gitignore ├── History.md ├── Makefile ├── component.json ├── package.json ├── index.js └── Readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | components 2 | build 3 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.0.0 / 2015-04-16 3 | ================== 4 | 5 | * add package.json 6 | * fix example 7 | 8 | 0.0.1 / 2014-07-01 9 | ================== 10 | 11 | * Initial commit 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | build: components index.js 3 | @component build --dev 4 | 5 | components: component.json 6 | @component install --dev 7 | 8 | clean: 9 | rm -fr build components template.js 10 | 11 | .PHONY: clean 12 | -------------------------------------------------------------------------------- /component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ie", 3 | "repo": "component/ie", 4 | "description": "get the version of IE or return undefined", 5 | "version": "1.0.0", 6 | "keywords": [], 7 | "dependencies": {}, 8 | "development": {}, 9 | "license": "MIT", 10 | "main": "index.js", 11 | "scripts": [ 12 | "index.js" 13 | ] 14 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "component-ie", 3 | "version": "1.0.0", 4 | "description": "get the version of IE or return undefined", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "make test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/component/ie.git" 12 | }, 13 | "keywords": [ 14 | "ie" 15 | ], 16 | "author": "Matthew Mueller", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/component/ie/issues" 20 | }, 21 | "homepage": "https://github.com/component/ie" 22 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Export `ie`. 3 | */ 4 | 5 | module.exports = ie(); 6 | 7 | /** 8 | * Initialize `ie` 9 | * 10 | * @return {Number|undefined} 11 | * @api public 12 | */ 13 | 14 | function ie() { 15 | for( var v = 3, 16 | el = document.createElement('b'), 17 | // empty array as loop breaker (and exception-avoider) for non-IE and IE10+ 18 | all = el.all || []; 19 | // i tag not well-formed since we know that IE5-IE9 won't mind 20 | el.innerHTML = '', 21 | all[0]; 22 | ); 23 | // return the documentMode for IE10+ compatibility 24 | // non-IE will get undefined 25 | return v > 4 ? v : document.documentMode; 26 | } 27 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # ie 3 | 4 | get the running version of IE or return undefined without UA sniffing. 5 | 6 | ## Installation 7 | 8 | Install with [component(1)](http://component.io): 9 | 10 | $ component install component/ie 11 | 12 | ## Example 13 | 14 | ```js 15 | var ie = require('ie'); 16 | ie // 9 17 | ``` 18 | 19 | ## API 20 | 21 | ### ie() 22 | 23 | Get the version of IE as a `number` or return `undefined`. 24 | 25 | ## Testing 26 | 27 | Test using the wonderful [browser-repl](https://github.com/cloudup/browser-repl). 28 | 29 | Has been tested on: 30 | 31 | - ie8 32 | - ie9 33 | - ie10 34 | - ie11 35 | 36 | ## Credits 37 | 38 | Original source from: https://gist.github.com/padolsey/527683#comment-786682. 39 | 40 | ## License 41 | 42 | The MIT License (MIT) 43 | 44 | Copyright (c) 2014 45 | 46 | Permission is hereby granted, free of charge, to any person obtaining a copy 47 | of this software and associated documentation files (the "Software"), to deal 48 | in the Software without restriction, including without limitation the rights 49 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 50 | copies of the Software, and to permit persons to whom the Software is 51 | furnished to do so, subject to the following conditions: 52 | 53 | The above copyright notice and this permission notice shall be included in 54 | all copies or substantial portions of the Software. 55 | 56 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 57 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 58 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 59 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 60 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 61 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 62 | THE SOFTWARE. 63 | --------------------------------------------------------------------------------