Repository: JedWatson/exenv
Branch: master
Commit: 5171d645e2d9
Files: 4
Total size: 4.2 KB
Directory structure:
gitextract_k55r0kvo/
├── LICENSE
├── README.md
├── index.js
└── package.json
================================================
FILE CONTENTS
================================================
================================================
FILE: LICENSE
================================================
BSD License
For React software
Copyright (c) 2013-2015, Facebook, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name Facebook nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================
FILE: README.md
================================================
# exenv
React's ExecutionEnvironment module extracted for use in other packages & components.
## Usage
```
npm install exenv --save
```
```js
var ExecutionEnvironment = require('exenv');
// You now have...
ExecutionEnvironment.canUseDOM // is the DOM available? i.e window document etc.
ExecutionEnvironment.canUseWorkers // are Web Workers available?
ExecutionEnvironment.canUseEventListeners // are Events available? i.e addEventListener etc.
ExecutionEnvironment.canUseViewport // is there a viewport? i.e window.screen
```
### Differences from React's ExecutionEnvironment
The `ExecutionEnvironment` lib in React 0.13 includes an `isInWorker` property, which is `!canUseDOM`. This is highly specific to React internals and probably (a) hacky and (b) not useful to other packages, so it has been left out. Please open an issue with your thoughts if you disagree or have a better idea.
## Why?
A number of packages and components use React's private ExecutionEnvironment lib to detect available features, particularly to detect server-side rendering, e.g
```
canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM; // BAD
```
**It is bad practice to use React internals** and this is likely to be broken / disabled in the future.
Use this package instead!
================================================
FILE: index.js
================================================
/*!
Copyright (c) 2015 Jed Watson.
Based on code that is Copyright 2013-2015, Facebook, Inc.
All rights reserved.
*/
/* global define */
(function () {
'use strict';
var canUseDOM = !!(
typeof window !== 'undefined' &&
window.document &&
window.document.createElement
);
var ExecutionEnvironment = {
canUseDOM: canUseDOM,
canUseWorkers: typeof Worker !== 'undefined',
canUseEventListeners:
canUseDOM && !!(window.addEventListener || window.attachEvent),
canUseViewport: canUseDOM && !!window.screen
};
if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
define(function () {
return ExecutionEnvironment;
});
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = ExecutionEnvironment;
} else {
window.ExecutionEnvironment = ExecutionEnvironment;
}
}());
================================================
FILE: package.json
================================================
{
"name": "exenv",
"version": "1.2.2",
"description": "React's ExecutionEnvironment module extracted for use in other packages & components",
"main": "index.js",
"scripts": {
"test": "echo \"See React tests\" && exit 0"
},
"repository": {
"type": "git",
"url": "https://github.com/JedWatson/exenv.git"
},
"keywords": [
"react",
"browser",
"server",
"environment",
"env",
"execution",
"executionenvironment"
],
"author": "Jed Watson",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/JedWatson/exenv/issues"
},
"homepage": "https://github.com/JedWatson/exenv"
}
gitextract_k55r0kvo/ ├── LICENSE ├── README.md ├── index.js └── package.json
Condensed preview — 4 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (5K chars).
[
{
"path": "LICENSE",
"chars": 1523,
"preview": "BSD License\n\nFor React software\n\nCopyright (c) 2013-2015, Facebook, Inc.\nAll rights reserved.\n\nRedistribution and use in"
},
{
"path": "README.md",
"chars": 1312,
"preview": "# exenv\n\nReact's ExecutionEnvironment module extracted for use in other packages & components.\n\n## Usage\n\n```\nnpm in"
},
{
"path": "index.js",
"chars": 863,
"preview": "/*!\n Copyright (c) 2015 Jed Watson.\n Based on code that is Copyright 2013-2015, Facebook, Inc.\n All rights reserved.\n"
},
{
"path": "package.json",
"chars": 650,
"preview": "{\n \"name\": \"exenv\",\n \"version\": \"1.2.2\",\n \"description\": \"React's ExecutionEnvironment module extracted for use in ot"
}
]
About this extraction
This page contains the full source code of the JedWatson/exenv GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 4 files (4.2 KB), approximately 1.1k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.