nigerian-mobile-validator
Version:
The most rigorous, up-to-date library for validating Nigerian mobile numbers. Fully NCC-compliant, and security-focused, with enterprise-grade features to prevent the business risks of validation failures in regulated industries.
73 lines (72 loc) • 3.17 kB
JavaScript
;
// src/utils/runtime-environment.ts
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuntimeEnvironment = exports.CurrentEnvironment = void 0;
/**
* An enum indicating the environment our code is running in ie node, browser, or web worker
*/
var CurrentEnvironment;
(function (CurrentEnvironment) {
/** The code is running in a browser environment */
CurrentEnvironment["Browser"] = "Browser";
/** The code is running in a Node.js environment */
CurrentEnvironment["Node"] = "Node";
/** The code is running in a Web Worker environment */
CurrentEnvironment["WebWorker"] = "Webworker";
/** The environment code is running in cannot be determined */
CurrentEnvironment["Unknown"] = "Unknown";
})(CurrentEnvironment || (exports.CurrentEnvironment = CurrentEnvironment = {}));
/**
* Checks if we are running in a node, browser, or web worker environment
*/
class RuntimeEnvironment {
/**
* Gets a boolen flag indicating if the code appears to be running in a browser environment.
*
* NOTE: Avoid using this getter and use {@link currentEnvironment} instead.
*/
static get isBrowserDocumentPresent() {
return (typeof window !== 'undefined' && window !== null) && typeof window.document !== 'undefined';
}
/**
* Gets a boolen flag indicating if the code appears to be running in a Node.js environment.
*
* NOTE: Avoid using this getter and use {@link currentEnvironment} instead.
*/
static get isNodeProcessPresent() {
var _a;
return (typeof process !== 'undefined' && process !== null) && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node) != null;
}
/**
* Gets a boolen flag indicating if the code appears to be running in a Web Worker environment.
*
* NOTE: Avoid using this getter and use {@link currentEnvironment} instead.
*/
static get isWebWorkerConstructorPresent() {
return (typeof self !== 'undefined' && self !== null) &&
typeof self === 'object' &&
self.constructor &&
self.constructor.name === 'DedicatedWorkerGlobalScope';
}
/**
* Gets the most likely environment our code is running in ie node, browser, or web worker
*
* @returns A {@link CurrentEnvironment} enum indicating the environment our code is running in
* i.e. Node, Browser, or Web worker
*
* @description
* Resolves conflicts by setting priority order as Node > Browser > Web worker
*/
static get currentEnvironment() {
if (RuntimeEnvironment.isNodeProcessPresent)
return CurrentEnvironment.Node;
if (RuntimeEnvironment.isBrowserDocumentPresent && RuntimeEnvironment.isWebWorkerConstructorPresent)
return CurrentEnvironment.Node; // Edge case
if (RuntimeEnvironment.isBrowserDocumentPresent)
return CurrentEnvironment.Browser;
if (RuntimeEnvironment.isWebWorkerConstructorPresent)
return CurrentEnvironment.WebWorker;
return CurrentEnvironment.Unknown;
}
}
exports.RuntimeEnvironment = RuntimeEnvironment;