Skip to content

Latest commit

 

History

History
118 lines (88 loc) · 3.17 KB

File metadata and controls

118 lines (88 loc) · 3.17 KB

⚙️ Runtime Utilities

Useful runtime helpers for platform detection, module loading, and environment awareness.


Access the runtime utilities

import atomix from '@nasriya/atomix';

const runtime = atomix.runtime;

The APIs

API Description
getProjectName Reads and returns the project name from the package.json
getModuleSystem Dynamically loads a module by name or path
getRuntimeEngine Detect the current JavaScript runtime environment.
loadModule Dynamically loads a module by name or path
loadFileModule Loads a module from a specified file path
platform Utilities to detect current operating system
isNode Detects if the code is running in Node.js
isBun Detects if the code is running in Bun
isDeno Detects if the code is running in Deno

API Details:

🧾 getProjectName

Signature: getProjectName()

Reads the package.json file and returns the value of the name field.

const name = runtime.getProjectName();
console.log(name); // "@nasriya/my-package"

📦 getModuleSystem

Signature: getModuleSystem()

Detects whether the current runtime uses CommonJS or ESM.

const system = runtime.getModuleSystem();
console.log(system); // "commonjs" or "module"

📥 loadModule

Signature: loadModule(name, options?)

Dynamically loads a module (either a package or path), with support for both CommonJS and ESM.

const lodash = await runtime.loadModule('lodash');
lodash.camelCase('hello world'); // "helloWorld"

📄 loadFileModule

Signature: loadFileModule(filePath)

Loads a module from a file path. Equivalent to loadModule(path, { isFile: true }).

const config = await runtime.loadFileModule('/absolute/path/to/config.js');
console.log(config); // loaded module export

🖥 platform

Signature: platform.isWindows() / isLinux() / isMac()

Detects the current operating system platform.

if (runtime.platform.isWindows()) {
  console.log('Running on Windows');
}

🧠 getRuntimeEngine

Signature: getRuntimeEngine(): 'node' | 'bun' | 'deno' | 'unknown'

Detect the current JavaScript runtime environment.

const runtimeEngine = runtime.getRuntimeEngine();
console.log(runtimeEngine);
// "node", "bun", "deno", or "unknown"

🌍 isNode

Signature: isNode()

if (runtime.isNode()) {
  console.log('Running in Node.js');
}

🥖 isBun

Signature: isBun()

if (runtime.isBun()) {
  console.log('Running in Bun');
}

🦕 isDeno

Signature: isDeno()

if (runtime.isDeno()) {
  console.log('Running in Deno');
}