@augment-vir/node
Version:
A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.
56 lines (55 loc) • 1.65 kB
JavaScript
/**
* The three major operating system types.
*
* @category Node : OS
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export var OperatingSystem;
(function (OperatingSystem) {
OperatingSystem["Linux"] = "linux";
OperatingSystem["Mac"] = "mac";
OperatingSystem["Windows"] = "windows";
})(OperatingSystem || (OperatingSystem = {}));
/**
* The current operating system type, as deduced from
* [`process.platform`](https://nodejs.org/api/process.html#processplatform).
*
* @category Node : OS
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export const currentOperatingSystem = getOperatingSystem();
/**
* Checks if the current operating system is the requested one.
*
* @category Node : OS
* @category Package : @augment-vir/node
* @example
*
* ```ts
* import {isOperatingSystem, OperatingSystem} from '@augment-vir/node';
*
* if (isOperatingSystem(OperatingSystem.Mac)) {
* // do something
* }
* ```
*
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export function isOperatingSystem(operatingSystem) {
return currentOperatingSystem === operatingSystem;
}
function getOperatingSystem() {
/** We can't test all of these on a single system. */
/* node:coverage ignore next 7 */
if (process.platform === 'win32') {
return OperatingSystem.Windows;
}
else if (process.platform === 'darwin') {
return OperatingSystem.Mac;
}
else {
return OperatingSystem.Linux;
}
}