@botonic/plugin-contentful
Version:
Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet
105 lines • 3.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Measure = exports.Profiler = exports.isBrowser = void 0;
const node_performance_measurer_1 = require("./measurer/node-performance-measurer");
const web_performance_measurer_1 = require("./measurer/web-performance-measurer");
const isBrowser = () => {
// @ts-ignore
return typeof IS_BROWSER !== 'undefined'
? // eslint-disable-next-line no-undef
// @ts-ignore
IS_BROWSER
: typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
!window.process;
};
exports.isBrowser = isBrowser;
class Profiler {
/**
* disables any profiling logic
*/
static isEnabled() {
return Profiler.performanceMeasurer.isEnabled();
}
/**
* disables any profiling logic
*/
static disable() {
Profiler.performanceMeasurer.disable();
}
/**
* enables profiling logic
*/
static enable() {
Profiler.performanceMeasurer.enable();
}
/**
* get a pretty summary of your profiling
*/
static getSummaryAll() {
return Profiler.performanceMeasurer.stringSummaryAll();
}
/**
* get a pretty summary 1 profiling
*/
static getSummary(name) {
return Profiler.performanceMeasurer.stringSummary(name);
}
static getCallCount(name) {
return Profiler.performanceMeasurer.callCount(name);
}
/**
* clear all measurements
*/
static clear() {
return Profiler.performanceMeasurer.clear();
}
/**
* annotation for a typescript class member
* @constructor
*/
static Profile(customName) {
return function (_target, _propertyKey, descriptor) {
const f = descriptor.value;
const newF = Profiler.profiledFunction(f, customName);
// @ts-ignore
descriptor.value = function (...args) {
return newF.apply(this, args);
};
return descriptor;
};
}
/**
* creates a profiled function
*/
// eslint-disable-next-line @typescript-eslint/ban-types
static profiledFunction(f, customName) {
const name = customName || f.name;
// @ts-ignore
return function (...args) {
const m = new Measure(name);
// @ts-ignore
const res = f.apply(this, args);
m.end();
return res;
};
}
}
exports.Profiler = Profiler;
Profiler.performanceMeasurer = (0, exports.isBrowser)()
? new web_performance_measurer_1.WebPerformanceMeasurer()
: new node_performance_measurer_1.NodePerformanceMeasurer();
class Measure {
constructor(name) {
this.name = (name || '<NO_NAME>').substr(0, 40);
this.uuid = this.name + String(Measure.lastUuid++);
Profiler.performanceMeasurer.start(this.uuid);
}
end(passthrough) {
Profiler.performanceMeasurer.end(this.uuid, this.name);
return passthrough;
}
}
exports.Measure = Measure;
Measure.lastUuid = 0;
//# sourceMappingURL=profiler.js.map