UNPKG

@eleva-io/erp-sdk

Version:

SDK oficial para el ERP de Eleva

100 lines 2.96 kB
"use strict"; // Utility functions for cross-platform compatibility Object.defineProperty(exports, "__esModule", { value: true }); exports.isNode = exports.isBrowser = void 0; exports.createBuffer = createBuffer; exports.bufferToString = bufferToString; exports.createFile = createFile; exports.createFormData = createFormData; exports.isCrossPlatformBuffer = isCrossPlatformBuffer; /** * Check if the code is running in a browser environment */ exports.isBrowser = typeof globalThis !== 'undefined' && typeof globalThis.window !== 'undefined' && typeof globalThis.document !== 'undefined'; /** * Check if the code is running in a Node.js environment */ exports.isNode = typeof globalThis !== 'undefined' && typeof globalThis.process !== 'undefined' && globalThis.process.versions && globalThis.process.versions.node; /** * Create a Buffer-like object that works in both browser and Node.js */ function createBuffer(data) { if (exports.isNode) { // In Node.js, use Buffer if (data instanceof ArrayBuffer) { return Buffer.from(data); } if (typeof data === 'string') { return Buffer.from(data, 'utf8'); } return data; } else { // In browser, use Uint8Array if (data instanceof ArrayBuffer) { return new Uint8Array(data); } if (typeof data === 'string') { return new TextEncoder().encode(data); } return new Uint8Array(data); } } /** * Convert Buffer/Uint8Array to string */ function bufferToString(buffer) { if (exports.isNode) { return buffer.toString('utf8'); } else { return new TextDecoder().decode(buffer); } } /** * Create a File object that works in both environments */ function createFile(data, name, type) { if (exports.isBrowser) { // In browser, use File constructor if (typeof data === 'string') { return new File([data], name, { type }); } return new File([data], name, { type }); } else { // In Node.js, use Blob (or you might want to use a different approach) if (typeof data === 'string') { return new Blob([data], { type }); } return new Blob([data], { type }); } } /** * Create FormData that works in both environments */ function createFormData() { if (exports.isBrowser) { return new FormData(); } else { // In Node.js, you might need to use a polyfill or different approach // For now, we'll assume FormData is available (it might be polyfilled) return new FormData(); } } /** * Check if a value is a cross-platform buffer */ function isCrossPlatformBuffer(value) { if (typeof value !== 'object' || value === null) { return false; } return value instanceof Uint8Array || value instanceof ArrayBuffer; } //# sourceMappingURL=compatibility.js.map