@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
25 lines (24 loc) • 790 B
JavaScript
//#region src/lib/throttledWarn.ts
const THROTTLE_THRESHOLD_MS = 5e3;
let lastMessage;
let lastCalledAt = 0;
/**
* Logs a warning. If the message is identical the immediate previous logged message and that
* message was logged within 5 seconds of the current call, the log is ignored. This throttle
* behavior prevents identical messages from flooding the console.
*
* @param message - A message to log.
* @param config - Configuration for the log.
*/
const throttledWarn = (message) => {
if (message === lastMessage && Date.now() - lastCalledAt < THROTTLE_THRESHOLD_MS) {
lastCalledAt = Date.now();
return;
}
lastCalledAt = Date.now();
lastMessage = message;
console.warn(message);
};
//#endregion
exports.throttledWarn = throttledWarn;
//# sourceMappingURL=throttledWarn.cjs.map