rebootify
Version:
A Faster and lightweight alertnative to nodemon to monitor your Node Application
31 lines (24 loc) • 870 B
JavaScript
const constant = require('../lib/constant');
const fs = require('fs');
const path = require('path');
// Function to validate if the JavaScript file exists
exports.isValidJS = (fileName) => {
const resolvedPath = path.resolve(fileName.endsWith(constant.JS_EXT) ? fileName : fileName + constant.JS_EXT);
return fs.existsSync(resolvedPath);
};
// Debounce function to limit the frequency of function calls
exports.debounce = (func, delay) => {
console.log('Debounce function triggered');
if (typeof func !== 'function') {
throw new TypeError('Expected function as the first argument');
}
let debounceTimer;
return function() {
let context = this;
let args = arguments;
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
func.apply(context, args);
}, delay);
}
}