UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

1 lines 1.13 kB
{"version":3,"file":"throttledWarn.cjs","names":["lastMessage: string | undefined"],"sources":["../../src/lib/throttledWarn.ts"],"sourcesContent":["const THROTTLE_THRESHOLD_MS = 5000\n\nlet lastMessage: string | undefined\nlet lastCalledAt = 0\n\n/**\n * Logs a warning. If the message is identical the immediate previous logged\n * message and that message was logged within 5 seconds of the current call, the\n * log is ignored. This throttle behavior prevents identical messages from\n * flooding the console.\n *\n * @param message - A message to log.\n * @param config - Configuration for the log.\n */\nexport const throttledWarn = (message: string): void => {\n\tif (\n\t\tmessage === lastMessage &&\n\t\tDate.now() - lastCalledAt < THROTTLE_THRESHOLD_MS\n\t) {\n\t\tlastCalledAt = Date.now()\n\n\t\treturn\n\t}\n\n\tlastCalledAt = Date.now()\n\tlastMessage = message\n\n\tconsole.warn(message)\n}\n"],"mappings":";;AAAA,MAAM,wBAAwB;AAE9B,IAAIA;AACJ,IAAI,eAAe;;;;;;;;;;AAWnB,MAAa,iBAAiB,YAA0B;AACvD,KACC,YAAY,eACZ,KAAK,KAAK,GAAG,eAAe,uBAC3B;AACD,iBAAe,KAAK,KAAK;AAEzB;;AAGD,gBAAe,KAAK,KAAK;AACzB,eAAc;AAEd,SAAQ,KAAK,QAAQ"}