From bde8f340c7a9e888574e29b1eea0d799206e2c86 Mon Sep 17 00:00:00 2001 From: dcode Date: Tue, 14 Jul 2020 23:12:42 +0200 Subject: [PATCH] reorder --- index.d.ts | 9 ++++++--- src/util/minimal.js | 35 ++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/index.d.ts b/index.d.ts index 772250491..cb86b61e6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1951,15 +1951,18 @@ export namespace util { public length(): number; } + /** Whether running within node or not. */ + let isNode: boolean; + + /** Global object reference. */ + let global: object; + /** An immuable empty array. */ const emptyArray: any[]; /** An immutable empty object. */ const emptyObject: object; - /** Whether running within node or not. */ - const isNode: boolean; - /** * Tests if the specified value is an integer. * @param value Value to test diff --git a/src/util/minimal.js b/src/util/minimal.js index 4bf53fabf..064b6dd3d 100644 --- a/src/util/minimal.js +++ b/src/util/minimal.js @@ -25,18 +25,23 @@ util.pool = require("@protobufjs/pool"); // utility to work with the low and high bits of a 64 bit value util.LongBits = require("./longbits"); -/** Tests whether the specified object is most likely a node.js process. */ -function isNodeProcess(process) { - return Boolean(process && process.versions && process.versions.node); -} - -/** Tests whether the specified object is most likely a node.js global. */ -function isNodeGlobal(global) { - return global && isNodeProcess(global.process); -} +/** + * Whether running within node or not. + * @memberof util + * @type {boolean} + */ +util.isNode = typeof global !== "undefined" + && global + && global.process + && global.process.versions + && global.process.versions.node; -// global object reference -util.global = typeof global !== "undefined" && isNodeGlobal(global) && global +/** + * Global object reference. + * @memberof util + * @type {Object} + */ +util.global = util.isNode && global || typeof window !== "undefined" && window || typeof self !== "undefined" && self || this; // eslint-disable-line no-invalid-this @@ -56,14 +61,6 @@ util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ */ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes -/** - * Whether running within node or not. - * @memberof util - * @type {boolean} - * @const - */ -util.isNode = isNodeProcess(util.global.process); - /** * Tests if the specified value is an integer. * @function