mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 07:50:37 +01:00
feat: hooks can now return promise or call callbacks
* hooks can now return promise or call callbacks, either way works * cleanups * moar cleanups and fix callback 1st null arg * rm unnessesary spread
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
if (typeof module === 'object' && module.exports) {
|
||||
var winston = require('winston');
|
||||
|
||||
|
||||
module.exports = factory(require('xregexp'));
|
||||
module.exports = factory(require('xregexp'), winston);
|
||||
module.exports.walk = function (dir, done) {
|
||||
// DEPRECATED
|
||||
var file = require('../../src/file');
|
||||
@@ -14,7 +13,7 @@
|
||||
};
|
||||
|
||||
process.profile = function (operation, start) {
|
||||
console.log('%s took %d milliseconds', operation, process.elapsedTimeSince(start));
|
||||
winston.log('%s took %d milliseconds', operation, process.elapsedTimeSince(start));
|
||||
};
|
||||
|
||||
process.elapsedTimeSince = function (start) {
|
||||
@@ -22,9 +21,10 @@
|
||||
return (diff[0] * 1e3) + (diff[1] / 1e6);
|
||||
};
|
||||
} else {
|
||||
window.utils = factory(window.XRegExp);
|
||||
window.utils = factory(window.XRegExp, console);
|
||||
}
|
||||
}(function (XRegExp) {
|
||||
// eslint-disable-next-line
|
||||
}(function (XRegExp, console) {
|
||||
var freeze = Object.freeze || function (obj) { return obj; };
|
||||
|
||||
// add default escape function for escaping HTML entities
|
||||
@@ -469,6 +469,11 @@
|
||||
return utils.extensionMimeTypeMap[extension] || '*';
|
||||
},
|
||||
|
||||
isPromise: function (object) {
|
||||
// https://stackoverflow.com/questions/27746304/how-do-i-tell-if-an-object-is-a-promise#comment97339131_27746324
|
||||
return object && typeof object.then === 'function';
|
||||
},
|
||||
|
||||
isRelativeUrl: function (url) {
|
||||
var firstChar = String(url || '').charAt(0);
|
||||
return (firstChar === '.' || firstChar === '/');
|
||||
|
||||
Reference in New Issue
Block a user