Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
callMeMaybe
✓ import callMeMaybe from 'call-me-maybe';
✗ import { callMeMaybe } from 'call-me-maybe';
The package exports its main utility function as a default export, compatible with both ESM `import` and CJS `require` syntax.
callMeMaybe (CJS)
✓ const callMeMaybe = require('call-me-maybe');
✗ const { callMeMaybe } = require('call-me-maybe');
When using CommonJS, the default export is directly returned by `require()`. Accessing it as a named property will fail.
This quickstart demonstrates how to create a function that transparently supports both error-first callbacks and Promises using `call-me-maybe`, showing both consumption patterns.
import callMeMaybe from 'call-me-maybe';
interface FetchOptions {
delay?: number;
shouldError?: boolean;
}
/**
* Simulates an asynchronous data fetch that can be consumed via callback or Promise.
*/
function fetchData(id: string, options?: FetchOptions, callback?: (err: Error | null, data?: string) => void): Promise<string> | void {
// callMeMaybe expects the callback as the last argument.
// The second argument is an async function that receives resolve/reject for the Promise path.
return callMeMaybe(callback, async (resolve, reject) => {
try {
const delay = options?.delay ?? 100;
await new Promise(res => setTimeout(res, delay)); // Simulate network delay
if (options?.shouldError || id === 'error') {
throw new Error(`Failed to fetch data for ID: ${id}`);
}
const data = `Successfully fetched data for ID: ${id} (delayed by ${delay}ms)`;
resolve(data);
} catch (error: any) {
reject(error);
}
});
}
// --- Usage Examples ---
// 1. Promise-based consumption
console.log('--- Promise Usage ---');
fetchData('user-promise', { delay: 50 })
.then(data => console.log('Promise resolved:', data))
.catch(err => console.error('Promise rejected:', err.message));
fetchData('error-promise', { shouldError: true, delay: 20 })
.then(data => console.log('Promise resolved (unexpected):', data))
.catch(err => console.error('Promise rejected:', err.message));
// 2. Callback-based consumption
console.log('\n--- Callback Usage ---');
fetchData('user-callback', { delay: 70 }, (err, data) => {
if (err) {
console.error('Callback error:', err.message);
return;
}
console.log('Callback success:', data);
});
fetchData('error-callback', { shouldError: true, delay: 30 }, (err, data) => {
if (err) {
console.error('Callback error:', err.message);
return;
}
console.log('Callback success (unexpected):', data);
});
// 3. Illustrating the return type (for environments where no callback is provided)
console.log('\n--- Mixed Usage (implicitly Promise) ---');
const resultWithoutCallback = fetchData('implicit-promise', { delay: 10 });
if (resultWithoutCallback instanceof Promise) {
resultWithoutCallback
.then(data => console.log('Implicit Promise resolved:', data))
.catch(err => console.error('Implicit Promise rejected:', err.message));
} else {
// This branch is only hit if a callback was provided and handled internally.
console.log('Function returned void (callback handled it).');
}
Errors
Common errors & fixes
TypeError: callMeMaybe is not a function
This error typically occurs when attempting to import `callMeMaybe` as a named export (`import { callMeMaybe } from 'call-me-maybe';`) or incorrectly destructuring in CommonJS (`const { callMeMaybe } = require('call-me-maybe');`). The package uses a default export.
fixFor ESM, use `import callMeMaybe from 'call-me-maybe';`. For CommonJS, use `const callMeMaybe = require('call-me-maybe');`. ReferenceError: global is not defined
This error was a known bug in `call-me-maybe` versions prior to `1.0.2` when used in specific CommonJS environments that did not properly define or polyfill the `global` object.
fixUpgrade your `call-me-maybe` package to version `1.0.2` or newer. If this is not possible, ensure your CJS environment explicitly defines `global` if it's expected.
Audit
Dependencies
No dependency data recorded yet.