Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/globals
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 890bcfe6e052739ce2d4dea038589f9243cf9b17
Choose a base ref
...
head repository: sindresorhus/globals
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f966f4d1acf7fcacb34911719108dd5bc970fac9
Choose a head ref

Commits on Oct 29, 2017

  1. Add PerformanceObserver (#120)

    jonkeller authored and sindresorhus committed Oct 29, 2017
    Copy the full SHA
    308f142 View commit details
  2. 10.2.0

    sindresorhus committed Oct 29, 2017
    Copy the full SHA
    8cb3de2 View commit details

Commits on Nov 3, 2017

  1. Copy the full SHA
    50a3bb9 View commit details
  2. 10.3.0

    sindresorhus committed Nov 3, 2017
    Copy the full SHA
    1de990c View commit details

Commits on Nov 17, 2017

  1. Add GM to greasemonkey

    Fixes #122
    Closes #123
    sindresorhus committed Nov 17, 2017
    Copy the full SHA
    c55efa4 View commit details
  2. 10.4.0

    sindresorhus committed Nov 17, 2017
    Copy the full SHA
    18de215 View commit details
  3. Remove System (#121)

    mysticatea authored and sindresorhus committed Nov 17, 2017
    Copy the full SHA
    c4982d1 View commit details
  4. Remove deprecated node globals

    Also removes `arguments` as it should not be depended upon as it's just a side-effect of the script being wrapped in an IIFE internally and will not work with ES2015 modules.
    
    Fixes #117
    sindresorhus committed Nov 17, 2017
    Copy the full SHA
    0e23a5c View commit details
  5. Meta tweaks

    sindresorhus committed Nov 17, 2017
    Copy the full SHA
    fdd1962 View commit details
  6. Add and remove browser globals

    According to latest Chrome Canary.
    sindresorhus committed Nov 17, 2017
    Copy the full SHA
    c736b57 View commit details
  7. Add devtools globals

    For when you're in the DevTools console.
    sindresorhus committed Nov 17, 2017
    Copy the full SHA
    9e25b17 View commit details
  8. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    65efa0d View commit details
  9. Rename es6 to es2015 and es8 to es2017

    As that's their official names.
    sindresorhus committed Nov 17, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    baccc2a View commit details
  10. 11.0.0

    sindresorhus committed Nov 17, 2017
    Copy the full SHA
    969a12c View commit details
  11. Make event properties rewritable (#124)

    * Chore: remove duplicated properties
    
    * Fix: make event properties rewritable
    
    * Update get-browser-globals.js
    mysticatea authored and sindresorhus committed Nov 17, 2017
    Copy the full SHA
    427dc53 View commit details
  12. 11.0.1

    sindresorhus committed Nov 17, 2017
    Copy the full SHA
    b8c38eb View commit details

Commits on Dec 9, 2017

  1. Copy the full SHA
    f701fd5 View commit details
  2. Copy the full SHA
    2bcc603 View commit details
  3. Copy the full SHA
    4a22639 View commit details
  4. 11.1.0

    sindresorhus committed Dec 9, 2017
    Copy the full SHA
    97c7105 View commit details

Commits on Jan 25, 2018

  1. Add AbortController, AbortSignal in "browser" environment (#128)

    Implemented already in Firefox + Edge, and soon in Chrome (crbug.com/750599)
    mo authored and sindresorhus committed Jan 25, 2018
    Copy the full SHA
    9449d19 View commit details
  2. 11.2.0

    sindresorhus committed Jan 25, 2018
    Copy the full SHA
    df0993c View commit details

Commits on Jan 30, 2018

  1. Add WebRTC related variables in browser env (#130)

    Yuji Sugiura authored and sindresorhus committed Jan 30, 2018
    Copy the full SHA
    9aef6ad View commit details
  2. 11.3.0

    sindresorhus committed Jan 30, 2018
    Copy the full SHA
    f1448bb View commit details

Commits on Mar 24, 2018

  1. Copy the full SHA
    fa0f44e View commit details
  2. 11.4.0

    sindresorhus committed Mar 24, 2018
    Copy the full SHA
    7591679 View commit details

Commits on Apr 27, 2018

  1. Copy the full SHA
    0a57eb5 View commit details
  2. 11.5.0

    sindresorhus committed Apr 27, 2018
    Copy the full SHA
    4ce1b7a View commit details

Commits on Jun 19, 2018

  1. Add BigInt to builtin (#137)

    silverwind authored and sindresorhus committed Jun 19, 2018
    Copy the full SHA
    baee13c View commit details
  2. Add AudioWorklet interfaces (#136)

    pioug authored and sindresorhus committed Jun 19, 2018
    Copy the full SHA
    8542fdd View commit details
  3. Meta tweaks

    sindresorhus committed Jun 19, 2018
    Copy the full SHA
    7552368 View commit details
  4. 11.6.0

    sindresorhus committed Jun 19, 2018
    Copy the full SHA
    feb15f3 View commit details

Commits on Jun 20, 2018

  1. Copy the full SHA
    69916b9 View commit details
  2. 11.7.0

    sindresorhus committed Jun 20, 2018
    Copy the full SHA
    45fc1b8 View commit details

Commits on Sep 24, 2018

  1. fix yui global variables (#139)

    * fix yui global variables
    
    * correct alphabetical order
    Mouvedia authored and nzakas committed Sep 24, 2018
    Copy the full SHA
    bc1ab8d View commit details

Commits on Oct 2, 2018

  1. Copy the full SHA
    b044d50 View commit details
  2. 11.8.0

    sindresorhus committed Oct 2, 2018
    Copy the full SHA
    40a26a4 View commit details

Commits on Nov 12, 2018

  1. Add some globals (#142)

    - Add `queueMicrotask` to node and browsers
    - Add `TextEncoder` and `TextDecoder` to node
    devsnek authored and sindresorhus committed Nov 12, 2018
    Copy the full SHA
    2f083e3 View commit details
  2. 11.9.0

    sindresorhus committed Nov 12, 2018
    Copy the full SHA
    3341b4d View commit details

Commits on Jan 9, 2019

  1. Copy the full SHA
    71dd473 View commit details
  2. Change location in the browser environment to be a read-write globa…

    …l, rather than read-only (#143)
    Standard8 authored and sindresorhus committed Jan 9, 2019
    Copy the full SHA
    2e5e841 View commit details
  3. 11.10.0

    sindresorhus committed Jan 9, 2019
    Copy the full SHA
    06fb764 View commit details

Commits on Feb 11, 2019

  1. Copy the full SHA
    c83536e View commit details
  2. 11.11.0

    sindresorhus committed Feb 11, 2019
    Copy the full SHA
    0155131 View commit details

Commits on Apr 30, 2019

  1. Copy the full SHA
    53a0bde View commit details
  2. 11.12.0

    sindresorhus committed Apr 30, 2019
    Copy the full SHA
    6bf39e6 View commit details

Commits on May 28, 2019

  1. Create funding.yml

    sindresorhus authored May 28, 2019
    Copy the full SHA
    8f022be View commit details

Commits on Jul 21, 2019

  1. Copy the full SHA
    0ca4843 View commit details
  2. Meta tweaks

    sindresorhus committed Jul 21, 2019
    Copy the full SHA
    ba730a1 View commit details
  3. 12.0.0

    sindresorhus committed Jul 21, 2019
    Copy the full SHA
    a1d32c7 View commit details
Showing with 1,049 additions and 403 deletions.
  1. +1 −2 .gitattributes
  2. +2 −0 .github/funding.yml
  3. +3 −0 .github/security.md
  4. +22 −0 .github/workflows/main.yml
  5. +1 −0 .gitignore
  6. +1 −0 .npmrc
  7. +0 −5 .travis.yml
  8. +75 −0 get-browser-globals.js
  9. +813 −134 globals.json
  10. +6 −0 index.d.ts
  11. +7 −0 index.test-d.ts
  12. +1 −1 license
  13. +0 −211 package-lock.json
  14. +53 −33 package.json
  15. +26 −11 readme.md
  16. +38 −6 test.js
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
2 changes: 2 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: sindresorhus
tidelift: npm/globals
3 changes: 3 additions & 0 deletions .github/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

75 changes: 75 additions & 0 deletions get-browser-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

const ignorePatterns = [
/^webkit/i,
'BeforeInstallPromptEvent',
/^Bluetooth/,
'CDATASection',
'captureEvents',
'InputDeviceCapabilities',
'releaseEvents',
'SyncManager',
/^USB/,

// DevTools globals
'chrome',
'$_',
'$0',
'$1',
'$2',
'$3',
'$4',
'$',
'$$',
'$x',
'clear',
'copy',
'debug',
'dir',
'dirxml',
'getEventListeners',
'inspect',
'keys',
'monitor',
'monitorEvents',
'profile',
'profileEnd',
'queryObjects',
'table',
'undebug',
'unmonitor',
'unmonitorEvents',
'values'
];

const globals = Object.getOwnPropertyNames(window)
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.filter(global => {
for (const pattern of ignorePatterns) {
if (typeof pattern === 'string') {
if (global === pattern) {
return false;
}
} else {
if (pattern.test(global)) {
return false;
}
}
}

return true;
});

const ret = {};
for (const key of globals) {
ret[key] = key.startsWith('on');
}

copy(JSON.stringify(ret, null, '\t'));

/*
Usage:
Open an Incognito window in Chrome Canary and paste the above into the console. You'll now have a new object in your clipboard for the `browser` field in `globals.json`. You still need to manually filter out items from the `builtin` list.
*/
947 changes: 813 additions & 134 deletions globals.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {ReadonlyDeep} from 'type-fest';
import globalsJson = require('./globals.json');

declare const globals: ReadonlyDeep<typeof globalsJson>;

export = globals;
7 changes: 7 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {expectType, expectError} from 'tsd';
import {ReadonlyDeep} from 'type-fest';
import globals = require('.');

expectType<ReadonlyDeep<Record<string, Record<string, boolean>>>>(globals);
expectType<boolean>(globals.builtin.Array);
expectError((globals.builtin.Array = true));
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

211 changes: 0 additions & 211 deletions package-lock.json

This file was deleted.

86 changes: 53 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
{
"name": "globals",
"version": "10.1.0",
"description": "Global identifiers from different JavaScript environments",
"license": "MIT",
"repository": "sindresorhus/globals",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "mocha"
},
"files": [
"index.js",
"globals.json"
],
"keywords": [
"globals",
"global",
"identifiers",
"variables",
"vars",
"jshint",
"eslint",
"environments"
],
"devDependencies": {
"mocha": "^3.4.2"
}
"name": "globals",
"version": "13.21.0",
"description": "Global identifiers from different JavaScript environments",
"license": "MIT",
"repository": "sindresorhus/globals",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js",
"index.d.ts",
"globals.json"
],
"keywords": [
"globals",
"global",
"identifiers",
"variables",
"vars",
"jshint",
"eslint",
"environments"
],
"dependencies": {
"type-fest": "^0.20.2"
},
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.14.0",
"xo": "^0.36.1"
},
"xo": {
"ignores": [
"get-browser-globals.js"
],
"rules": {
"node/no-unsupported-features/es-syntax": "off"
}
},
"tsd": {
"compilerOptions": {
"resolveJsonModule": true
}
}
}
37 changes: 26 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# globals [![Build Status](https://travis-ci.org/sindresorhus/globals.svg?branch=master)](https://travis-ci.org/sindresorhus/globals)
# globals

> Global identifiers from different JavaScript environments
Extracted from [JSHint](https://github.com/jshint/jshint/blob/3a8efa979dbb157bfb5c10b5826603a55a33b9ad/src/vars.js) and [ESLint](https://github.com/eslint/eslint/blob/b648406218f8a2d7302b98f5565e23199f44eb31/conf/environments.json) and merged.
It's just a [JSON file](globals.json), so use it in any environment.

It's just a [JSON file](globals.json), so use it in whatever environment you like.

**This module [no longer accepts](https://github.com/sindresorhus/globals/issues/82) new environments. If you need it for ESLint, just [create a plugin](http://eslint.org/docs/developer-guide/working-with-plugins#environments-in-plugins).**
This package is used by ESLint.

**This package [no longer accepts](https://github.com/sindresorhus/globals/issues/82) new environments. If you need it for ESLint, just [create a plugin](http://eslint.org/docs/developer-guide/working-with-plugins#environments-in-plugins).**

## Install

```
$ npm install --save globals
$ npm install globals
```


## Usage

```js
var globals = require('globals');
const globals = require('globals');

console.log(globals.browser);
/*
@@ -28,14 +26,31 @@ console.log(globals.browser);
applicationCache: false,
ArrayBuffer: false,
atob: false,
...
}
*/
```

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.

For Node.js this package provides two sets of globals:

- `globals.nodeBuiltin`: Globals available to all code running in Node.js.
These will usually be available as properties on the `global` object and include `process`, `Buffer`, but not CommonJS arguments like `require`.
See: https://nodejs.org/api/globals.html
- `globals.node`: A combination of the globals from `nodeBuiltin` plus all CommonJS arguments ("CommonJS module scope").
See: https://nodejs.org/api/modules.html#modules_the_module_scope

When analyzing code that is known to run outside of a CommonJS wrapper, for example, JavaScript modules, `nodeBuiltin` can find accidental CommonJS references.

## License
---

MIT © [Sindre Sorhus](http://sindresorhus.com)
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-globals?utm_source=npm-globals&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
44 changes: 38 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
'use strict';
const assert = require('assert');
const globals = require('.');
import test from 'ava';
import globals from '.';

it('should return an object of globals', () => {
assert.strictEqual(typeof globals, 'object');
assert(Object.keys(globals).length > 10 && Object.keys(globals).length < 1000);
test('main', t => {
t.is(typeof globals, 'object');
t.true(Object.keys(globals).length > 10 && Object.keys(globals).length < 1000);
});

test('ensure alphabetical order', t => {
for (const env of Object.keys(globals)) {
const keys = Object.keys(globals[env]);
t.deepEqual(
keys.slice(), keys.sort((a, b) => a.localeCompare(b)),
`The \`${env}\` keys don't have the correct alphabetical order`
);
}
});

test('`node` is `nodeBuiltin` with CommonJS arguments', t => {
// `globals.node` has `global`` which isn't a CommonJS argument and doesn't include
// `__filename` and `__dirname` which are.
const commonjsArgs = {
__dirname: false,
__filename: false,
exports: true,
module: false,
require: false
};

t.deepEqual({...globals.nodeBuiltin, ...commonjsArgs}, globals.node);

// Ensure that there's no overlap between true globals and the CommonJS arguments above.
for (const builtin of Object.keys(globals.nodeBuiltin)) {
t.is(
commonjsArgs[builtin],
undefined,
`The builtin ${builtin} is not a CommonJS argument`
);
}
});