Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_isValidKey(key) {
// const rightType = Array.isArray(key) || isString(key)
// return rightType && key.length > 0
return isFunction(key[Symbol.iterator])
}
function makeAsync(callback) {
if (!util.isFunction(callback)) {
return callback;
}
return function asyncCallback() {
if (asyncCallback.immediately) {
// The API already returned, we can invoke the callback immediately.
callback.apply(null, arguments);
} else {
var args = arguments;
process.nextTick(function() {
callback.apply(null, args);
});
}
};
}
export const requestToCacheKey = (req, hashStrategy) => {
const {
method,
originalUrl,
query: originQuery,
route,
uid = null //Custom rule
} = req;
const query = { ...originQuery };
delete query.flush;
if (hashStrategy && !util.isFunction(hashStrategy)) {
throw new RuntimeException(`View cache hash strategy must be a function for ${originalUrl}`);
}
if (!route) {
throw new RuntimeException(`View cache middleware require route for ${originalUrl}`);
}
if (method.toLowerCase() !== 'get') {
throw new RuntimeException(`View cache middleware only support GET method of http request for ${originalUrl}`);
}
const { host = 'unknown' } = req.headers;
const [urlPath = ''] = originalUrl.split('?');
const key = [method, `/${host}`, urlPath].join('').replace(/:/g, '_').toLowerCase();
const strategy = hashStrategy || defaultHashStrategy;
const hash = crypto
.createHash('md5')
.update(JSON
.stringify(strategy({
Writable.prototype.write = function(chunk, encoding, cb) {
var state = this._writableState;
var ret = false;
if (util.isFunction(encoding)) {
cb = encoding;
encoding = null;
}
if (util.isBuffer(chunk))
encoding = 'buffer';
else if (!encoding)
encoding = state.defaultEncoding;
if (!util.isFunction(cb))
cb = function() {};
if (state.ended)
writeAfterEnd(this, state, cb);
else if (validChunk(this, state, chunk, cb)) {
state.pendingcb++;
function afterCallback(err, buffer) {
for (var i = 0; i < rxLength; i++) {
rxBuffer[i] = buffer[i];
}
util.isFunction(callback) && callback.call(self, err);
}
EventEmitter.listenerCount = function(emitter, type) {
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
else if (util.isFunction(emitter._events[type]))
ret = 1;
else
ret = emitter._events[type].length;
return ret;
};
dirList.forEach((fileName) => {
if (filter && util.isArray(filter) && filter.indexOf(fileName) >= 0) return;
let curPath = filePath + (filePath.substr(-1) === '/' ? '' : '/') + fileName;
let file = fs.statSync(curPath);
if (file.isFile()) {
let data = callback && util.isFunction(callback) && callback(curPath, filePath, fileName);
res.push(data || { path: curPath, name: fileName });
} else if (file.isDirectory()) {
res = res.concat(walk(curPath, filter, callback));
}
});
return res;
exports.watch = function(task, watchFiles) {
if(util.isFunction(watchFiles)) {
return watchFiles
}
else {
let patterns = (
(watchFiles ? (util.isArray(watchFiles) ? watchFiles : [watchFiles]) : []).map(x => x.toString())
)
return (filename) => {
for(let i=0; i
function replacer(key, value) {
if (util.isUndefined(value)) {
return '' + value;
}
if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
return value.toString();
}
if (util.isFunction(value) || util.isRegExp(value)) {
return value.toString();
}
return value;
}
function onclose() {
if (didOnEnd) return;
didOnEnd = true;
if (util.isFunction(dest.destroy)) dest.destroy();
}