Skip to content

Commit

Permalink
[breaking] update property name, rename repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 26, 2018
1 parent 37fad9d commit be42e3d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

"extends": "@ljharb",

"globals": {
"globalThis": false,
},

"rules": {
"max-statements-per-line": [2, { "max": 2 }]
}
Expand Down
54 changes: 26 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#system.global <sup>[![Version Badge][npm-version-svg]][npm-url]</sup>
# globalThis <sup>[![Version Badge][npm-version-svg]][npm-url]</sup>

[![Build Status][travis-svg]][travis-url]
[![dependency status][deps-svg]][deps-url]
Expand All @@ -8,17 +8,15 @@

[![npm badge][npm-badge-png]][npm-url]

[![browser support][testling-png]][testling-url]

An ECMAScript spec-compliant polyfill/shim for `global`. Invoke its "shim" method to shim `global` if it is unavailable.
An ECMAScript spec-compliant polyfill/shim for `globalThis`. Invoke its "shim" method to shim `globalThis` if it is unavailable.

This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec proposal](https://github.com/tc39/proposal-global).

Most common usage:
```js
var global = require('system.global')(); // returns native method if compliant
var globalThis = require('globalThis')(); // returns native method if compliant
/* or */
var global = require('system.global/polyfill')(); // returns native method if compliant
var globalThis = require('globalThis/polyfill')(); // returns native method if compliant
```

## Example
Expand All @@ -30,42 +28,42 @@ var assert = require('assert');
// global object in sloppy mode in every engine.
var getGlobal = Function('return this');

assert.equal(global, getGlobal());
assert.equal(globalThis, getGlobal());
```

```js
/* when `global` is not present */
var shimmedGlobal = require('system.global').shim();
/* when `globalThis` is not present */
var shimmedGlobal = require('globalthis').shim();
/* or */
var shimmedGlobal = require('system.global/shim')();
var shimmedGlobal = require('globalthis/shim')();

assert.equal(shimmedGlobal, global);
assert.equal(shimmedGlobal, globalThis);
assert.equal(shimmedGlobal, getGlobal());
```

```js
/* when `global` is present */
var shimmedGlobal = require('system.global').shim();
/* when `globalThis` is present */
var shimmedGlobal = require('globalthis').shim();

assert.equal(shimmedGlobal, global);
assert.equal(shimmedGlobal, globalThis);
assert.equal(shimmedGlobal, getGlobal());
```

## Tests
Simply clone the repo, `npm install`, and run `npm test`

[npm-url]: https://npmjs.org/package/system.global
[npm-version-svg]: http://versionbadg.es/ljharb/System.global.svg
[travis-svg]: https://travis-ci.org/ljharb/System.global.svg
[travis-url]: https://travis-ci.org/ljharb/System.global
[deps-svg]: https://david-dm.org/ljharb/System.global.svg?theme=shields.io
[deps-url]: https://david-dm.org/ljharb/System.global
[dev-deps-svg]: https://david-dm.org/ljharb/System.global/dev-status.svg?theme=shields.io
[dev-deps-url]: https://david-dm.org/ljharb/System.global#info=devDependencies
[testling-png]: https://ci.testling.com/ljharb/System.global.png
[testling-url]: https://ci.testling.com/ljharb/System.global
[npm-badge-png]: https://nodei.co/npm/system.global.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/system.global.svg
[npm-url]: https://npmjs.org/package/globalthis
[npm-version-svg]: http://versionbadg.es/ljharb/globalThis.svg
[travis-svg]: https://travis-ci.org/ljharb/globalThis.svg
[travis-url]: https://travis-ci.org/ljharb/globalThis
[deps-svg]: https://david-dm.org/ljharb/globalThis.svg?theme=shields.io
[deps-url]: https://david-dm.org/ljharb/globalThis
[dev-deps-svg]: https://david-dm.org/ljharb/globalThis/dev-status.svg?theme=shields.io
[dev-deps-url]: https://david-dm.org/ljharb/globalThis#info=devDependencies
[testling-png]: https://ci.testling.com/ljharb/globalThis.png
[testling-url]: https://ci.testling.com/ljharb/globalThis
[npm-badge-png]: https://nodei.co/npm/globalthis.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/globalthis.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/system.global.svg
[downloads-url]: http://npm-stat.com/charts.html?package=system.global
[downloads-image]: http://img.shields.io/npm/dm/globalthis.svg
[downloads-url]: http://npm-stat.com/charts.html?package=globalthis
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "system.global",
"version": "2.0.0",
"name": "globalthis",
"version": "0.0.0",
"author": "Jordan Harband",
"description": "ECMAScript spec-compliant polyfill/shim for `global`",
"description": "ECMAScript spec-compliant polyfill/shim for `globalThis`",
"license": "MIT",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -30,8 +30,10 @@
"window",
"self",
"global",
"globalThis",
"System.global",
"global object",
"global this value",
"ECMAScript",
"es-shim API",
"polyfill",
Expand Down
10 changes: 5 additions & 5 deletions shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ var getPolyfill = require('./polyfill');
module.exports = function shimGlobal() {
var polyfill = getPolyfill();
if (define.supportsDescriptors) {
var descriptor = Object.getOwnPropertyDescriptor(polyfill, 'global');
if (!descriptor || (descriptor.configurable && (descriptor.enumerable || descriptor.writable || global !== polyfill))) { // eslint-disable-line max-len
Object.defineProperty(polyfill, 'global', {
var descriptor = Object.getOwnPropertyDescriptor(polyfill, 'globalThis');
if (!descriptor || (descriptor.configurable && (descriptor.enumerable || descriptor.writable || globalThis !== polyfill))) { // eslint-disable-line max-len
Object.defineProperty(polyfill, 'globalThis', {
configurable: true,
enumerable: false,
value: polyfill,
writable: false
});
}
} else if (typeof global !== 'object' || global !== polyfill) {
polyfill.global = polyfill;
} else if (typeof globalThis !== 'object' || globalThis !== polyfill) {
polyfill.globalThis = polyfill;
}
return polyfill;
};
12 changes: 6 additions & 6 deletions test/shimmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ var isEnumerable = Object.prototype.propertyIsEnumerable;
var runTests = require('./tests');

test('shimmed', function (t) {
t.equal(typeof global, 'object', 'global is an object');
t.equal('global' in global, true, 'global is in global');
t.equal(typeof globalThis, 'object', 'globalThis is an object');
t.equal('globalThis' in globalThis, true, 'globalThis is in globalThis');

t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
et.equal(false, isEnumerable.call(global, 'global'), 'global.global is not enumerable');
et.equal(false, isEnumerable.call(globalThis, 'globalThis'), 'globalThis.globalThis is not enumerable');
et.end();
});

t.test('writability', { skip: !defineProperties.supportsDescriptors }, function (wt) {
var desc = Object.getOwnPropertyDescriptor(global, 'global');
wt.equal(desc.writable, false, 'global.global is not writable');
var desc = Object.getOwnPropertyDescriptor(globalThis, 'globalThis');
wt.equal(desc.writable, false, 'globalThis.globalThis is not writable');
wt.end();
});

runTests(global.global, t);
runTests(globalThis.globalThis, t);

t.end();
});

0 comments on commit be42e3d

Please sign in to comment.