hoek
Advanced tools
Comparing version 4.2.0 to 5.0.0
@@ -73,3 +73,3 @@ 'use strict'; | ||
(descriptor.get || | ||
descriptor.set)) { | ||
descriptor.set)) { | ||
@@ -92,3 +92,3 @@ Object.defineProperty(newObj, key, descriptor); | ||
exports.merge = function (target, source, isNullOverride /* = true */, isMergeArrays /* = true */) { | ||
/*eslint-enable */ | ||
/*eslint-enable */ | ||
@@ -472,3 +472,2 @@ exports.assert(target && typeof target === 'object', 'Invalid target value: must be an object'); | ||
exports.assert(arguments.length >= 2, 'Insufficient arguments'); | ||
exports.assert(typeof ref === 'string' || typeof ref === 'object', 'Reference must be string or an object'); | ||
@@ -680,3 +679,3 @@ exports.assert(values.length, 'Values array cannot be empty'); | ||
const capture = {}; | ||
Error.captureStackTrace(capture, this); // arguments.callee is not supported in strict mode so we use this and slice the trace of this off the result | ||
Error.captureStackTrace(capture, this); | ||
const stack = capture.stack; | ||
@@ -718,3 +717,3 @@ | ||
exports.assert = function (condition /*, msg1, msg2, msg3 */) { | ||
exports.assert = function (condition, ...args) { | ||
@@ -725,18 +724,13 @@ if (condition) { | ||
if (arguments.length === 2 && arguments[1] instanceof Error) { | ||
throw arguments[1]; | ||
if (args.length === 1 && args[0] instanceof Error) { | ||
throw args[0]; | ||
} | ||
let msgs = []; | ||
for (let i = 1; i < arguments.length; ++i) { | ||
if (arguments[i] !== '') { | ||
msgs.push(arguments[i]); // Avoids Array.slice arguments leak, allowing for V8 optimizations | ||
} | ||
} | ||
const msgs = args | ||
.filter((arg) => arg !== '') | ||
.map((arg) => { | ||
msgs = msgs.map((msg) => { | ||
return typeof arg === 'string' ? arg : arg instanceof Error ? arg.message : exports.stringify(arg); | ||
}); | ||
return typeof msg === 'string' ? msg : msg instanceof Error ? msg.message : exports.stringify(msg); | ||
}); | ||
throw new Error(msgs.join(' ') || 'Unknown error'); | ||
@@ -746,21 +740,2 @@ }; | ||
exports.Timer = function () { | ||
this.ts = 0; | ||
this.reset(); | ||
}; | ||
exports.Timer.prototype.reset = function () { | ||
this.ts = Date.now(); | ||
}; | ||
exports.Timer.prototype.elapsed = function () { | ||
return Date.now() - this.ts; | ||
}; | ||
exports.Bench = function () { | ||
@@ -853,2 +828,3 @@ | ||
exports.escapeJson = function (string) { | ||
@@ -859,15 +835,3 @@ | ||
exports.nextTick = function (callback) { | ||
return function () { | ||
const args = arguments; | ||
process.nextTick(() => { | ||
callback.apply(null, args); | ||
}); | ||
}; | ||
}; | ||
exports.once = function (method) { | ||
@@ -880,7 +844,7 @@ | ||
let once = false; | ||
const wrapped = function () { | ||
const wrapped = function (...args) { | ||
if (!once) { | ||
once = true; | ||
method.apply(null, arguments); | ||
method.apply(null, args); | ||
} | ||
@@ -890,3 +854,2 @@ }; | ||
wrapped._hoekOnce = true; | ||
return wrapped; | ||
@@ -964,6 +927,6 @@ }; | ||
exports.stringify = function () { | ||
exports.stringify = function (...args) { | ||
try { | ||
return JSON.stringify.apply(null, arguments); | ||
return JSON.stringify.apply(null, args); | ||
} | ||
@@ -987,1 +950,13 @@ catch (err) { | ||
}; | ||
exports.wait = function (timeout) { | ||
return new Promise((resolve) => setTimeout(resolve, timeout)); | ||
}; | ||
exports.block = function () { | ||
return new Promise(exports.ignore); | ||
}; |
{ | ||
"name": "hoek", | ||
"description": "General purpose node utilities", | ||
"version": "4.2.0", | ||
"version": "5.0.0", | ||
"repository": "git://github.com/hapijs/hoek", | ||
@@ -11,8 +11,8 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=8.0.0" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"code": "4.x.x", | ||
"lab": "13.x.x" | ||
"code": "5.x.x", | ||
"lab": "14.x.x" | ||
}, | ||
@@ -19,0 +19,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
30902
791