UNPKG

@sconedev/ai_toolkit

Version:

Simplify AI integration in web apps with local and offline model support

36 lines (35 loc) 1.14 kB
/** * Utility to detect browser vs Node.js environment */ /** * Check if the code is running in a browser environment */ export function isBrowser() { return typeof window !== 'undefined' && typeof window.document !== 'undefined'; } /** * Check if the code is running in a Node.js environment */ export function isNode() { return typeof process !== 'undefined' && process.versions != null && process.versions.node != null; } /** * Throws an error if being run in a browser environment * @param functionName Name of the function that requires Node.js */ export function requireNodeEnvironment(functionName) { if (isBrowser()) { throw new Error(`${functionName} is only available in Node.js environment. Use a browser-compatible alternative.`); } } /** * Throws an error if being run in a Node.js environment * @param functionName Name of the function that requires browser */ export function requireBrowserEnvironment(functionName) { if (!isBrowser()) { throw new Error(`${functionName} is only available in browser environments. Use a Node.js-compatible alternative.`); } }