forked from dosyago/dn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
33 lines (24 loc) · 993 Bytes
/
common.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
import path from 'path';
import {fileURLToPath} from 'url';
// determine where this code is running
let Context = 'unknown';
// ignore the possibility that window or global or chrome could be overwritten
const isBrowser = function () { try {return window && window.fetch;}catch(e){ return false;} };
const isNode = function () { try {return global && global.Math;}catch(e){return false;} };
const isExtension = function () { try {return chrome.runtime && chrome.debugger;}catch(e){return false;} };
if ( isNode() ) {
Context = 'node';
} else if ( isBrowser() ) {
Context = 'browser';
if ( isExtension() ) {
Context = 'extension';
}
}
export const context = Context;
export const DEBUG = process.env.DEBUG_22120 || false;
export const NO_SANDBOX = process.env.DEBUG_22120 || false;
export const APP_ROOT = __dirname;
export const sleep = ms => new Promise(res => setTimeout(res, ms));
export function say(o) {
console.log(JSON.stringify(o));
}