1 | # globals
|
2 |
|
3 | > Global identifiers from different JavaScript environments
|
4 |
|
5 | It's just a [JSON file](globals.json), so you can use it in any environment.
|
6 |
|
7 | This package is used by ESLint 8 and earlier. For ESLint 9 and later, you should depend on this package directly in [your ESLint config](https://eslint.org/docs/latest/use/configure/language-options#predefined-global-variables).
|
8 |
|
9 | ## Install
|
10 |
|
11 | ```sh
|
12 | npm install globals
|
13 | ```
|
14 |
|
15 | ## Usage
|
16 |
|
17 | ```js
|
18 | import globals from 'globals';
|
19 |
|
20 | console.log(globals.browser);
|
21 | /*
|
22 | {
|
23 | addEventListener: false,
|
24 | applicationCache: false,
|
25 | ArrayBuffer: false,
|
26 | atob: false,
|
27 | …
|
28 | }
|
29 | */
|
30 | ```
|
31 |
|
32 | Each global is given a value of `true` or `false`. A value of `true` indicates that the variable may be overwritten. A value of `false` indicates that the variable should be considered read-only. This information is used by static analysis tools to flag incorrect behavior. We assume all variables should be `false` unless we hear otherwise.
|
33 |
|
34 | For Node.js this package provides two sets of globals:
|
35 |
|
36 | - `globals.nodeBuiltin`: Globals available to all code running in Node.js.
|
37 | These will usually be available as properties on the `globalThis` object and include `process`, `Buffer`, but not CommonJS arguments like `require`.
|
38 | See: https://nodejs.org/api/globals.html
|
39 | - `globals.node`: A combination of the globals from `nodeBuiltin` plus all CommonJS arguments ("CommonJS module scope").
|
40 | See: https://nodejs.org/api/modules.html#modules_the_module_scope
|
41 |
|
42 | When analyzing code that is known to run outside of a CommonJS wrapper, for example, JavaScript modules, `nodeBuiltin` can find accidental CommonJS references.
|