UNPKG

timeandreturn

Version:

Get the elapsed time of a block of code and return the result of that block of code.

21 lines 777 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function formatBlockTime(block, elapsedTime) { return `"${formatFunctionDefinition(50, block.toString())}" ran for ${elapsedTime / 1000} seconds`; } exports.formatBlockTime = formatBlockTime; function formatFunctionDefinition(maxLength, functionDefinition) { let oneLineDefinition = functionDefinition.toString() // Strip line breaks and tabs .replace(/\r?\n|\r|\t/g, ' ') // Squash spaces .replace(/ +/g, ' '); // Slice and append ... if too long if (oneLineDefinition.length > maxLength) { return oneLineDefinition.slice(0, maxLength - 4) + ' ...'; } else { return oneLineDefinition; } } //# sourceMappingURL=format.js.map