32 lines
3.9 KiB
JavaScript
32 lines
3.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const callsite_record_1 = require("callsite-record");
|
|
const raw_command_callsite_record_1 = require("./raw-command-callsite-record");
|
|
function renderCallsiteSync(callsite, options) {
|
|
if (!callsite)
|
|
return '';
|
|
// NOTE: for raw API callsites
|
|
if (typeof callsite === 'string')
|
|
return callsite;
|
|
if (callsite.prerendered) {
|
|
const renderer = options && options.renderer;
|
|
if (renderer === callsite_record_1.renderers.html || renderer === raw_command_callsite_record_1.renderers.html)
|
|
return callsite.html;
|
|
if (renderer === callsite_record_1.renderers.noColor || renderer === raw_command_callsite_record_1.renderers.noColor)
|
|
return callsite.noColor;
|
|
return callsite.default || '';
|
|
}
|
|
if (!callsite.renderSync)
|
|
return '';
|
|
try {
|
|
// NOTE: Callsite will throw during rendering if it can't find a target file for the specified function or method:
|
|
// https://github.com/inikulin/callsite-record/issues/2#issuecomment-223263941
|
|
return callsite.renderSync(options);
|
|
}
|
|
catch (err) {
|
|
return '';
|
|
}
|
|
}
|
|
exports.default = renderCallsiteSync;
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVuZGVyLWNhbGxzaXRlLXN5bmMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvcmVuZGVyLWNhbGxzaXRlLXN5bmMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxxREFBK0Q7QUFDL0QsK0VBQThFO0FBRzlFLFNBQXdCLGtCQUFrQixDQUFFLFFBQVEsRUFBRSxPQUFPO0lBQ3pELElBQUksQ0FBQyxRQUFRO1FBQ1QsT0FBTyxFQUFFLENBQUM7SUFFZCw4QkFBOEI7SUFDOUIsSUFBSSxPQUFPLFFBQVEsS0FBSyxRQUFRO1FBQzVCLE9BQU8sUUFBUSxDQUFDO0lB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