-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
115 lines (97 loc) · 2.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
*
* Package: which-platform
* Author: Ganesh B
* Description: check if an enviromment is a nodejs or browser enviroment
* Install: npm i which-platform --save
* Github: https://github.com/ganeshkbhat/which-platform
* npmjs Link: https://www.npmjs.com/package/which-platform
* File: index.js
* File Description: file has isBrowser function that checks if an enviromment is a nodejs or browser enviroment
*
*/
/* eslint no-console: 0 */
'use strict';
// function coreJSImplementation() {
// // /core-js/internals/global.js
// https://www.npmjs.com/package/core-js
// var check = function (it) {
// return it && it.Math === Math && it;
// };
// // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
// module.exports =
// // eslint-disable-next-line es/no-global-this -- safe
// check(typeof globalThis == 'object' && globalThis) ||
// check(typeof window == 'object' && window) ||
// // eslint-disable-next-line no-restricted-globals -- safe
// check(typeof self == 'object' && self) ||
// check(typeof global == 'object' && global) ||
// check(typeof this == 'object' && this) ||
// // eslint-disable-next-line no-new-func -- fallback
// (function () { return this; })() || Function('return this')();
// }
/**
* isBrowser
*
* @return {*}
*/
function isBrowser() {
if (typeof process === "object" && typeof require === "function") {
return false;
}
if (typeof importScripts === "function") { return false; }
if (typeof window === "object") { return true; }
}
/**
*
*
* @return {*}
*/
function nodeVersionLTS() {
return { lts: process.versions.node.split('.')[0], version: process.versions.node.split('.') };
}
/**
*
*
* @return {*}
*/
function nodeVersion() {
return process.versions.node.split('.')[0];
}
function whichVersion() {
// Check if the environment is Node.js
if (typeof process === "object" &&
typeof require === "function") {
return nodeVersion();
}
// Check if the environment is a Service worker
if (typeof importScripts === "function") {
return window.navigator.userAgent;
}
// Check if the environment is a Browser
if (typeof window === "object") {
return window.navigator.userAgent;
}
}
function isBrowser() {
// Check if the environment is Node.js
if (typeof process === "object" &&
typeof require === "function") {
return false;
}
// Check if the environment is a Service worker
if (typeof importScripts === "function") {
return false;
}
// Check if the environment is a Browser
if (typeof window === "object") {
return true;
}
}
if (!isBrowser()) {
module.exports.isBrowser = isBrowser;
module.exports.whichVersion = whichVersion;
module.exports.default = isBrowser;
module.exports.nodeVersionLTS = nodeVersionLTS;
module.exports.nodeVersion = nodeVersion;
}