@monterosa/sdk-util 0.18.2 → 0.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/error.d.ts +4 -0
- package/dist/index.cjs.js +18 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +18 -1
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +18 -1
- package/dist/index.esm5.js.map +1 -1
- package/package.json +2 -2
package/dist/error.d.ts
CHANGED
|
@@ -35,4 +35,8 @@ declare type ErrorMap<ErrorCode extends string> = {
|
|
|
35
35
|
* @internal
|
|
36
36
|
*/
|
|
37
37
|
export declare function createError<ErrorCode extends string>(code: ErrorCode, messages: ErrorMap<ErrorCode>, ...params: any[]): MonterosaError;
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare function getErrorMessage(err: unknown): string;
|
|
38
42
|
export {};
|
package/dist/index.cjs.js
CHANGED
|
@@ -352,6 +352,23 @@ function createError(code, messages) {
|
|
|
352
352
|
}
|
|
353
353
|
var message = messages[code].apply(messages, params);
|
|
354
354
|
return new MonterosaError(code, message);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* @internal
|
|
358
|
+
*/
|
|
359
|
+
function getErrorMessage(err) {
|
|
360
|
+
if (err instanceof Error) {
|
|
361
|
+
return err.message;
|
|
362
|
+
}
|
|
363
|
+
if (typeof err === 'string') {
|
|
364
|
+
return err;
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
return JSON.stringify(err);
|
|
368
|
+
}
|
|
369
|
+
catch (_a) {
|
|
370
|
+
return 'Unknown error';
|
|
371
|
+
}
|
|
355
372
|
}
|
|
356
373
|
|
|
357
374
|
/**
|
|
@@ -915,6 +932,7 @@ exports.checkAvailability = checkAvailability;
|
|
|
915
932
|
exports.clear = clear;
|
|
916
933
|
exports.createError = createError;
|
|
917
934
|
exports.delay = delay;
|
|
935
|
+
exports.getErrorMessage = getErrorMessage;
|
|
918
936
|
exports.getGlobal = getGlobal;
|
|
919
937
|
exports.getItem = getItem;
|
|
920
938
|
exports.getKey = getKey;
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/emitter.ts","../src/delay.ts","../src/memoize-promise.ts","../src/global.ts","../src/storage.ts","../src/error.ts","../src/throttle.ts","../src/time.ts","../src/calculate-percentage.ts"],"sourcesContent":["/**\n * @license\n * subscribe.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport mitt, { Emitter as MittEmitter, Handler as MittHandler } from 'mitt';\n\ntype Handler = (...args: any[]) => void;\n\nexport class Emitter {\n private readonly emitter: MittEmitter<Record<string, any>>;\n private readonly handlers = new Map<Handler, MittHandler>();\n\n constructor() {\n this.emitter = mitt<Record<string, any>>();\n }\n\n on(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n\n off(event: string, handler?: Handler): void {\n if (handler === undefined) {\n this.emitter.off(event);\n return;\n }\n\n const mittHandler = this.handlers.get(handler);\n\n if (mittHandler) {\n this.emitter.off(event, mittHandler);\n this.handlers.delete(handler);\n }\n }\n\n emit(event: string, ...args: any[]): void {\n this.emitter.emit(event, args);\n }\n\n once(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n\n this.off(event, handler);\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n}\n\n/**\n * The unsubscribe function. When it is called, the previously set event\n * listener is removed. It is returned by every observer functions\n *\n * @example\n * ```typescript\n * const unsubscribe: Unsubscribe = onElementPublished((element) => {\n * console.log('Element published', element);\n * });\n *\n * unsubscribe();\n * ```\n */\nexport interface Unsubscribe {\n (): void;\n}\n\n/**\n * @internal\n */\nexport interface Subscribe {\n (\n emitter: Emitter,\n event: string,\n callback: (...args: any[]) => void,\n ): Unsubscribe;\n}\n\n/**\n * @internal\n */\nexport const subscribe: Subscribe = (emitter, event, callback) => {\n emitter.on(event, callback);\n\n return () => emitter.off(event, callback);\n};\n","/**\n * @license\n * delay.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * @internal\n */\nexport const delay = async (timeout: number): Promise<void> => {\n await new Promise((resolve) => setTimeout(resolve, timeout));\n};\n","/**\n * @license\n * memoize-promise.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-09-20\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Creates a function that memoizes the result of `func`.\n *\n * @internal\n *\n * @param func - A function that returns a promise. The results of its work will be memoized.\n * @param resolver - A function that determines the cache key.\n * @param config - A configuration object with the following optional properties:\n * `clearOnResolve` - Deletes memoized result upon promise resolve. Defaults to `false`.\n * `clearOnReject` - Deletes memoized result upon promise reject. Defaults to `true`.\n */\n\nexport const memoizePromise = <T>(\n func: (...args: any[]) => Promise<T>,\n resolver: (...args: any[]) => any,\n config: {\n clearOnResolve?: boolean;\n clearOnReject?: boolean;\n } = {},\n): ((...args: any[]) => Promise<T>) => {\n const clearOnResolve = config.clearOnResolve ?? false;\n const clearOnReject = config.clearOnReject ?? true;\n\n const cache: Map<any, Promise<T>> = new Map();\n\n const memoized = (...args: any[]) => {\n const key = resolver(...args);\n\n if (cache.has(key)) {\n return cache.get(key) as Promise<T>;\n }\n\n const promise = func(...args);\n\n cache.set(key, promise);\n\n promise.then(() => clearOnResolve && cache.delete(key));\n promise.catch(() => clearOnReject && cache.delete(key));\n\n return promise;\n };\n\n memoized.cache = cache;\n\n return memoized;\n};\n","/**\n * @license\n * global.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint no-restricted-globals: \"off\" */\n\n/**\n * Global object polyfill.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\n *\n * @internal\n *\n * @returns typeof globalThis\n */\nexport function getGlobal(): typeof globalThis {\n if (typeof self !== 'undefined') {\n return self;\n }\n\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n\n if (typeof window !== 'undefined') {\n return window;\n }\n\n if (typeof global !== 'undefined') {\n return global;\n }\n\n throw new Error('Unable to locate global object.');\n}\n","/**\n * @license\n * storage.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getGlobal } from './global';\n\nconst PREFIX = 'monterosa_sdk_';\n\nconst BAIT = 'bait';\n\nconst globals = getGlobal();\n\n/**\n * @internal\n */\nexport const getKey = (name: string) => `${PREFIX}${name}`;\n\n/**\n * @internal\n */\nexport function getItem(key: string): string | null {\n return globals.localStorage.getItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function setItem(key: string, value: string): void {\n return globals.localStorage.setItem(getKey(key), value);\n}\n\n/**\n * @internal\n */\nexport function removeItem(key: string): void {\n return globals.localStorage.removeItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function clear(): void {\n return globals.localStorage.clear();\n}\n\n/**\n * Checks locastorage availability.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\n * and Paul Irish gists: https://gist.github.com/paulirish/5558557\n *\n * @internal\n *\n * @returns boolean\n */\nexport function checkAvailability() {\n try {\n setItem(BAIT, BAIT);\n getItem(BAIT);\n removeItem(BAIT);\n\n return true;\n } catch (e) {\n return false;\n }\n}\n","/**\n * @license\n * error.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-31\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint max-classes-per-file: [\"error\", 2] */\n\n/**\n * MonterosaError extends the standard JavaScript `Error` object. It has\n * an error code so that user can identify the error. Also it has it's own\n * specific `name` \"MonterosaError\"\n */\nexport class MonterosaError extends Error {\n /**\n * The name property represents a name for the type of error.\n */\n readonly name = 'MonterosaError';\n\n /**\n * Error code string\n */\n readonly code: string;\n\n /**\n * @param code - Error code string\n * @param message - A descriptive message for the error\n */\n constructor(code: string, message: string) {\n super(message);\n\n this.code = code;\n\n // Fix For ES5\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, MonterosaError.prototype);\n }\n}\n\ntype ErrorMap<ErrorCode extends string> = {\n readonly [K in ErrorCode]: (...rest: any[]) => string;\n};\n\n/**\n * @internal\n */\nexport function createError<ErrorCode extends string>(\n code: ErrorCode,\n messages: ErrorMap<ErrorCode>,\n ...params: any[]\n) {\n const message = messages[code](...params);\n\n return new MonterosaError(code, message);\n}\n","/**\n * @license\n * throttle.ts\n * util\n *\n * Created by Josep Rodriguez <josep.rodriguez@monterosa.co.uk> on 2022-07-13\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint-disable */\n// @ts-nocheck\n\n/**\n * lodash (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright jQuery Foundation and other contributors <https://jquery.org/>\n * Released under MIT license <https://lodash.com/license>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n */\n\n/** Used as the `TypeError` message for \"Functions\" methods. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/** Used as references for various `Number` constants. */\nvar NAN = 0 / 0;\n\n/** `Object#toString` result references. */\nvar symbolTag = '[object Symbol]';\n\n/** Used to match leading and trailing whitespace. */\nvar reTrim = /^\\s+|\\s+$/g;\n\n/** Used to detect bad signed hexadecimal string values. */\nvar reIsBadHex = /^[-+]0x[0-9a-f]+$/i;\n\n/** Used to detect binary string values. */\nvar reIsBinary = /^0b[01]+$/i;\n\n/** Used to detect octal string values. */\nvar reIsOctal = /^0o[0-7]+$/i;\n\n/** Built-in method references without a dependency on `root`. */\nvar freeParseInt = parseInt;\n\n/** Detect free variable `global` from Node.js. */\nvar freeGlobal =\n typeof global == 'object' && global && global.Object === Object && global;\n\n/** Detect free variable `self`. */\nvar freeSelf =\n typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar objectToString = objectProto.toString;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max,\n nativeMin = Math.min;\n\n/**\n * Gets the timestamp of the number of milliseconds that have elapsed since\n * the Unix epoch (1 January 1970 00:00:00 UTC).\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Date\n * @returns {number} Returns the timestamp.\n * @example\n *\n * _.defer(function(stamp) {\n * console.log(_.now() - stamp);\n * }, _.now());\n * // => Logs the number of milliseconds it took for the deferred invocation.\n */\nvar now = function () {\n return root.Date.now();\n};\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel\n * delayed `func` invocations and a `flush` method to immediately invoke them.\n * Provide `options` to indicate whether `func` should be invoked on the\n * leading and/or trailing edge of the `wait` timeout. The `func` is invoked\n * with the last arguments provided to the debounced function. Subsequent\n * calls to the debounced function return the result of the last `func`\n * invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.debounce` and `_.throttle`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0] The number of milliseconds to delay.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * jQuery(window).on('resize', _.debounce(calculateLayout, 150));\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * jQuery(element).on('click', _.debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }));\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });\n * var source = new EventSource('/stream');\n * jQuery(source).on('message', debounced);\n *\n * // Cancel the trailing debounced invocation.\n * jQuery(window).on('popstate', debounced.cancel);\n */\nfunction debounce(func, wait, options) {\n var lastArgs,\n lastThis,\n maxWait,\n result,\n timerId,\n lastCallTime,\n lastInvokeTime = 0,\n leading = false,\n maxing = false,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n wait = toNumber(wait) || 0;\n if (isObject(options)) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing\n ? nativeMax(toNumber(options.maxWait) || 0, wait)\n : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time) {\n var args = lastArgs,\n thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n result = func.apply(thisArg, args);\n return result;\n }\n\n function leadingEdge(time) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime,\n result = wait - timeSinceLastCall;\n\n return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;\n }\n\n function shouldInvoke(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n lastCallTime === undefined ||\n timeSinceLastCall >= wait ||\n timeSinceLastCall < 0 ||\n (maxing && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired() {\n var time = now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(now());\n }\n\n function debounced() {\n var time = now(),\n isInvoking = shouldInvoke(time);\n\n lastArgs = arguments;\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n return debounced;\n}\n\n/**\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.throttle` and `_.debounce`.\n *\n * @internal\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to throttle.\n * @param {number} [wait=0] The number of milliseconds to throttle invocations to.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=true]\n * Specify invoking on the leading edge of the timeout.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new throttled function.\n * @example\n *\n * // Avoid excessively updating the position while scrolling.\n * jQuery(window).on('scroll', _.throttle(updatePosition, 100));\n *\n * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.\n * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });\n * jQuery(element).on('click', throttled);\n *\n * // Cancel the trailing throttled invocation.\n * jQuery(window).on('popstate', throttled.cancel);\n */\nexport function throttle(func, wait, options) {\n var leading = true,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n if (isObject(options)) {\n leading = 'leading' in options ? !!options.leading : leading;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n return debounce(func, wait, {\n leading: leading,\n maxWait: wait,\n trailing: trailing,\n });\n}\n\n/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return !!value && (type == 'object' || type == 'function');\n}\n\n/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value) {\n return !!value && typeof value == 'object';\n}\n\n/**\n * Checks if `value` is classified as a `Symbol` primitive or object.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.\n * @example\n *\n * _.isSymbol(Symbol.iterator);\n * // => true\n *\n * _.isSymbol('abc');\n * // => false\n */\nfunction isSymbol(value) {\n return (\n typeof value == 'symbol' ||\n (isObjectLike(value) && objectToString.call(value) == symbolTag)\n );\n}\n\n/**\n * Converts `value` to a number.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to process.\n * @returns {number} Returns the number.\n * @example\n *\n * _.toNumber(3.2);\n * // => 3.2\n *\n * _.toNumber(Number.MIN_VALUE);\n * // => 5e-324\n *\n * _.toNumber(Infinity);\n * // => Infinity\n *\n * _.toNumber('3.2');\n * // => 3.2\n */\nfunction toNumber(value) {\n if (typeof value == 'number') {\n return value;\n }\n if (isSymbol(value)) {\n return NAN;\n }\n if (isObject(value)) {\n var other = typeof value.valueOf == 'function' ? value.valueOf() : value;\n value = isObject(other) ? other + '' : other;\n }\n if (typeof value != 'string') {\n return value === 0 ? value : +value;\n }\n value = value.replace(reTrim, '');\n var isBinary = reIsBinary.test(value);\n return isBinary || reIsOctal.test(value)\n ? freeParseInt(value.slice(2), isBinary ? 2 : 8)\n : reIsBadHex.test(value)\n ? NAN\n : +value;\n}\n","/**\n * @license\n * time.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2025-03-24\n * Copyright © 2025 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Time service that maintains current timestamp.\n *\n * Timestamp is set either:\n * - initially with the local timestamp `Date.now()` when there is yet\n * communication with Enmasse server yet\n * - later with the accurate low-latency timestamp that comes in Enmasse\n * message handshake\n *\n * Thereafter the timestamp is maintained by `tick()` function and can be\n * retrieved in two ways:\n *\n * - subscribing to an event using `onTick(callback: () => void)` function\n * that pushes notification every second with the current timestamp\n * - or pulling data directly using function `now()`\n */\n\nimport { Emitter, subscribe, Unsubscribe } from './emitter';\n\nconst emitter = new Emitter();\n\nlet serverTimestamp: number = 0;\nlet lastTickTimestamp: number = 0;\nlet tickTimeoutId: ReturnType<typeof setTimeout>;\n\n/**\n * Returns local timestamp in seconds\n */\nfunction getCurrentTimestamp(): number {\n return Date.now() / 1000;\n}\n\n/**\n * Normalizes the timestamp to reduce fluctuations due to `setTimeout` delays.\n * Ensures the fractional part is around 0.5 to avoid skipping a second.\n *\n * Returns half-second timestamp. It is used to be sure that timestamp will not\n * fluctuate more than in 1 second after each tick due to longer delays.\n * https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified\n *\n * For example if the initial timestamp has a fractional part 0.9999 then with\n * the setTimeout (tick) longer than specified we might jump over a one second.\n * Lets imaging setTimeout took 1.0002 second, then our timestamp will be 2.0001.\n * Thats why we are trying to keep fractional part in the middle of the second.\n */\nfunction getMiddleTimestamp(timestamp: number): number {\n return Math.floor(timestamp) + 0.5;\n}\n\n/**\n * Calculates the delay for the next tick to keep timestamps stable.\n */\nfunction calculateNextTickDelay(): number {\n const expectedNextTick = getMiddleTimestamp(serverTimestamp) + 1;\n\n return (expectedNextTick - serverTimestamp) * 1000;\n}\n\n/**\n * Main function that maintains current timestamp\n */\nexport function tick() {\n clearTimeout(tickTimeoutId);\n\n const currentTimestamp = getCurrentTimestamp();\n const timeSinceLastTick = currentTimestamp - lastTickTimestamp;\n\n serverTimestamp += timeSinceLastTick;\n lastTickTimestamp = currentTimestamp;\n\n tickTimeoutId = setTimeout(tick, calculateNextTickDelay());\n\n emitter.emit('tick', serverTimestamp);\n}\n\n/**\n * @internal\n *\n * Sets or updates current timestamp\n *\n * @param timestamp - Current timestamp in seconds\n */\nexport function setTimestamp(timestamp: number): void {\n lastTickTimestamp = getCurrentTimestamp();\n serverTimestamp = getMiddleTimestamp(timestamp);\n}\n\n/**\n * Returns current timestamp that is preserved by `tick()` function\n *\n * @returns Current timestamp in seconds\n */\nexport function now(): number {\n return Math.floor(serverTimestamp);\n}\n\n/**\n * Subscribes listener to the timestamp increment\n *\n * @param callback - A handler that executes when the timestamp is incremented\n *\n * @returns A function that unsubscribes the listener\n */\nexport function onTick(callback: (timestamp: number) => void): Unsubscribe {\n return subscribe(emitter, 'tick', callback);\n}\n\n// Initially timestamp is set based on a local date\n// Later on it can be overriden outside at any moment\n// in our case it is populated with the server timestamp\n// which comes from Enmasse session handshake message\nsetTimestamp(getCurrentTimestamp());\n\n// Kicking in timestamp maintaining\ntick();\n","/**\n * @license\n * @monterosa/sdk-util\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Calculate percentage of each value in the array.\n *\n * It uses Hamilton's method, also known as the method of largest remainder.\n * It is a system used for distributing vote percentages among different\n * options (like candidates or choices) based on their vote counts. It ensures\n * that each option receives at least its lower quota of percentage points, and\n * any remaining percentage points are allocated to those with the largest\n * fractional remainders. This method is used in the US Electoral College.\n *\n * @param values - Array of number values to calculate percentage for\n * @returns Array of percentages, where the sum of the array is 100%\n */\nexport const calculatePercentage = (values: number[]): number[] => {\n // Calculate sum of all votes\n const sum = values.reduce((memo, value) => memo + value, 0);\n\n // create array of hashes\n const results = values.map((value, idx) => {\n const percentage = (100 * value) / sum || 0;\n\n return {\n idx,\n votes: value,\n percentage: Math.floor(percentage),\n remainder: percentage % 1,\n };\n });\n\n // Sum them all up - this can't be higher than 100%\n let total = results.reduce((memo, { percentage }) => memo + percentage, 0);\n\n total = total || 100;\n\n // Calculate number of percent that we are missing\n const delta = 100 - total;\n\n // Order all options by remainder\n results.sort((a, b) => {\n if (a.remainder !== b.remainder) {\n return b.remainder - a.remainder;\n }\n\n return a.idx - b.idx;\n });\n\n // Distribute delta to highest remainder options\n for (let i = 0; i < delta; i++) {\n results[i].percentage += 1;\n }\n\n // Restore options order\n results.sort((a, b) => a.idx - b.idx);\n\n return results.map((item) => item.percentage);\n};\n"],"names":["mitt","now"],"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;IAmBE;QAFiB,aAAQ,GAAG,IAAI,G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OAAO,CAAC,MAAM,CAAC,UAAC,IAAI,EAAE,EAAc;YAAZ,UAAU,gBAAA;QAAO,OAAA,IAAI,GAAG,UAAU;KAAA,EAAE,CAAC,CAAC,CAAC;IAE3E,KAAK,GAAG,KAAK,IAAI,GAAG,CAAC;;IAGrB,IAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;;IAG1B,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,EAAE;YAC/B,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;SAClC;QAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;KACtB,CAAC,CAAC;;IAGH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;QAC9B,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC;KAC5B;;IAGD,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAA,CAAC,CAAC;IAEtC,OAAO,OAAO,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,UAAU,GAAA,CAAC,CAAC;AAChD;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/emitter.ts","../src/delay.ts","../src/memoize-promise.ts","../src/global.ts","../src/storage.ts","../src/error.ts","../src/throttle.ts","../src/time.ts","../src/calculate-percentage.ts"],"sourcesContent":["/**\n * @license\n * subscribe.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport mitt, { Emitter as MittEmitter, Handler as MittHandler } from 'mitt';\n\ntype Handler = (...args: any[]) => void;\n\nexport class Emitter {\n private readonly emitter: MittEmitter<Record<string, any>>;\n private readonly handlers = new Map<Handler, MittHandler>();\n\n constructor() {\n this.emitter = mitt<Record<string, any>>();\n }\n\n on(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n\n off(event: string, handler?: Handler): void {\n if (handler === undefined) {\n this.emitter.off(event);\n return;\n }\n\n const mittHandler = this.handlers.get(handler);\n\n if (mittHandler) {\n this.emitter.off(event, mittHandler);\n this.handlers.delete(handler);\n }\n }\n\n emit(event: string, ...args: any[]): void {\n this.emitter.emit(event, args);\n }\n\n once(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n\n this.off(event, handler);\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n}\n\n/**\n * The unsubscribe function. When it is called, the previously set event\n * listener is removed. It is returned by every observer functions\n *\n * @example\n * ```typescript\n * const unsubscribe: Unsubscribe = onElementPublished((element) => {\n * console.log('Element published', element);\n * });\n *\n * unsubscribe();\n * ```\n */\nexport interface Unsubscribe {\n (): void;\n}\n\n/**\n * @internal\n */\nexport interface Subscribe {\n (\n emitter: Emitter,\n event: string,\n callback: (...args: any[]) => void,\n ): Unsubscribe;\n}\n\n/**\n * @internal\n */\nexport const subscribe: Subscribe = (emitter, event, callback) => {\n emitter.on(event, callback);\n\n return () => emitter.off(event, callback);\n};\n","/**\n * @license\n * delay.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * @internal\n */\nexport const delay = async (timeout: number): Promise<void> => {\n await new Promise((resolve) => setTimeout(resolve, timeout));\n};\n","/**\n * @license\n * memoize-promise.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-09-20\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Creates a function that memoizes the result of `func`.\n *\n * @internal\n *\n * @param func - A function that returns a promise. The results of its work will be memoized.\n * @param resolver - A function that determines the cache key.\n * @param config - A configuration object with the following optional properties:\n * `clearOnResolve` - Deletes memoized result upon promise resolve. Defaults to `false`.\n * `clearOnReject` - Deletes memoized result upon promise reject. Defaults to `true`.\n */\n\nexport const memoizePromise = <T>(\n func: (...args: any[]) => Promise<T>,\n resolver: (...args: any[]) => any,\n config: {\n clearOnResolve?: boolean;\n clearOnReject?: boolean;\n } = {},\n): ((...args: any[]) => Promise<T>) => {\n const clearOnResolve = config.clearOnResolve ?? false;\n const clearOnReject = config.clearOnReject ?? true;\n\n const cache: Map<any, Promise<T>> = new Map();\n\n const memoized = (...args: any[]) => {\n const key = resolver(...args);\n\n if (cache.has(key)) {\n return cache.get(key) as Promise<T>;\n }\n\n const promise = func(...args);\n\n cache.set(key, promise);\n\n promise.then(() => clearOnResolve && cache.delete(key));\n promise.catch(() => clearOnReject && cache.delete(key));\n\n return promise;\n };\n\n memoized.cache = cache;\n\n return memoized;\n};\n","/**\n * @license\n * global.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint no-restricted-globals: \"off\" */\n\n/**\n * Global object polyfill.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\n *\n * @internal\n *\n * @returns typeof globalThis\n */\nexport function getGlobal(): typeof globalThis {\n if (typeof self !== 'undefined') {\n return self;\n }\n\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n\n if (typeof window !== 'undefined') {\n return window;\n }\n\n if (typeof global !== 'undefined') {\n return global;\n }\n\n throw new Error('Unable to locate global object.');\n}\n","/**\n * @license\n * storage.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getGlobal } from './global';\n\nconst PREFIX = 'monterosa_sdk_';\n\nconst BAIT = 'bait';\n\nconst globals = getGlobal();\n\n/**\n * @internal\n */\nexport const getKey = (name: string) => `${PREFIX}${name}`;\n\n/**\n * @internal\n */\nexport function getItem(key: string): string | null {\n return globals.localStorage.getItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function setItem(key: string, value: string): void {\n return globals.localStorage.setItem(getKey(key), value);\n}\n\n/**\n * @internal\n */\nexport function removeItem(key: string): void {\n return globals.localStorage.removeItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function clear(): void {\n return globals.localStorage.clear();\n}\n\n/**\n * Checks locastorage availability.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\n * and Paul Irish gists: https://gist.github.com/paulirish/5558557\n *\n * @internal\n *\n * @returns boolean\n */\nexport function checkAvailability() {\n try {\n setItem(BAIT, BAIT);\n getItem(BAIT);\n removeItem(BAIT);\n\n return true;\n } catch (e) {\n return false;\n }\n}\n","/**\n * @license\n * error.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-31\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint max-classes-per-file: [\"error\", 2] */\n\n/**\n * MonterosaError extends the standard JavaScript `Error` object. It has\n * an error code so that user can identify the error. Also it has it's own\n * specific `name` \"MonterosaError\"\n */\nexport class MonterosaError extends Error {\n /**\n * The name property represents a name for the type of error.\n */\n readonly name = 'MonterosaError';\n\n /**\n * Error code string\n */\n readonly code: string;\n\n /**\n * @param code - Error code string\n * @param message - A descriptive message for the error\n */\n constructor(code: string, message: string) {\n super(message);\n\n this.code = code;\n\n // Fix For ES5\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, MonterosaError.prototype);\n }\n}\n\ntype ErrorMap<ErrorCode extends string> = {\n readonly [K in ErrorCode]: (...rest: any[]) => string;\n};\n\n/**\n * @internal\n */\nexport function createError<ErrorCode extends string>(\n code: ErrorCode,\n messages: ErrorMap<ErrorCode>,\n ...params: any[]\n) {\n const message = messages[code](...params);\n\n return new MonterosaError(code, message);\n}\n\n/**\n * @internal\n */\nexport function getErrorMessage(err: unknown): string {\n if (err instanceof Error) {\n return err.message;\n }\n\n if (typeof err === 'string') {\n return err;\n }\n\n try {\n return JSON.stringify(err);\n } catch {\n return 'Unknown error';\n }\n}\n","/**\n * @license\n * throttle.ts\n * util\n *\n * Created by Josep Rodriguez <josep.rodriguez@monterosa.co.uk> on 2022-07-13\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint-disable */\n// @ts-nocheck\n\n/**\n * lodash (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright jQuery Foundation and other contributors <https://jquery.org/>\n * Released under MIT license <https://lodash.com/license>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n */\n\n/** Used as the `TypeError` message for \"Functions\" methods. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/** Used as references for various `Number` constants. */\nvar NAN = 0 / 0;\n\n/** `Object#toString` result references. */\nvar symbolTag = '[object Symbol]';\n\n/** Used to match leading and trailing whitespace. */\nvar reTrim = /^\\s+|\\s+$/g;\n\n/** Used to detect bad signed hexadecimal string values. */\nvar reIsBadHex = /^[-+]0x[0-9a-f]+$/i;\n\n/** Used to detect binary string values. */\nvar reIsBinary = /^0b[01]+$/i;\n\n/** Used to detect octal string values. */\nvar reIsOctal = /^0o[0-7]+$/i;\n\n/** Built-in method references without a dependency on `root`. */\nvar freeParseInt = parseInt;\n\n/** Detect free variable `global` from Node.js. */\nvar freeGlobal =\n typeof global == 'object' && global && global.Object === Object && global;\n\n/** Detect free variable `self`. */\nvar freeSelf =\n typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar objectToString = objectProto.toString;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max,\n nativeMin = Math.min;\n\n/**\n * Gets the timestamp of the number of milliseconds that have elapsed since\n * the Unix epoch (1 January 1970 00:00:00 UTC).\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Date\n * @returns {number} Returns the timestamp.\n * @example\n *\n * _.defer(function(stamp) {\n * console.log(_.now() - stamp);\n * }, _.now());\n * // => Logs the number of milliseconds it took for the deferred invocation.\n */\nvar now = function () {\n return root.Date.now();\n};\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel\n * delayed `func` invocations and a `flush` method to immediately invoke them.\n * Provide `options` to indicate whether `func` should be invoked on the\n * leading and/or trailing edge of the `wait` timeout. The `func` is invoked\n * with the last arguments provided to the debounced function. Subsequent\n * calls to the debounced function return the result of the last `func`\n * invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.debounce` and `_.throttle`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0] The number of milliseconds to delay.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * jQuery(window).on('resize', _.debounce(calculateLayout, 150));\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * jQuery(element).on('click', _.debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }));\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });\n * var source = new EventSource('/stream');\n * jQuery(source).on('message', debounced);\n *\n * // Cancel the trailing debounced invocation.\n * jQuery(window).on('popstate', debounced.cancel);\n */\nfunction debounce(func, wait, options) {\n var lastArgs,\n lastThis,\n maxWait,\n result,\n timerId,\n lastCallTime,\n lastInvokeTime = 0,\n leading = false,\n maxing = false,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n wait = toNumber(wait) || 0;\n if (isObject(options)) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing\n ? nativeMax(toNumber(options.maxWait) || 0, wait)\n : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time) {\n var args = lastArgs,\n thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n result = func.apply(thisArg, args);\n return result;\n }\n\n function leadingEdge(time) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime,\n result = wait - timeSinceLastCall;\n\n return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;\n }\n\n function shouldInvoke(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n lastCallTime === undefined ||\n timeSinceLastCall >= wait ||\n timeSinceLastCall < 0 ||\n (maxing && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired() {\n var time = now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(now());\n }\n\n function debounced() {\n var time = now(),\n isInvoking = shouldInvoke(time);\n\n lastArgs = arguments;\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n return debounced;\n}\n\n/**\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.throttle` and `_.debounce`.\n *\n * @internal\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to throttle.\n * @param {number} [wait=0] The number of milliseconds to throttle invocations to.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=true]\n * Specify invoking on the leading edge of the timeout.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new throttled function.\n * @example\n *\n * // Avoid excessively updating the position while scrolling.\n * jQuery(window).on('scroll', _.throttle(updatePosition, 100));\n *\n * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.\n * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });\n * jQuery(element).on('click', throttled);\n *\n * // Cancel the trailing throttled invocation.\n * jQuery(window).on('popstate', throttled.cancel);\n */\nexport function throttle(func, wait, options) {\n var leading = true,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n if (isObject(options)) {\n leading = 'leading' in options ? !!options.leading : leading;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n return debounce(func, wait, {\n leading: leading,\n maxWait: wait,\n trailing: trailing,\n });\n}\n\n/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return !!value && (type == 'object' || type == 'function');\n}\n\n/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value) {\n return !!value && typeof value == 'object';\n}\n\n/**\n * Checks if `value` is classified as a `Symbol` primitive or object.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.\n * @example\n *\n * _.isSymbol(Symbol.iterator);\n * // => true\n *\n * _.isSymbol('abc');\n * // => false\n */\nfunction isSymbol(value) {\n return (\n typeof value == 'symbol' ||\n (isObjectLike(value) && objectToString.call(value) == symbolTag)\n );\n}\n\n/**\n * Converts `value` to a number.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to process.\n * @returns {number} Returns the number.\n * @example\n *\n * _.toNumber(3.2);\n * // => 3.2\n *\n * _.toNumber(Number.MIN_VALUE);\n * // => 5e-324\n *\n * _.toNumber(Infinity);\n * // => Infinity\n *\n * _.toNumber('3.2');\n * // => 3.2\n */\nfunction toNumber(value) {\n if (typeof value == 'number') {\n return value;\n }\n if (isSymbol(value)) {\n return NAN;\n }\n if (isObject(value)) {\n var other = typeof value.valueOf == 'function' ? value.valueOf() : value;\n value = isObject(other) ? other + '' : other;\n }\n if (typeof value != 'string') {\n return value === 0 ? value : +value;\n }\n value = value.replace(reTrim, '');\n var isBinary = reIsBinary.test(value);\n return isBinary || reIsOctal.test(value)\n ? freeParseInt(value.slice(2), isBinary ? 2 : 8)\n : reIsBadHex.test(value)\n ? NAN\n : +value;\n}\n","/**\n * @license\n * time.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2025-03-24\n * Copyright © 2025 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Time service that maintains current timestamp.\n *\n * Timestamp is set either:\n * - initially with the local timestamp `Date.now()` when there is yet\n * communication with Enmasse server yet\n * - later with the accurate low-latency timestamp that comes in Enmasse\n * message handshake\n *\n * Thereafter the timestamp is maintained by `tick()` function and can be\n * retrieved in two ways:\n *\n * - subscribing to an event using `onTick(callback: () => void)` function\n * that pushes notification every second with the current timestamp\n * - or pulling data directly using function `now()`\n */\n\nimport { Emitter, subscribe, Unsubscribe } from './emitter';\n\nconst emitter = new Emitter();\n\nlet serverTimestamp: number = 0;\nlet lastTickTimestamp: number = 0;\nlet tickTimeoutId: ReturnType<typeof setTimeout>;\n\n/**\n * Returns local timestamp in seconds\n */\nfunction getCurrentTimestamp(): number {\n return Date.now() / 1000;\n}\n\n/**\n * Normalizes the timestamp to reduce fluctuations due to `setTimeout` delays.\n * Ensures the fractional part is around 0.5 to avoid skipping a second.\n *\n * Returns half-second timestamp. It is used to be sure that timestamp will not\n * fluctuate more than in 1 second after each tick due to longer delays.\n * https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified\n *\n * For example if the initial timestamp has a fractional part 0.9999 then with\n * the setTimeout (tick) longer than specified we might jump over a one second.\n * Lets imaging setTimeout took 1.0002 second, then our timestamp will be 2.0001.\n * Thats why we are trying to keep fractional part in the middle of the second.\n */\nfunction getMiddleTimestamp(timestamp: number): number {\n return Math.floor(timestamp) + 0.5;\n}\n\n/**\n * Calculates the delay for the next tick to keep timestamps stable.\n */\nfunction calculateNextTickDelay(): number {\n const expectedNextTick = getMiddleTimestamp(serverTimestamp) + 1;\n\n return (expectedNextTick - serverTimestamp) * 1000;\n}\n\n/**\n * Main function that maintains current timestamp\n */\nexport function tick() {\n clearTimeout(tickTimeoutId);\n\n const currentTimestamp = getCurrentTimestamp();\n const timeSinceLastTick = currentTimestamp - lastTickTimestamp;\n\n serverTimestamp += timeSinceLastTick;\n lastTickTimestamp = currentTimestamp;\n\n tickTimeoutId = setTimeout(tick, calculateNextTickDelay());\n\n emitter.emit('tick', serverTimestamp);\n}\n\n/**\n * @internal\n *\n * Sets or updates current timestamp\n *\n * @param timestamp - Current timestamp in seconds\n */\nexport function setTimestamp(timestamp: number): void {\n lastTickTimestamp = getCurrentTimestamp();\n serverTimestamp = getMiddleTimestamp(timestamp);\n}\n\n/**\n * Returns current timestamp that is preserved by `tick()` function\n *\n * @returns Current timestamp in seconds\n */\nexport function now(): number {\n return Math.floor(serverTimestamp);\n}\n\n/**\n * Subscribes listener to the timestamp increment\n *\n * @param callback - A handler that executes when the timestamp is incremented\n *\n * @returns A function that unsubscribes the listener\n */\nexport function onTick(callback: (timestamp: number) => void): Unsubscribe {\n return subscribe(emitter, 'tick', callback);\n}\n\n// Initially timestamp is set based on a local date\n// Later on it can be overriden outside at any moment\n// in our case it is populated with the server timestamp\n// which comes from Enmasse session handshake message\nsetTimestamp(getCurrentTimestamp());\n\n// Kicking in timestamp maintaining\ntick();\n","/**\n * @license\n * @monterosa/sdk-util\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Calculate percentage of each value in the array.\n *\n * It uses Hamilton's method, also known as the method of largest remainder.\n * It is a system used for distributing vote percentages among different\n * options (like candidates or choices) based on their vote counts. It ensures\n * that each option receives at least its lower quota of percentage points, and\n * any remaining percentage points are allocated to those with the largest\n * fractional remainders. This method is used in the US Electoral College.\n *\n * @param values - Array of number values to calculate percentage for\n * @returns Array of percentages, where the sum of the array is 100%\n */\nexport const calculatePercentage = (values: number[]): number[] => {\n // Calculate sum of all votes\n const sum = values.reduce((memo, value) => memo + value, 0);\n\n // create array of hashes\n const results = values.map((value, idx) => {\n const percentage = (100 * value) / sum || 0;\n\n return {\n idx,\n votes: value,\n percentage: Math.floor(percentage),\n remainder: percentage % 1,\n };\n });\n\n // Sum them all up - this can't be higher than 100%\n let total = results.reduce((memo, { percentage }) => memo + percentage, 0);\n\n total = total || 100;\n\n // Calculate number of percent that we are missing\n const delta = 100 - total;\n\n // Order all options by remainder\n results.sort((a, b) => {\n if (a.remainder !== b.remainder) {\n return b.remainder - a.remainder;\n }\n\n return a.idx - b.idx;\n });\n\n // Distribute delta to highest remainder options\n for (let i = 0; i < delta; i++) {\n results[i].percentage += 1;\n }\n\n // Restore options order\n results.sort((a, b) => a.idx - b.idx);\n\n return results.map((item) => item.percentage);\n};\n"],"names":["mitt","now"],"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;IAmBE;QAFiB,aAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;QAG1D,IAAI,CAAC,OAAO,GAAGA,wBAAI,EAAuB,CAAC;KAC5C;IAED,oBAAE,GAAF,UAAG,KAAa,EAAE,OAAgB;QAAlC,iBASC;QARC,IAAM,WAAW,GAAgB,UAAC,IAAI;YACpC,OAAO,gBAAK,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG;SACnD,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW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AI,EAAE,EAAc;YAAZ,UAAU,gBAAA;QAAO,OAAA,IAAI,GAAG,UAAU;KAAA,EAAE,CAAC,CAAC,CAAC;IAE3E,KAAK,GAAG,KAAK,IAAI,GAAG,CAAC;;IAGrB,IAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;;IAG1B,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,EAAE;YAC/B,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;SAClC;QAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;KACtB,CAAC,CAAC;;IAGH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;QAC9B,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC;KAC5B;;IAGD,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAA,CAAC,CAAC;IAEtC,OAAO,OAAO,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,UAAU,GAAA,CAAC,CAAC;AAChD;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.esm2017.js
CHANGED
|
@@ -249,6 +249,23 @@ class MonterosaError extends Error {
|
|
|
249
249
|
function createError(code, messages, ...params) {
|
|
250
250
|
const message = messages[code](...params);
|
|
251
251
|
return new MonterosaError(code, message);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* @internal
|
|
255
|
+
*/
|
|
256
|
+
function getErrorMessage(err) {
|
|
257
|
+
if (err instanceof Error) {
|
|
258
|
+
return err.message;
|
|
259
|
+
}
|
|
260
|
+
if (typeof err === 'string') {
|
|
261
|
+
return err;
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
return JSON.stringify(err);
|
|
265
|
+
}
|
|
266
|
+
catch (_a) {
|
|
267
|
+
return 'Unknown error';
|
|
268
|
+
}
|
|
252
269
|
}
|
|
253
270
|
|
|
254
271
|
/**
|
|
@@ -802,5 +819,5 @@ const calculatePercentage = (values) => {
|
|
|
802
819
|
return results.map((item) => item.percentage);
|
|
803
820
|
};
|
|
804
821
|
|
|
805
|
-
export { Emitter, MonterosaError, calculatePercentage, checkAvailability, clear, createError, delay, getGlobal, getItem, getKey, memoizePromise, now, onTick, removeItem, setItem, setTimestamp, subscribe, throttle, tick };
|
|
822
|
+
export { Emitter, MonterosaError, calculatePercentage, checkAvailability, clear, createError, delay, getErrorMessage, getGlobal, getItem, getKey, memoizePromise, now, onTick, removeItem, setItem, setTimestamp, subscribe, throttle, tick };
|
|
806
823
|
//# sourceMappingURL=index.esm2017.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm2017.js","sources":["../src/emitter.ts","../src/delay.ts","../src/memoize-promise.ts","../src/global.ts","../src/storage.ts","../src/error.ts","../src/throttle.ts","../src/time.ts","../src/calculate-percentage.ts"],"sourcesContent":["/**\n * @license\n * subscribe.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport mitt, { Emitter as MittEmitter, Handler as MittHandler } from 'mitt';\n\ntype Handler = (...args: any[]) => void;\n\nexport class Emitter {\n private readonly emitter: MittEmitter<Record<string, any>>;\n private readonly handlers = new Map<Handler, MittHandler>();\n\n constructor() {\n this.emitter = mitt<Record<string, any>>();\n }\n\n on(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n\n off(event: string, handler?: Handler): void {\n if (handler === undefined) {\n this.emitter.off(event);\n return;\n }\n\n const mittHandler = this.handlers.get(handler);\n\n if (mittHandler) {\n this.emitter.off(event, mittHandler);\n this.handlers.delete(handler);\n }\n }\n\n emit(event: string, ...args: any[]): void {\n this.emitter.emit(event, args);\n }\n\n once(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n\n this.off(event, handler);\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n}\n\n/**\n * The unsubscribe function. When it is called, the previously set event\n * listener is removed. It is returned by every observer functions\n *\n * @example\n * ```typescript\n * const unsubscribe: Unsubscribe = onElementPublished((element) => {\n * console.log('Element published', element);\n * });\n *\n * unsubscribe();\n * ```\n */\nexport interface Unsubscribe {\n (): void;\n}\n\n/**\n * @internal\n */\nexport interface Subscribe {\n (\n emitter: Emitter,\n event: string,\n callback: (...args: any[]) => void,\n ): Unsubscribe;\n}\n\n/**\n * @internal\n */\nexport const subscribe: Subscribe = (emitter, event, callback) => {\n emitter.on(event, callback);\n\n return () => emitter.off(event, callback);\n};\n","/**\n * @license\n * delay.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * @internal\n */\nexport const delay = async (timeout: number): Promise<void> => {\n await new Promise((resolve) => setTimeout(resolve, timeout));\n};\n","/**\n * @license\n * memoize-promise.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-09-20\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Creates a function that memoizes the result of `func`.\n *\n * @internal\n *\n * @param func - A function that returns a promise. The results of its work will be memoized.\n * @param resolver - A function that determines the cache key.\n * @param config - A configuration object with the following optional properties:\n * `clearOnResolve` - Deletes memoized result upon promise resolve. Defaults to `false`.\n * `clearOnReject` - Deletes memoized result upon promise reject. Defaults to `true`.\n */\n\nexport const memoizePromise = <T>(\n func: (...args: any[]) => Promise<T>,\n resolver: (...args: any[]) => any,\n config: {\n clearOnResolve?: boolean;\n clearOnReject?: boolean;\n } = {},\n): ((...args: any[]) => Promise<T>) => {\n const clearOnResolve = config.clearOnResolve ?? false;\n const clearOnReject = config.clearOnReject ?? true;\n\n const cache: Map<any, Promise<T>> = new Map();\n\n const memoized = (...args: any[]) => {\n const key = resolver(...args);\n\n if (cache.has(key)) {\n return cache.get(key) as Promise<T>;\n }\n\n const promise = func(...args);\n\n cache.set(key, promise);\n\n promise.then(() => clearOnResolve && cache.delete(key));\n promise.catch(() => clearOnReject && cache.delete(key));\n\n return promise;\n };\n\n memoized.cache = cache;\n\n return memoized;\n};\n","/**\n * @license\n * global.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint no-restricted-globals: \"off\" */\n\n/**\n * Global object polyfill.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\n *\n * @internal\n *\n * @returns typeof globalThis\n */\nexport function getGlobal(): typeof globalThis {\n if (typeof self !== 'undefined') {\n return self;\n }\n\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n\n if (typeof window !== 'undefined') {\n return window;\n }\n\n if (typeof global !== 'undefined') {\n return global;\n }\n\n throw new Error('Unable to locate global object.');\n}\n","/**\n * @license\n * storage.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getGlobal } from './global';\n\nconst PREFIX = 'monterosa_sdk_';\n\nconst BAIT = 'bait';\n\nconst globals = getGlobal();\n\n/**\n * @internal\n */\nexport const getKey = (name: string) => `${PREFIX}${name}`;\n\n/**\n * @internal\n */\nexport function getItem(key: string): string | null {\n return globals.localStorage.getItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function setItem(key: string, value: string): void {\n return globals.localStorage.setItem(getKey(key), value);\n}\n\n/**\n * @internal\n */\nexport function removeItem(key: string): void {\n return globals.localStorage.removeItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function clear(): void {\n return globals.localStorage.clear();\n}\n\n/**\n * Checks locastorage availability.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\n * and Paul Irish gists: https://gist.github.com/paulirish/5558557\n *\n * @internal\n *\n * @returns boolean\n */\nexport function checkAvailability() {\n try {\n setItem(BAIT, BAIT);\n getItem(BAIT);\n removeItem(BAIT);\n\n return true;\n } catch (e) {\n return false;\n }\n}\n","/**\n * @license\n * error.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-31\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint max-classes-per-file: [\"error\", 2] */\n\n/**\n * MonterosaError extends the standard JavaScript `Error` object. It has\n * an error code so that user can identify the error. Also it has it's own\n * specific `name` \"MonterosaError\"\n */\nexport class MonterosaError extends Error {\n /**\n * The name property represents a name for the type of error.\n */\n readonly name = 'MonterosaError';\n\n /**\n * Error code string\n */\n readonly code: string;\n\n /**\n * @param code - Error code string\n * @param message - A descriptive message for the error\n */\n constructor(code: string, message: string) {\n super(message);\n\n this.code = code;\n\n // Fix For ES5\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, MonterosaError.prototype);\n }\n}\n\ntype ErrorMap<ErrorCode extends string> = {\n readonly [K in ErrorCode]: (...rest: any[]) => string;\n};\n\n/**\n * @internal\n */\nexport function createError<ErrorCode extends string>(\n code: ErrorCode,\n messages: ErrorMap<ErrorCode>,\n ...params: any[]\n) {\n const message = messages[code](...params);\n\n return new MonterosaError(code, message);\n}\n","/**\n * @license\n * throttle.ts\n * util\n *\n * Created by Josep Rodriguez <josep.rodriguez@monterosa.co.uk> on 2022-07-13\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint-disable */\n// @ts-nocheck\n\n/**\n * lodash (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright jQuery Foundation and other contributors <https://jquery.org/>\n * Released under MIT license <https://lodash.com/license>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n */\n\n/** Used as the `TypeError` message for \"Functions\" methods. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/** Used as references for various `Number` constants. */\nvar NAN = 0 / 0;\n\n/** `Object#toString` result references. */\nvar symbolTag = '[object Symbol]';\n\n/** Used to match leading and trailing whitespace. */\nvar reTrim = /^\\s+|\\s+$/g;\n\n/** Used to detect bad signed hexadecimal string values. */\nvar reIsBadHex = /^[-+]0x[0-9a-f]+$/i;\n\n/** Used to detect binary string values. */\nvar reIsBinary = /^0b[01]+$/i;\n\n/** Used to detect octal string values. */\nvar reIsOctal = /^0o[0-7]+$/i;\n\n/** Built-in method references without a dependency on `root`. */\nvar freeParseInt = parseInt;\n\n/** Detect free variable `global` from Node.js. */\nvar freeGlobal =\n typeof global == 'object' && global && global.Object === Object && global;\n\n/** Detect free variable `self`. */\nvar freeSelf =\n typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar objectToString = objectProto.toString;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max,\n nativeMin = Math.min;\n\n/**\n * Gets the timestamp of the number of milliseconds that have elapsed since\n * the Unix epoch (1 January 1970 00:00:00 UTC).\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Date\n * @returns {number} Returns the timestamp.\n * @example\n *\n * _.defer(function(stamp) {\n * console.log(_.now() - stamp);\n * }, _.now());\n * // => Logs the number of milliseconds it took for the deferred invocation.\n */\nvar now = function () {\n return root.Date.now();\n};\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel\n * delayed `func` invocations and a `flush` method to immediately invoke them.\n * Provide `options` to indicate whether `func` should be invoked on the\n * leading and/or trailing edge of the `wait` timeout. The `func` is invoked\n * with the last arguments provided to the debounced function. Subsequent\n * calls to the debounced function return the result of the last `func`\n * invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.debounce` and `_.throttle`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0] The number of milliseconds to delay.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * jQuery(window).on('resize', _.debounce(calculateLayout, 150));\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * jQuery(element).on('click', _.debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }));\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });\n * var source = new EventSource('/stream');\n * jQuery(source).on('message', debounced);\n *\n * // Cancel the trailing debounced invocation.\n * jQuery(window).on('popstate', debounced.cancel);\n */\nfunction debounce(func, wait, options) {\n var lastArgs,\n lastThis,\n maxWait,\n result,\n timerId,\n lastCallTime,\n lastInvokeTime = 0,\n leading = false,\n maxing = false,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n wait = toNumber(wait) || 0;\n if (isObject(options)) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing\n ? nativeMax(toNumber(options.maxWait) || 0, wait)\n : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time) {\n var args = lastArgs,\n thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n result = func.apply(thisArg, args);\n return result;\n }\n\n function leadingEdge(time) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime,\n result = wait - timeSinceLastCall;\n\n return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;\n }\n\n function shouldInvoke(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n lastCallTime === undefined ||\n timeSinceLastCall >= wait ||\n timeSinceLastCall < 0 ||\n (maxing && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired() {\n var time = now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(now());\n }\n\n function debounced() {\n var time = now(),\n isInvoking = shouldInvoke(time);\n\n lastArgs = arguments;\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n return debounced;\n}\n\n/**\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.throttle` and `_.debounce`.\n *\n * @internal\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to throttle.\n * @param {number} [wait=0] The number of milliseconds to throttle invocations to.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=true]\n * Specify invoking on the leading edge of the timeout.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new throttled function.\n * @example\n *\n * // Avoid excessively updating the position while scrolling.\n * jQuery(window).on('scroll', _.throttle(updatePosition, 100));\n *\n * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.\n * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });\n * jQuery(element).on('click', throttled);\n *\n * // Cancel the trailing throttled invocation.\n * jQuery(window).on('popstate', throttled.cancel);\n */\nexport function throttle(func, wait, options) {\n var leading = true,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n if (isObject(options)) {\n leading = 'leading' in options ? !!options.leading : leading;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n return debounce(func, wait, {\n leading: leading,\n maxWait: wait,\n trailing: trailing,\n });\n}\n\n/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return !!value && (type == 'object' || type == 'function');\n}\n\n/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value) {\n return !!value && typeof value == 'object';\n}\n\n/**\n * Checks if `value` is classified as a `Symbol` primitive or object.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.\n * @example\n *\n * _.isSymbol(Symbol.iterator);\n * // => true\n *\n * _.isSymbol('abc');\n * // => false\n */\nfunction isSymbol(value) {\n return (\n typeof value == 'symbol' ||\n (isObjectLike(value) && objectToString.call(value) == symbolTag)\n );\n}\n\n/**\n * Converts `value` to a number.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to process.\n * @returns {number} Returns the number.\n * @example\n *\n * _.toNumber(3.2);\n * // => 3.2\n *\n * _.toNumber(Number.MIN_VALUE);\n * // => 5e-324\n *\n * _.toNumber(Infinity);\n * // => Infinity\n *\n * _.toNumber('3.2');\n * // => 3.2\n */\nfunction toNumber(value) {\n if (typeof value == 'number') {\n return value;\n }\n if (isSymbol(value)) {\n return NAN;\n }\n if (isObject(value)) {\n var other = typeof value.valueOf == 'function' ? value.valueOf() : value;\n value = isObject(other) ? other + '' : other;\n }\n if (typeof value != 'string') {\n return value === 0 ? value : +value;\n }\n value = value.replace(reTrim, '');\n var isBinary = reIsBinary.test(value);\n return isBinary || reIsOctal.test(value)\n ? freeParseInt(value.slice(2), isBinary ? 2 : 8)\n : reIsBadHex.test(value)\n ? NAN\n : +value;\n}\n","/**\n * @license\n * time.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2025-03-24\n * Copyright © 2025 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Time service that maintains current timestamp.\n *\n * Timestamp is set either:\n * - initially with the local timestamp `Date.now()` when there is yet\n * communication with Enmasse server yet\n * - later with the accurate low-latency timestamp that comes in Enmasse\n * message handshake\n *\n * Thereafter the timestamp is maintained by `tick()` function and can be\n * retrieved in two ways:\n *\n * - subscribing to an event using `onTick(callback: () => void)` function\n * that pushes notification every second with the current timestamp\n * - or pulling data directly using function `now()`\n */\n\nimport { Emitter, subscribe, Unsubscribe } from './emitter';\n\nconst emitter = new Emitter();\n\nlet serverTimestamp: number = 0;\nlet lastTickTimestamp: number = 0;\nlet tickTimeoutId: ReturnType<typeof setTimeout>;\n\n/**\n * Returns local timestamp in seconds\n */\nfunction getCurrentTimestamp(): number {\n return Date.now() / 1000;\n}\n\n/**\n * Normalizes the timestamp to reduce fluctuations due to `setTimeout` delays.\n * Ensures the fractional part is around 0.5 to avoid skipping a second.\n *\n * Returns half-second timestamp. It is used to be sure that timestamp will not\n * fluctuate more than in 1 second after each tick due to longer delays.\n * https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified\n *\n * For example if the initial timestamp has a fractional part 0.9999 then with\n * the setTimeout (tick) longer than specified we might jump over a one second.\n * Lets imaging setTimeout took 1.0002 second, then our timestamp will be 2.0001.\n * Thats why we are trying to keep fractional part in the middle of the second.\n */\nfunction getMiddleTimestamp(timestamp: number): number {\n return Math.floor(timestamp) + 0.5;\n}\n\n/**\n * Calculates the delay for the next tick to keep timestamps stable.\n */\nfunction calculateNextTickDelay(): number {\n const expectedNextTick = getMiddleTimestamp(serverTimestamp) + 1;\n\n return (expectedNextTick - serverTimestamp) * 1000;\n}\n\n/**\n * Main function that maintains current timestamp\n */\nexport function tick() {\n clearTimeout(tickTimeoutId);\n\n const currentTimestamp = getCurrentTimestamp();\n const timeSinceLastTick = currentTimestamp - lastTickTimestamp;\n\n serverTimestamp += timeSinceLastTick;\n lastTickTimestamp = currentTimestamp;\n\n tickTimeoutId = setTimeout(tick, calculateNextTickDelay());\n\n emitter.emit('tick', serverTimestamp);\n}\n\n/**\n * @internal\n *\n * Sets or updates current timestamp\n *\n * @param timestamp - Current timestamp in seconds\n */\nexport function setTimestamp(timestamp: number): void {\n lastTickTimestamp = getCurrentTimestamp();\n serverTimestamp = getMiddleTimestamp(timestamp);\n}\n\n/**\n * Returns current timestamp that is preserved by `tick()` function\n *\n * @returns Current timestamp in seconds\n */\nexport function now(): number {\n return Math.floor(serverTimestamp);\n}\n\n/**\n * Subscribes listener to the timestamp increment\n *\n * @param callback - A handler that executes when the timestamp is incremented\n *\n * @returns A function that unsubscribes the listener\n */\nexport function onTick(callback: (timestamp: number) => void): Unsubscribe {\n return subscribe(emitter, 'tick', callback);\n}\n\n// Initially timestamp is set based on a local date\n// Later on it can be overriden outside at any moment\n// in our case it is populated with the server timestamp\n// which comes from Enmasse session handshake message\nsetTimestamp(getCurrentTimestamp());\n\n// Kicking in timestamp maintaining\ntick();\n","/**\n * @license\n * @monterosa/sdk-util\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Calculate percentage of each value in the array.\n *\n * It uses Hamilton's method, also known as the method of largest remainder.\n * It is a system used for distributing vote percentages among different\n * options (like candidates or choices) based on their vote counts. It ensures\n * that each option receives at least its lower quota of percentage points, and\n * any remaining percentage points are allocated to those with the largest\n * fractional remainders. This method is used in the US Electoral College.\n *\n * @param values - Array of number values to calculate percentage for\n * @returns Array of percentages, where the sum of the array is 100%\n */\nexport const calculatePercentage = (values: number[]): number[] => {\n // Calculate sum of all votes\n const sum = values.reduce((memo, value) => memo + value, 0);\n\n // create array of hashes\n const results = values.map((value, idx) => {\n const percentage = (100 * value) / sum || 0;\n\n return {\n idx,\n votes: value,\n percentage: Math.floor(percentage),\n remainder: percentage % 1,\n };\n });\n\n // Sum them all up - this can't be higher than 100%\n let total = results.reduce((memo, { percentage }) => memo + percentage, 0);\n\n total = total || 100;\n\n // Calculate number of percent that we are missing\n const delta = 100 - total;\n\n // Order all options by remainder\n results.sort((a, b) => {\n if (a.remainder !== b.remainder) {\n return b.remainder - a.remainder;\n }\n\n return a.idx - b.idx;\n });\n\n // Distribute delta to highest remainder options\n for (let i = 0; i < delta; i++) {\n results[i].percentage += 1;\n }\n\n // Restore options order\n results.sort((a, b) => a.idx - b.idx);\n\n return results.map((item) => item.percentage);\n};\n"],"names":["now"],"mappings":";;AAAA;;;;;;;;;;MAea,OAAO;IAIlB;QAFiB,aAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;QAG1D,IAAI,CAAC,OAAO,GAAG,IAAI,EAAuB,CAAC;KAC5C;IAED,EAAE,CAAC,KAAa,EAAE,OAAgB;QAChC,MAAM,WAAW,GAAgB,CAAC,IAAI;YACpC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACnD,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAEpC,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KACvC;IAED,GAAG,CAAC,KAAa,EAAE,OAAiB;QAClC,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACxB,OAAO;SACR;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE/C,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAA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,EAAE,UAAU,EAAE,KAAK,IAAI,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;IAE3E,KAAK,GAAG,KAAK,IAAI,GAAG,CAAC;;IAGrB,MAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;;IAG1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,EAAE;YAC/B,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;SAClC;QAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;KACtB,CAAC,CAAC;;IAGH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;QAC9B,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC;KAC5B;;IAGD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAEtC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;AAChD;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm2017.js","sources":["../src/emitter.ts","../src/delay.ts","../src/memoize-promise.ts","../src/global.ts","../src/storage.ts","../src/error.ts","../src/throttle.ts","../src/time.ts","../src/calculate-percentage.ts"],"sourcesContent":["/**\n * @license\n * subscribe.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport mitt, { Emitter as MittEmitter, Handler as MittHandler } from 'mitt';\n\ntype Handler = (...args: any[]) => void;\n\nexport class Emitter {\n private readonly emitter: MittEmitter<Record<string, any>>;\n private readonly handlers = new Map<Handler, MittHandler>();\n\n constructor() {\n this.emitter = mitt<Record<string, any>>();\n }\n\n on(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n\n off(event: string, handler?: Handler): void {\n if (handler === undefined) {\n this.emitter.off(event);\n return;\n }\n\n const mittHandler = this.handlers.get(handler);\n\n if (mittHandler) {\n this.emitter.off(event, mittHandler);\n this.handlers.delete(handler);\n }\n }\n\n emit(event: string, ...args: any[]): void {\n this.emitter.emit(event, args);\n }\n\n once(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n\n this.off(event, handler);\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n}\n\n/**\n * The unsubscribe function. When it is called, the previously set event\n * listener is removed. It is returned by every observer functions\n *\n * @example\n * ```typescript\n * const unsubscribe: Unsubscribe = onElementPublished((element) => {\n * console.log('Element published', element);\n * });\n *\n * unsubscribe();\n * ```\n */\nexport interface Unsubscribe {\n (): void;\n}\n\n/**\n * @internal\n */\nexport interface Subscribe {\n (\n emitter: Emitter,\n event: string,\n callback: (...args: any[]) => void,\n ): Unsubscribe;\n}\n\n/**\n * @internal\n */\nexport const subscribe: Subscribe = (emitter, event, callback) => {\n emitter.on(event, callback);\n\n return () => emitter.off(event, callback);\n};\n","/**\n * @license\n * delay.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * @internal\n */\nexport const delay = async (timeout: number): Promise<void> => {\n await new Promise((resolve) => setTimeout(resolve, timeout));\n};\n","/**\n * @license\n * memoize-promise.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-09-20\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Creates a function that memoizes the result of `func`.\n *\n * @internal\n *\n * @param func - A function that returns a promise. The results of its work will be memoized.\n * @param resolver - A function that determines the cache key.\n * @param config - A configuration object with the following optional properties:\n * `clearOnResolve` - Deletes memoized result upon promise resolve. Defaults to `false`.\n * `clearOnReject` - Deletes memoized result upon promise reject. Defaults to `true`.\n */\n\nexport const memoizePromise = <T>(\n func: (...args: any[]) => Promise<T>,\n resolver: (...args: any[]) => any,\n config: {\n clearOnResolve?: boolean;\n clearOnReject?: boolean;\n } = {},\n): ((...args: any[]) => Promise<T>) => {\n const clearOnResolve = config.clearOnResolve ?? false;\n const clearOnReject = config.clearOnReject ?? true;\n\n const cache: Map<any, Promise<T>> = new Map();\n\n const memoized = (...args: any[]) => {\n const key = resolver(...args);\n\n if (cache.has(key)) {\n return cache.get(key) as Promise<T>;\n }\n\n const promise = func(...args);\n\n cache.set(key, promise);\n\n promise.then(() => clearOnResolve && cache.delete(key));\n promise.catch(() => clearOnReject && cache.delete(key));\n\n return promise;\n };\n\n memoized.cache = cache;\n\n return memoized;\n};\n","/**\n * @license\n * global.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint no-restricted-globals: \"off\" */\n\n/**\n * Global object polyfill.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\n *\n * @internal\n *\n * @returns typeof globalThis\n */\nexport function getGlobal(): typeof globalThis {\n if (typeof self !== 'undefined') {\n return self;\n }\n\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n\n if (typeof window !== 'undefined') {\n return window;\n }\n\n if (typeof global !== 'undefined') {\n return global;\n }\n\n throw new Error('Unable to locate global object.');\n}\n","/**\n * @license\n * storage.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getGlobal } from './global';\n\nconst PREFIX = 'monterosa_sdk_';\n\nconst BAIT = 'bait';\n\nconst globals = getGlobal();\n\n/**\n * @internal\n */\nexport const getKey = (name: string) => `${PREFIX}${name}`;\n\n/**\n * @internal\n */\nexport function getItem(key: string): string | null {\n return globals.localStorage.getItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function setItem(key: string, value: string): void {\n return globals.localStorage.setItem(getKey(key), value);\n}\n\n/**\n * @internal\n */\nexport function removeItem(key: string): void {\n return globals.localStorage.removeItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function clear(): void {\n return globals.localStorage.clear();\n}\n\n/**\n * Checks locastorage availability.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\n * and Paul Irish gists: https://gist.github.com/paulirish/5558557\n *\n * @internal\n *\n * @returns boolean\n */\nexport function checkAvailability() {\n try {\n setItem(BAIT, BAIT);\n getItem(BAIT);\n removeItem(BAIT);\n\n return true;\n } catch (e) {\n return false;\n }\n}\n","/**\n * @license\n * error.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-31\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint max-classes-per-file: [\"error\", 2] */\n\n/**\n * MonterosaError extends the standard JavaScript `Error` object. It has\n * an error code so that user can identify the error. Also it has it's own\n * specific `name` \"MonterosaError\"\n */\nexport class MonterosaError extends Error {\n /**\n * The name property represents a name for the type of error.\n */\n readonly name = 'MonterosaError';\n\n /**\n * Error code string\n */\n readonly code: string;\n\n /**\n * @param code - Error code string\n * @param message - A descriptive message for the error\n */\n constructor(code: string, message: string) {\n super(message);\n\n this.code = code;\n\n // Fix For ES5\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, MonterosaError.prototype);\n }\n}\n\ntype ErrorMap<ErrorCode extends string> = {\n readonly [K in ErrorCode]: (...rest: any[]) => string;\n};\n\n/**\n * @internal\n */\nexport function createError<ErrorCode extends string>(\n code: ErrorCode,\n messages: ErrorMap<ErrorCode>,\n ...params: any[]\n) {\n const message = messages[code](...params);\n\n return new MonterosaError(code, message);\n}\n\n/**\n * @internal\n */\nexport function getErrorMessage(err: unknown): string {\n if (err instanceof Error) {\n return err.message;\n }\n\n if (typeof err === 'string') {\n return err;\n }\n\n try {\n return JSON.stringify(err);\n } catch {\n return 'Unknown error';\n }\n}\n","/**\n * @license\n * throttle.ts\n * util\n *\n * Created by Josep Rodriguez <josep.rodriguez@monterosa.co.uk> on 2022-07-13\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint-disable */\n// @ts-nocheck\n\n/**\n * lodash (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright jQuery Foundation and other contributors <https://jquery.org/>\n * Released under MIT license <https://lodash.com/license>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n */\n\n/** Used as the `TypeError` message for \"Functions\" methods. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/** Used as references for various `Number` constants. */\nvar NAN = 0 / 0;\n\n/** `Object#toString` result references. */\nvar symbolTag = '[object Symbol]';\n\n/** Used to match leading and trailing whitespace. */\nvar reTrim = /^\\s+|\\s+$/g;\n\n/** Used to detect bad signed hexadecimal string values. */\nvar reIsBadHex = /^[-+]0x[0-9a-f]+$/i;\n\n/** Used to detect binary string values. */\nvar reIsBinary = /^0b[01]+$/i;\n\n/** Used to detect octal string values. */\nvar reIsOctal = /^0o[0-7]+$/i;\n\n/** Built-in method references without a dependency on `root`. */\nvar freeParseInt = parseInt;\n\n/** Detect free variable `global` from Node.js. */\nvar freeGlobal =\n typeof global == 'object' && global && global.Object === Object && global;\n\n/** Detect free variable `self`. */\nvar freeSelf =\n typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar objectToString = objectProto.toString;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max,\n nativeMin = Math.min;\n\n/**\n * Gets the timestamp of the number of milliseconds that have elapsed since\n * the Unix epoch (1 January 1970 00:00:00 UTC).\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Date\n * @returns {number} Returns the timestamp.\n * @example\n *\n * _.defer(function(stamp) {\n * console.log(_.now() - stamp);\n * }, _.now());\n * // => Logs the number of milliseconds it took for the deferred invocation.\n */\nvar now = function () {\n return root.Date.now();\n};\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel\n * delayed `func` invocations and a `flush` method to immediately invoke them.\n * Provide `options` to indicate whether `func` should be invoked on the\n * leading and/or trailing edge of the `wait` timeout. The `func` is invoked\n * with the last arguments provided to the debounced function. Subsequent\n * calls to the debounced function return the result of the last `func`\n * invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.debounce` and `_.throttle`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0] The number of milliseconds to delay.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * jQuery(window).on('resize', _.debounce(calculateLayout, 150));\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * jQuery(element).on('click', _.debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }));\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });\n * var source = new EventSource('/stream');\n * jQuery(source).on('message', debounced);\n *\n * // Cancel the trailing debounced invocation.\n * jQuery(window).on('popstate', debounced.cancel);\n */\nfunction debounce(func, wait, options) {\n var lastArgs,\n lastThis,\n maxWait,\n result,\n timerId,\n lastCallTime,\n lastInvokeTime = 0,\n leading = false,\n maxing = false,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n wait = toNumber(wait) || 0;\n if (isObject(options)) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing\n ? nativeMax(toNumber(options.maxWait) || 0, wait)\n : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time) {\n var args = lastArgs,\n thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n result = func.apply(thisArg, args);\n return result;\n }\n\n function leadingEdge(time) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime,\n result = wait - timeSinceLastCall;\n\n return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;\n }\n\n function shouldInvoke(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n lastCallTime === undefined ||\n timeSinceLastCall >= wait ||\n timeSinceLastCall < 0 ||\n (maxing && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired() {\n var time = now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(now());\n }\n\n function debounced() {\n var time = now(),\n isInvoking = shouldInvoke(time);\n\n lastArgs = arguments;\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n return debounced;\n}\n\n/**\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.throttle` and `_.debounce`.\n *\n * @internal\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to throttle.\n * @param {number} [wait=0] The number of milliseconds to throttle invocations to.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=true]\n * Specify invoking on the leading edge of the timeout.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new throttled function.\n * @example\n *\n * // Avoid excessively updating the position while scrolling.\n * jQuery(window).on('scroll', _.throttle(updatePosition, 100));\n *\n * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.\n * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });\n * jQuery(element).on('click', throttled);\n *\n * // Cancel the trailing throttled invocation.\n * jQuery(window).on('popstate', throttled.cancel);\n */\nexport function throttle(func, wait, options) {\n var leading = true,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n if (isObject(options)) {\n leading = 'leading' in options ? !!options.leading : leading;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n return debounce(func, wait, {\n leading: leading,\n maxWait: wait,\n trailing: trailing,\n });\n}\n\n/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return !!value && (type == 'object' || type == 'function');\n}\n\n/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value) {\n return !!value && typeof value == 'object';\n}\n\n/**\n * Checks if `value` is classified as a `Symbol` primitive or object.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.\n * @example\n *\n * _.isSymbol(Symbol.iterator);\n * // => true\n *\n * _.isSymbol('abc');\n * // => false\n */\nfunction isSymbol(value) {\n return (\n typeof value == 'symbol' ||\n (isObjectLike(value) && objectToString.call(value) == symbolTag)\n );\n}\n\n/**\n * Converts `value` to a number.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to process.\n * @returns {number} Returns the number.\n * @example\n *\n * _.toNumber(3.2);\n * // => 3.2\n *\n * _.toNumber(Number.MIN_VALUE);\n * // => 5e-324\n *\n * _.toNumber(Infinity);\n * // => Infinity\n *\n * _.toNumber('3.2');\n * // => 3.2\n */\nfunction toNumber(value) {\n if (typeof value == 'number') {\n return value;\n }\n if (isSymbol(value)) {\n return NAN;\n }\n if (isObject(value)) {\n var other = typeof value.valueOf == 'function' ? value.valueOf() : value;\n value = isObject(other) ? other + '' : other;\n }\n if (typeof value != 'string') {\n return value === 0 ? value : +value;\n }\n value = value.replace(reTrim, '');\n var isBinary = reIsBinary.test(value);\n return isBinary || reIsOctal.test(value)\n ? freeParseInt(value.slice(2), isBinary ? 2 : 8)\n : reIsBadHex.test(value)\n ? NAN\n : +value;\n}\n","/**\n * @license\n * time.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2025-03-24\n * Copyright © 2025 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Time service that maintains current timestamp.\n *\n * Timestamp is set either:\n * - initially with the local timestamp `Date.now()` when there is yet\n * communication with Enmasse server yet\n * - later with the accurate low-latency timestamp that comes in Enmasse\n * message handshake\n *\n * Thereafter the timestamp is maintained by `tick()` function and can be\n * retrieved in two ways:\n *\n * - subscribing to an event using `onTick(callback: () => void)` function\n * that pushes notification every second with the current timestamp\n * - or pulling data directly using function `now()`\n */\n\nimport { Emitter, subscribe, Unsubscribe } from './emitter';\n\nconst emitter = new Emitter();\n\nlet serverTimestamp: number = 0;\nlet lastTickTimestamp: number = 0;\nlet tickTimeoutId: ReturnType<typeof setTimeout>;\n\n/**\n * Returns local timestamp in seconds\n */\nfunction getCurrentTimestamp(): number {\n return Date.now() / 1000;\n}\n\n/**\n * Normalizes the timestamp to reduce fluctuations due to `setTimeout` delays.\n * Ensures the fractional part is around 0.5 to avoid skipping a second.\n *\n * Returns half-second timestamp. It is used to be sure that timestamp will not\n * fluctuate more than in 1 second after each tick due to longer delays.\n * https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified\n *\n * For example if the initial timestamp has a fractional part 0.9999 then with\n * the setTimeout (tick) longer than specified we might jump over a one second.\n * Lets imaging setTimeout took 1.0002 second, then our timestamp will be 2.0001.\n * Thats why we are trying to keep fractional part in the middle of the second.\n */\nfunction getMiddleTimestamp(timestamp: number): number {\n return Math.floor(timestamp) + 0.5;\n}\n\n/**\n * Calculates the delay for the next tick to keep timestamps stable.\n */\nfunction calculateNextTickDelay(): number {\n const expectedNextTick = getMiddleTimestamp(serverTimestamp) + 1;\n\n return (expectedNextTick - serverTimestamp) * 1000;\n}\n\n/**\n * Main function that maintains current timestamp\n */\nexport function tick() {\n clearTimeout(tickTimeoutId);\n\n const currentTimestamp = getCurrentTimestamp();\n const timeSinceLastTick = currentTimestamp - lastTickTimestamp;\n\n serverTimestamp += timeSinceLastTick;\n lastTickTimestamp = currentTimestamp;\n\n tickTimeoutId = setTimeout(tick, calculateNextTickDelay());\n\n emitter.emit('tick', serverTimestamp);\n}\n\n/**\n * @internal\n *\n * Sets or updates current timestamp\n *\n * @param timestamp - Current timestamp in seconds\n */\nexport function setTimestamp(timestamp: number): void {\n lastTickTimestamp = getCurrentTimestamp();\n serverTimestamp = getMiddleTimestamp(timestamp);\n}\n\n/**\n * Returns current timestamp that is preserved by `tick()` function\n *\n * @returns Current timestamp in seconds\n */\nexport function now(): number {\n return Math.floor(serverTimestamp);\n}\n\n/**\n * Subscribes listener to the timestamp increment\n *\n * @param callback - A handler that executes when the timestamp is incremented\n *\n * @returns A function that unsubscribes the listener\n */\nexport function onTick(callback: (timestamp: number) => void): Unsubscribe {\n return subscribe(emitter, 'tick', callback);\n}\n\n// Initially timestamp is set based on a local date\n// Later on it can be overriden outside at any moment\n// in our case it is populated with the server timestamp\n// which comes from Enmasse session handshake message\nsetTimestamp(getCurrentTimestamp());\n\n// Kicking in timestamp maintaining\ntick();\n","/**\n * @license\n * @monterosa/sdk-util\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Calculate percentage of each value in the array.\n *\n * It uses Hamilton's method, also known as the method of largest remainder.\n * It is a system used for distributing vote percentages among different\n * options (like candidates or choices) based on their vote counts. It ensures\n * that each option receives at least its lower quota of percentage points, and\n * any remaining percentage points are allocated to those with the largest\n * fractional remainders. This method is used in the US Electoral College.\n *\n * @param values - Array of number values to calculate percentage for\n * @returns Array of percentages, where the sum of the array is 100%\n */\nexport const calculatePercentage = (values: number[]): number[] => {\n // Calculate sum of all votes\n const sum = values.reduce((memo, value) => memo + value, 0);\n\n // create array of hashes\n const results = values.map((value, idx) => {\n const percentage = (100 * value) / sum || 0;\n\n return {\n idx,\n votes: value,\n percentage: Math.floor(percentage),\n remainder: percentage % 1,\n };\n });\n\n // Sum them all up - this can't be higher than 100%\n let total = results.reduce((memo, { percentage }) => memo + percentage, 0);\n\n total = total || 100;\n\n // Calculate number of percent that we are missing\n const delta = 100 - total;\n\n // Order all options by remainder\n results.sort((a, b) => {\n if (a.remainder !== b.remainder) {\n return b.remainder - a.remainder;\n }\n\n return a.idx - b.idx;\n });\n\n // Distribute delta to highest remainder options\n for (let i = 0; i < delta; i++) {\n results[i].percentage += 1;\n }\n\n // Restore options order\n results.sort((a, b) => a.idx - b.idx);\n\n return results.map((item) => item.percentage);\n};\n"],"names":["now"],"mappings":";;AAAA;;;;;;;;;;MAea,OAAO;IAIlB;QAFiB,aAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;QAG1D,IAAI,CAAC,OAAO,GAAG,IAAI,EAAuB,CAAC;KAC5C;IAED,EAAE,CAAC,KAAa,EAAE,OAAgB;QAChC,MAAM,WAAW,GAAgB,CAAC,IAAI;YACpC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACnD,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAEpC,OAAO,MAAM,IAAI,CAAC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AC,CAAC;KAC5B;;IAGD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAEtC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;AAChD;;;;"}
|
package/dist/index.esm5.js
CHANGED
|
@@ -344,6 +344,23 @@ function createError(code, messages) {
|
|
|
344
344
|
}
|
|
345
345
|
var message = messages[code].apply(messages, params);
|
|
346
346
|
return new MonterosaError(code, message);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* @internal
|
|
350
|
+
*/
|
|
351
|
+
function getErrorMessage(err) {
|
|
352
|
+
if (err instanceof Error) {
|
|
353
|
+
return err.message;
|
|
354
|
+
}
|
|
355
|
+
if (typeof err === 'string') {
|
|
356
|
+
return err;
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
return JSON.stringify(err);
|
|
360
|
+
}
|
|
361
|
+
catch (_a) {
|
|
362
|
+
return 'Unknown error';
|
|
363
|
+
}
|
|
347
364
|
}
|
|
348
365
|
|
|
349
366
|
/**
|
|
@@ -900,5 +917,5 @@ var calculatePercentage = function (values) {
|
|
|
900
917
|
return results.map(function (item) { return item.percentage; });
|
|
901
918
|
};
|
|
902
919
|
|
|
903
|
-
export { Emitter, MonterosaError, calculatePercentage, checkAvailability, clear, createError, delay, getGlobal, getItem, getKey, memoizePromise, now, onTick, removeItem, setItem, setTimestamp, subscribe, throttle, tick };
|
|
920
|
+
export { Emitter, MonterosaError, calculatePercentage, checkAvailability, clear, createError, delay, getErrorMessage, getGlobal, getItem, getKey, memoizePromise, now, onTick, removeItem, setItem, setTimestamp, subscribe, throttle, tick };
|
|
904
921
|
//# sourceMappingURL=index.esm5.js.map
|
package/dist/index.esm5.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm5.js","sources":["../src/emitter.ts","../src/delay.ts","../src/memoize-promise.ts","../src/global.ts","../src/storage.ts","../src/error.ts","../src/throttle.ts","../src/time.ts","../src/calculate-percentage.ts"],"sourcesContent":["/**\n * @license\n * subscribe.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport mitt, { Emitter as MittEmitter, Handler as MittHandler } from 'mitt';\n\ntype Handler = (...args: any[]) => void;\n\nexport class Emitter {\n private readonly emitter: MittEmitter<Record<string, any>>;\n private readonly handlers = new Map<Handler, MittHandler>();\n\n constructor() {\n this.emitter = mitt<Record<string, any>>();\n }\n\n on(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n\n off(event: string, handler?: Handler): void {\n if (handler === undefined) {\n this.emitter.off(event);\n return;\n }\n\n const mittHandler = this.handlers.get(handler);\n\n if (mittHandler) {\n this.emitter.off(event, mittHandler);\n this.handlers.delete(handler);\n }\n }\n\n emit(event: string, ...args: any[]): void {\n this.emitter.emit(event, args);\n }\n\n once(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n\n this.off(event, handler);\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n}\n\n/**\n * The unsubscribe function. When it is called, the previously set event\n * listener is removed. It is returned by every observer functions\n *\n * @example\n * ```typescript\n * const unsubscribe: Unsubscribe = onElementPublished((element) => {\n * console.log('Element published', element);\n * });\n *\n * unsubscribe();\n * ```\n */\nexport interface Unsubscribe {\n (): void;\n}\n\n/**\n * @internal\n */\nexport interface Subscribe {\n (\n emitter: Emitter,\n event: string,\n callback: (...args: any[]) => void,\n ): Unsubscribe;\n}\n\n/**\n * @internal\n */\nexport const subscribe: Subscribe = (emitter, event, callback) => {\n emitter.on(event, callback);\n\n return () => emitter.off(event, callback);\n};\n","/**\n * @license\n * delay.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * @internal\n */\nexport const delay = async (timeout: number): Promise<void> => {\n await new Promise((resolve) => setTimeout(resolve, timeout));\n};\n","/**\n * @license\n * memoize-promise.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-09-20\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Creates a function that memoizes the result of `func`.\n *\n * @internal\n *\n * @param func - A function that returns a promise. The results of its work will be memoized.\n * @param resolver - A function that determines the cache key.\n * @param config - A configuration object with the following optional properties:\n * `clearOnResolve` - Deletes memoized result upon promise resolve. Defaults to `false`.\n * `clearOnReject` - Deletes memoized result upon promise reject. Defaults to `true`.\n */\n\nexport const memoizePromise = <T>(\n func: (...args: any[]) => Promise<T>,\n resolver: (...args: any[]) => any,\n config: {\n clearOnResolve?: boolean;\n clearOnReject?: boolean;\n } = {},\n): ((...args: any[]) => Promise<T>) => {\n const clearOnResolve = config.clearOnResolve ?? false;\n const clearOnReject = config.clearOnReject ?? true;\n\n const cache: Map<any, Promise<T>> = new Map();\n\n const memoized = (...args: any[]) => {\n const key = resolver(...args);\n\n if (cache.has(key)) {\n return cache.get(key) as Promise<T>;\n }\n\n const promise = func(...args);\n\n cache.set(key, promise);\n\n promise.then(() => clearOnResolve && cache.delete(key));\n promise.catch(() => clearOnReject && cache.delete(key));\n\n return promise;\n };\n\n memoized.cache = cache;\n\n return memoized;\n};\n","/**\n * @license\n * global.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint no-restricted-globals: \"off\" */\n\n/**\n * Global object polyfill.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\n *\n * @internal\n *\n * @returns typeof globalThis\n */\nexport function getGlobal(): typeof globalThis {\n if (typeof self !== 'undefined') {\n return self;\n }\n\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n\n if (typeof window !== 'undefined') {\n return window;\n }\n\n if (typeof global !== 'undefined') {\n return global;\n }\n\n throw new Error('Unable to locate global object.');\n}\n","/**\n * @license\n * storage.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getGlobal } from './global';\n\nconst PREFIX = 'monterosa_sdk_';\n\nconst BAIT = 'bait';\n\nconst globals = getGlobal();\n\n/**\n * @internal\n */\nexport const getKey = (name: string) => `${PREFIX}${name}`;\n\n/**\n * @internal\n */\nexport function getItem(key: string): string | null {\n return globals.localStorage.getItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function setItem(key: string, value: string): void {\n return globals.localStorage.setItem(getKey(key), value);\n}\n\n/**\n * @internal\n */\nexport function removeItem(key: string): void {\n return globals.localStorage.removeItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function clear(): void {\n return globals.localStorage.clear();\n}\n\n/**\n * Checks locastorage availability.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\n * and Paul Irish gists: https://gist.github.com/paulirish/5558557\n *\n * @internal\n *\n * @returns boolean\n */\nexport function checkAvailability() {\n try {\n setItem(BAIT, BAIT);\n getItem(BAIT);\n removeItem(BAIT);\n\n return true;\n } catch (e) {\n return false;\n }\n}\n","/**\n * @license\n * error.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-31\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint max-classes-per-file: [\"error\", 2] */\n\n/**\n * MonterosaError extends the standard JavaScript `Error` object. It has\n * an error code so that user can identify the error. Also it has it's own\n * specific `name` \"MonterosaError\"\n */\nexport class MonterosaError extends Error {\n /**\n * The name property represents a name for the type of error.\n */\n readonly name = 'MonterosaError';\n\n /**\n * Error code string\n */\n readonly code: string;\n\n /**\n * @param code - Error code string\n * @param message - A descriptive message for the error\n */\n constructor(code: string, message: string) {\n super(message);\n\n this.code = code;\n\n // Fix For ES5\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, MonterosaError.prototype);\n }\n}\n\ntype ErrorMap<ErrorCode extends string> = {\n readonly [K in ErrorCode]: (...rest: any[]) => string;\n};\n\n/**\n * @internal\n */\nexport function createError<ErrorCode extends string>(\n code: ErrorCode,\n messages: ErrorMap<ErrorCode>,\n ...params: any[]\n) {\n const message = messages[code](...params);\n\n return new MonterosaError(code, message);\n}\n","/**\n * @license\n * throttle.ts\n * util\n *\n * Created by Josep Rodriguez <josep.rodriguez@monterosa.co.uk> on 2022-07-13\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint-disable */\n// @ts-nocheck\n\n/**\n * lodash (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright jQuery Foundation and other contributors <https://jquery.org/>\n * Released under MIT license <https://lodash.com/license>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n */\n\n/** Used as the `TypeError` message for \"Functions\" methods. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/** Used as references for various `Number` constants. */\nvar NAN = 0 / 0;\n\n/** `Object#toString` result references. */\nvar symbolTag = '[object Symbol]';\n\n/** Used to match leading and trailing whitespace. */\nvar reTrim = /^\\s+|\\s+$/g;\n\n/** Used to detect bad signed hexadecimal string values. */\nvar reIsBadHex = /^[-+]0x[0-9a-f]+$/i;\n\n/** Used to detect binary string values. */\nvar reIsBinary = /^0b[01]+$/i;\n\n/** Used to detect octal string values. */\nvar reIsOctal = /^0o[0-7]+$/i;\n\n/** Built-in method references without a dependency on `root`. */\nvar freeParseInt = parseInt;\n\n/** Detect free variable `global` from Node.js. */\nvar freeGlobal =\n typeof global == 'object' && global && global.Object === Object && global;\n\n/** Detect free variable `self`. */\nvar freeSelf =\n typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar objectToString = objectProto.toString;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max,\n nativeMin = Math.min;\n\n/**\n * Gets the timestamp of the number of milliseconds that have elapsed since\n * the Unix epoch (1 January 1970 00:00:00 UTC).\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Date\n * @returns {number} Returns the timestamp.\n * @example\n *\n * _.defer(function(stamp) {\n * console.log(_.now() - stamp);\n * }, _.now());\n * // => Logs the number of milliseconds it took for the deferred invocation.\n */\nvar now = function () {\n return root.Date.now();\n};\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel\n * delayed `func` invocations and a `flush` method to immediately invoke them.\n * Provide `options` to indicate whether `func` should be invoked on the\n * leading and/or trailing edge of the `wait` timeout. The `func` is invoked\n * with the last arguments provided to the debounced function. Subsequent\n * calls to the debounced function return the result of the last `func`\n * invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.debounce` and `_.throttle`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0] The number of milliseconds to delay.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * jQuery(window).on('resize', _.debounce(calculateLayout, 150));\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * jQuery(element).on('click', _.debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }));\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });\n * var source = new EventSource('/stream');\n * jQuery(source).on('message', debounced);\n *\n * // Cancel the trailing debounced invocation.\n * jQuery(window).on('popstate', debounced.cancel);\n */\nfunction debounce(func, wait, options) {\n var lastArgs,\n lastThis,\n maxWait,\n result,\n timerId,\n lastCallTime,\n lastInvokeTime = 0,\n leading = false,\n maxing = false,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n wait = toNumber(wait) || 0;\n if (isObject(options)) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing\n ? nativeMax(toNumber(options.maxWait) || 0, wait)\n : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time) {\n var args = lastArgs,\n thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n result = func.apply(thisArg, args);\n return result;\n }\n\n function leadingEdge(time) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime,\n result = wait - timeSinceLastCall;\n\n return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;\n }\n\n function shouldInvoke(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n lastCallTime === undefined ||\n timeSinceLastCall >= wait ||\n timeSinceLastCall < 0 ||\n (maxing && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired() {\n var time = now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(now());\n }\n\n function debounced() {\n var time = now(),\n isInvoking = shouldInvoke(time);\n\n lastArgs = arguments;\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n return debounced;\n}\n\n/**\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.throttle` and `_.debounce`.\n *\n * @internal\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to throttle.\n * @param {number} [wait=0] The number of milliseconds to throttle invocations to.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=true]\n * Specify invoking on the leading edge of the timeout.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new throttled function.\n * @example\n *\n * // Avoid excessively updating the position while scrolling.\n * jQuery(window).on('scroll', _.throttle(updatePosition, 100));\n *\n * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.\n * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });\n * jQuery(element).on('click', throttled);\n *\n * // Cancel the trailing throttled invocation.\n * jQuery(window).on('popstate', throttled.cancel);\n */\nexport function throttle(func, wait, options) {\n var leading = true,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n if (isObject(options)) {\n leading = 'leading' in options ? !!options.leading : leading;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n return debounce(func, wait, {\n leading: leading,\n maxWait: wait,\n trailing: trailing,\n });\n}\n\n/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return !!value && (type == 'object' || type == 'function');\n}\n\n/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value) {\n return !!value && typeof value == 'object';\n}\n\n/**\n * Checks if `value` is classified as a `Symbol` primitive or object.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.\n * @example\n *\n * _.isSymbol(Symbol.iterator);\n * // => true\n *\n * _.isSymbol('abc');\n * // => false\n */\nfunction isSymbol(value) {\n return (\n typeof value == 'symbol' ||\n (isObjectLike(value) && objectToString.call(value) == symbolTag)\n );\n}\n\n/**\n * Converts `value` to a number.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to process.\n * @returns {number} Returns the number.\n * @example\n *\n * _.toNumber(3.2);\n * // => 3.2\n *\n * _.toNumber(Number.MIN_VALUE);\n * // => 5e-324\n *\n * _.toNumber(Infinity);\n * // => Infinity\n *\n * _.toNumber('3.2');\n * // => 3.2\n */\nfunction toNumber(value) {\n if (typeof value == 'number') {\n return value;\n }\n if (isSymbol(value)) {\n return NAN;\n }\n if (isObject(value)) {\n var other = typeof value.valueOf == 'function' ? value.valueOf() : value;\n value = isObject(other) ? other + '' : other;\n }\n if (typeof value != 'string') {\n return value === 0 ? value : +value;\n }\n value = value.replace(reTrim, '');\n var isBinary = reIsBinary.test(value);\n return isBinary || reIsOctal.test(value)\n ? freeParseInt(value.slice(2), isBinary ? 2 : 8)\n : reIsBadHex.test(value)\n ? NAN\n : +value;\n}\n","/**\n * @license\n * time.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2025-03-24\n * Copyright © 2025 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Time service that maintains current timestamp.\n *\n * Timestamp is set either:\n * - initially with the local timestamp `Date.now()` when there is yet\n * communication with Enmasse server yet\n * - later with the accurate low-latency timestamp that comes in Enmasse\n * message handshake\n *\n * Thereafter the timestamp is maintained by `tick()` function and can be\n * retrieved in two ways:\n *\n * - subscribing to an event using `onTick(callback: () => void)` function\n * that pushes notification every second with the current timestamp\n * - or pulling data directly using function `now()`\n */\n\nimport { Emitter, subscribe, Unsubscribe } from './emitter';\n\nconst emitter = new Emitter();\n\nlet serverTimestamp: number = 0;\nlet lastTickTimestamp: number = 0;\nlet tickTimeoutId: ReturnType<typeof setTimeout>;\n\n/**\n * Returns local timestamp in seconds\n */\nfunction getCurrentTimestamp(): number {\n return Date.now() / 1000;\n}\n\n/**\n * Normalizes the timestamp to reduce fluctuations due to `setTimeout` delays.\n * Ensures the fractional part is around 0.5 to avoid skipping a second.\n *\n * Returns half-second timestamp. It is used to be sure that timestamp will not\n * fluctuate more than in 1 second after each tick due to longer delays.\n * https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified\n *\n * For example if the initial timestamp has a fractional part 0.9999 then with\n * the setTimeout (tick) longer than specified we might jump over a one second.\n * Lets imaging setTimeout took 1.0002 second, then our timestamp will be 2.0001.\n * Thats why we are trying to keep fractional part in the middle of the second.\n */\nfunction getMiddleTimestamp(timestamp: number): number {\n return Math.floor(timestamp) + 0.5;\n}\n\n/**\n * Calculates the delay for the next tick to keep timestamps stable.\n */\nfunction calculateNextTickDelay(): number {\n const expectedNextTick = getMiddleTimestamp(serverTimestamp) + 1;\n\n return (expectedNextTick - serverTimestamp) * 1000;\n}\n\n/**\n * Main function that maintains current timestamp\n */\nexport function tick() {\n clearTimeout(tickTimeoutId);\n\n const currentTimestamp = getCurrentTimestamp();\n const timeSinceLastTick = currentTimestamp - lastTickTimestamp;\n\n serverTimestamp += timeSinceLastTick;\n lastTickTimestamp = currentTimestamp;\n\n tickTimeoutId = setTimeout(tick, calculateNextTickDelay());\n\n emitter.emit('tick', serverTimestamp);\n}\n\n/**\n * @internal\n *\n * Sets or updates current timestamp\n *\n * @param timestamp - Current timestamp in seconds\n */\nexport function setTimestamp(timestamp: number): void {\n lastTickTimestamp = getCurrentTimestamp();\n serverTimestamp = getMiddleTimestamp(timestamp);\n}\n\n/**\n * Returns current timestamp that is preserved by `tick()` function\n *\n * @returns Current timestamp in seconds\n */\nexport function now(): number {\n return Math.floor(serverTimestamp);\n}\n\n/**\n * Subscribes listener to the timestamp increment\n *\n * @param callback - A handler that executes when the timestamp is incremented\n *\n * @returns A function that unsubscribes the listener\n */\nexport function onTick(callback: (timestamp: number) => void): Unsubscribe {\n return subscribe(emitter, 'tick', callback);\n}\n\n// Initially timestamp is set based on a local date\n// Later on it can be overriden outside at any moment\n// in our case it is populated with the server timestamp\n// which comes from Enmasse session handshake message\nsetTimestamp(getCurrentTimestamp());\n\n// Kicking in timestamp maintaining\ntick();\n","/**\n * @license\n * @monterosa/sdk-util\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Calculate percentage of each value in the array.\n *\n * It uses Hamilton's method, also known as the method of largest remainder.\n * It is a system used for distributing vote percentages among different\n * options (like candidates or choices) based on their vote counts. It ensures\n * that each option receives at least its lower quota of percentage points, and\n * any remaining percentage points are allocated to those with the largest\n * fractional remainders. This method is used in the US Electoral College.\n *\n * @param values - Array of number values to calculate percentage for\n * @returns Array of percentages, where the sum of the array is 100%\n */\nexport const calculatePercentage = (values: number[]): number[] => {\n // Calculate sum of all votes\n const sum = values.reduce((memo, value) => memo + value, 0);\n\n // create array of hashes\n const results = values.map((value, idx) => {\n const percentage = (100 * value) / sum || 0;\n\n return {\n idx,\n votes: value,\n percentage: Math.floor(percentage),\n remainder: percentage % 1,\n };\n });\n\n // Sum them all up - this can't be higher than 100%\n let total = results.reduce((memo, { percentage }) => memo + percentage, 0);\n\n total = total || 100;\n\n // Calculate number of percent that we are missing\n const delta = 100 - total;\n\n // Order all options by remainder\n results.sort((a, b) => {\n if (a.remainder !== b.remainder) {\n return b.remainder - a.remainder;\n }\n\n return a.idx - b.idx;\n });\n\n // Distribute delta to highest remainder options\n for (let i = 0; i < delta; i++) {\n results[i].percentage += 1;\n }\n\n // Restore options order\n results.sort((a, b) => a.idx - b.idx);\n\n return results.map((item) => item.percentage);\n};\n"],"names":["now"],"mappings":";;AAAA;;;;;;;;;;;IAmBE;QAFiB,aAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;QAG1D,IAAI,CAAC,OAAO,GAAG,IAAI,EAAuB,CAAC;KAC5C;IAED,oBAAE,GAAF,UAAG,KAAa,EAAE,OAAgB;QAAlC,iBASC;QARC,IAAM,WAAW,GAAgB,UAAC,IAAI;YACpC,OAAO,gBAAK,KAAK,CAAC,OAAO,CAAC,IA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CAAC;;IAG1B,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,EAAE;YAC/B,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;SAClC;QAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;KACtB,CAAC,CAAC;;IAGH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;QAC9B,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC;KAC5B;;IAGD,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAA,CAAC,CAAC;IAEtC,OAAO,OAAO,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,UAAU,GAAA,CAAC,CAAC;AAChD;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm5.js","sources":["../src/emitter.ts","../src/delay.ts","../src/memoize-promise.ts","../src/global.ts","../src/storage.ts","../src/error.ts","../src/throttle.ts","../src/time.ts","../src/calculate-percentage.ts"],"sourcesContent":["/**\n * @license\n * subscribe.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport mitt, { Emitter as MittEmitter, Handler as MittHandler } from 'mitt';\n\ntype Handler = (...args: any[]) => void;\n\nexport class Emitter {\n private readonly emitter: MittEmitter<Record<string, any>>;\n private readonly handlers = new Map<Handler, MittHandler>();\n\n constructor() {\n this.emitter = mitt<Record<string, any>>();\n }\n\n on(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n\n off(event: string, handler?: Handler): void {\n if (handler === undefined) {\n this.emitter.off(event);\n return;\n }\n\n const mittHandler = this.handlers.get(handler);\n\n if (mittHandler) {\n this.emitter.off(event, mittHandler);\n this.handlers.delete(handler);\n }\n }\n\n emit(event: string, ...args: any[]): void {\n this.emitter.emit(event, args);\n }\n\n once(event: string, handler: Handler): Unsubscribe {\n const mittHandler: MittHandler = (args) => {\n handler(...(Array.isArray(args) ? args : [args]));\n\n this.off(event, handler);\n };\n\n this.handlers.set(handler, mittHandler);\n this.emitter.on(event, mittHandler);\n\n return () => this.off(event, handler);\n }\n}\n\n/**\n * The unsubscribe function. When it is called, the previously set event\n * listener is removed. It is returned by every observer functions\n *\n * @example\n * ```typescript\n * const unsubscribe: Unsubscribe = onElementPublished((element) => {\n * console.log('Element published', element);\n * });\n *\n * unsubscribe();\n * ```\n */\nexport interface Unsubscribe {\n (): void;\n}\n\n/**\n * @internal\n */\nexport interface Subscribe {\n (\n emitter: Emitter,\n event: string,\n callback: (...args: any[]) => void,\n ): Unsubscribe;\n}\n\n/**\n * @internal\n */\nexport const subscribe: Subscribe = (emitter, event, callback) => {\n emitter.on(event, callback);\n\n return () => emitter.off(event, callback);\n};\n","/**\n * @license\n * delay.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * @internal\n */\nexport const delay = async (timeout: number): Promise<void> => {\n await new Promise((resolve) => setTimeout(resolve, timeout));\n};\n","/**\n * @license\n * memoize-promise.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-09-20\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Creates a function that memoizes the result of `func`.\n *\n * @internal\n *\n * @param func - A function that returns a promise. The results of its work will be memoized.\n * @param resolver - A function that determines the cache key.\n * @param config - A configuration object with the following optional properties:\n * `clearOnResolve` - Deletes memoized result upon promise resolve. Defaults to `false`.\n * `clearOnReject` - Deletes memoized result upon promise reject. Defaults to `true`.\n */\n\nexport const memoizePromise = <T>(\n func: (...args: any[]) => Promise<T>,\n resolver: (...args: any[]) => any,\n config: {\n clearOnResolve?: boolean;\n clearOnReject?: boolean;\n } = {},\n): ((...args: any[]) => Promise<T>) => {\n const clearOnResolve = config.clearOnResolve ?? false;\n const clearOnReject = config.clearOnReject ?? true;\n\n const cache: Map<any, Promise<T>> = new Map();\n\n const memoized = (...args: any[]) => {\n const key = resolver(...args);\n\n if (cache.has(key)) {\n return cache.get(key) as Promise<T>;\n }\n\n const promise = func(...args);\n\n cache.set(key, promise);\n\n promise.then(() => clearOnResolve && cache.delete(key));\n promise.catch(() => clearOnReject && cache.delete(key));\n\n return promise;\n };\n\n memoized.cache = cache;\n\n return memoized;\n};\n","/**\n * @license\n * global.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint no-restricted-globals: \"off\" */\n\n/**\n * Global object polyfill.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\n *\n * @internal\n *\n * @returns typeof globalThis\n */\nexport function getGlobal(): typeof globalThis {\n if (typeof self !== 'undefined') {\n return self;\n }\n\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n\n if (typeof window !== 'undefined') {\n return window;\n }\n\n if (typeof global !== 'undefined') {\n return global;\n }\n\n throw new Error('Unable to locate global object.');\n}\n","/**\n * @license\n * storage.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-04-21\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getGlobal } from './global';\n\nconst PREFIX = 'monterosa_sdk_';\n\nconst BAIT = 'bait';\n\nconst globals = getGlobal();\n\n/**\n * @internal\n */\nexport const getKey = (name: string) => `${PREFIX}${name}`;\n\n/**\n * @internal\n */\nexport function getItem(key: string): string | null {\n return globals.localStorage.getItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function setItem(key: string, value: string): void {\n return globals.localStorage.setItem(getKey(key), value);\n}\n\n/**\n * @internal\n */\nexport function removeItem(key: string): void {\n return globals.localStorage.removeItem(getKey(key));\n}\n\n/**\n * @internal\n */\nexport function clear(): void {\n return globals.localStorage.clear();\n}\n\n/**\n * Checks locastorage availability.\n * Based on MDN article: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\n * and Paul Irish gists: https://gist.github.com/paulirish/5558557\n *\n * @internal\n *\n * @returns boolean\n */\nexport function checkAvailability() {\n try {\n setItem(BAIT, BAIT);\n getItem(BAIT);\n removeItem(BAIT);\n\n return true;\n } catch (e) {\n return false;\n }\n}\n","/**\n * @license\n * error.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-31\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint max-classes-per-file: [\"error\", 2] */\n\n/**\n * MonterosaError extends the standard JavaScript `Error` object. It has\n * an error code so that user can identify the error. Also it has it's own\n * specific `name` \"MonterosaError\"\n */\nexport class MonterosaError extends Error {\n /**\n * The name property represents a name for the type of error.\n */\n readonly name = 'MonterosaError';\n\n /**\n * Error code string\n */\n readonly code: string;\n\n /**\n * @param code - Error code string\n * @param message - A descriptive message for the error\n */\n constructor(code: string, message: string) {\n super(message);\n\n this.code = code;\n\n // Fix For ES5\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, MonterosaError.prototype);\n }\n}\n\ntype ErrorMap<ErrorCode extends string> = {\n readonly [K in ErrorCode]: (...rest: any[]) => string;\n};\n\n/**\n * @internal\n */\nexport function createError<ErrorCode extends string>(\n code: ErrorCode,\n messages: ErrorMap<ErrorCode>,\n ...params: any[]\n) {\n const message = messages[code](...params);\n\n return new MonterosaError(code, message);\n}\n\n/**\n * @internal\n */\nexport function getErrorMessage(err: unknown): string {\n if (err instanceof Error) {\n return err.message;\n }\n\n if (typeof err === 'string') {\n return err;\n }\n\n try {\n return JSON.stringify(err);\n } catch {\n return 'Unknown error';\n }\n}\n","/**\n * @license\n * throttle.ts\n * util\n *\n * Created by Josep Rodriguez <josep.rodriguez@monterosa.co.uk> on 2022-07-13\n * Copyright © 2022 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/* eslint-disable */\n// @ts-nocheck\n\n/**\n * lodash (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright jQuery Foundation and other contributors <https://jquery.org/>\n * Released under MIT license <https://lodash.com/license>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n */\n\n/** Used as the `TypeError` message for \"Functions\" methods. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/** Used as references for various `Number` constants. */\nvar NAN = 0 / 0;\n\n/** `Object#toString` result references. */\nvar symbolTag = '[object Symbol]';\n\n/** Used to match leading and trailing whitespace. */\nvar reTrim = /^\\s+|\\s+$/g;\n\n/** Used to detect bad signed hexadecimal string values. */\nvar reIsBadHex = /^[-+]0x[0-9a-f]+$/i;\n\n/** Used to detect binary string values. */\nvar reIsBinary = /^0b[01]+$/i;\n\n/** Used to detect octal string values. */\nvar reIsOctal = /^0o[0-7]+$/i;\n\n/** Built-in method references without a dependency on `root`. */\nvar freeParseInt = parseInt;\n\n/** Detect free variable `global` from Node.js. */\nvar freeGlobal =\n typeof global == 'object' && global && global.Object === Object && global;\n\n/** Detect free variable `self`. */\nvar freeSelf =\n typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar objectToString = objectProto.toString;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max,\n nativeMin = Math.min;\n\n/**\n * Gets the timestamp of the number of milliseconds that have elapsed since\n * the Unix epoch (1 January 1970 00:00:00 UTC).\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Date\n * @returns {number} Returns the timestamp.\n * @example\n *\n * _.defer(function(stamp) {\n * console.log(_.now() - stamp);\n * }, _.now());\n * // => Logs the number of milliseconds it took for the deferred invocation.\n */\nvar now = function () {\n return root.Date.now();\n};\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel\n * delayed `func` invocations and a `flush` method to immediately invoke them.\n * Provide `options` to indicate whether `func` should be invoked on the\n * leading and/or trailing edge of the `wait` timeout. The `func` is invoked\n * with the last arguments provided to the debounced function. Subsequent\n * calls to the debounced function return the result of the last `func`\n * invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.debounce` and `_.throttle`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0] The number of milliseconds to delay.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * jQuery(window).on('resize', _.debounce(calculateLayout, 150));\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * jQuery(element).on('click', _.debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }));\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });\n * var source = new EventSource('/stream');\n * jQuery(source).on('message', debounced);\n *\n * // Cancel the trailing debounced invocation.\n * jQuery(window).on('popstate', debounced.cancel);\n */\nfunction debounce(func, wait, options) {\n var lastArgs,\n lastThis,\n maxWait,\n result,\n timerId,\n lastCallTime,\n lastInvokeTime = 0,\n leading = false,\n maxing = false,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n wait = toNumber(wait) || 0;\n if (isObject(options)) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing\n ? nativeMax(toNumber(options.maxWait) || 0, wait)\n : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time) {\n var args = lastArgs,\n thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n result = func.apply(thisArg, args);\n return result;\n }\n\n function leadingEdge(time) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime,\n result = wait - timeSinceLastCall;\n\n return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;\n }\n\n function shouldInvoke(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n lastCallTime === undefined ||\n timeSinceLastCall >= wait ||\n timeSinceLastCall < 0 ||\n (maxing && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired() {\n var time = now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(now());\n }\n\n function debounced() {\n var time = now(),\n isInvoking = shouldInvoke(time);\n\n lastArgs = arguments;\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n return debounced;\n}\n\n/**\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.throttle` and `_.debounce`.\n *\n * @internal\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to throttle.\n * @param {number} [wait=0] The number of milliseconds to throttle invocations to.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=true]\n * Specify invoking on the leading edge of the timeout.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new throttled function.\n * @example\n *\n * // Avoid excessively updating the position while scrolling.\n * jQuery(window).on('scroll', _.throttle(updatePosition, 100));\n *\n * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.\n * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });\n * jQuery(element).on('click', throttled);\n *\n * // Cancel the trailing throttled invocation.\n * jQuery(window).on('popstate', throttled.cancel);\n */\nexport function throttle(func, wait, options) {\n var leading = true,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n if (isObject(options)) {\n leading = 'leading' in options ? !!options.leading : leading;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n return debounce(func, wait, {\n leading: leading,\n maxWait: wait,\n trailing: trailing,\n });\n}\n\n/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return !!value && (type == 'object' || type == 'function');\n}\n\n/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value) {\n return !!value && typeof value == 'object';\n}\n\n/**\n * Checks if `value` is classified as a `Symbol` primitive or object.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.\n * @example\n *\n * _.isSymbol(Symbol.iterator);\n * // => true\n *\n * _.isSymbol('abc');\n * // => false\n */\nfunction isSymbol(value) {\n return (\n typeof value == 'symbol' ||\n (isObjectLike(value) && objectToString.call(value) == symbolTag)\n );\n}\n\n/**\n * Converts `value` to a number.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to process.\n * @returns {number} Returns the number.\n * @example\n *\n * _.toNumber(3.2);\n * // => 3.2\n *\n * _.toNumber(Number.MIN_VALUE);\n * // => 5e-324\n *\n * _.toNumber(Infinity);\n * // => Infinity\n *\n * _.toNumber('3.2');\n * // => 3.2\n */\nfunction toNumber(value) {\n if (typeof value == 'number') {\n return value;\n }\n if (isSymbol(value)) {\n return NAN;\n }\n if (isObject(value)) {\n var other = typeof value.valueOf == 'function' ? value.valueOf() : value;\n value = isObject(other) ? other + '' : other;\n }\n if (typeof value != 'string') {\n return value === 0 ? value : +value;\n }\n value = value.replace(reTrim, '');\n var isBinary = reIsBinary.test(value);\n return isBinary || reIsOctal.test(value)\n ? freeParseInt(value.slice(2), isBinary ? 2 : 8)\n : reIsBadHex.test(value)\n ? NAN\n : +value;\n}\n","/**\n * @license\n * time.ts\n * util\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2025-03-24\n * Copyright © 2025 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Time service that maintains current timestamp.\n *\n * Timestamp is set either:\n * - initially with the local timestamp `Date.now()` when there is yet\n * communication with Enmasse server yet\n * - later with the accurate low-latency timestamp that comes in Enmasse\n * message handshake\n *\n * Thereafter the timestamp is maintained by `tick()` function and can be\n * retrieved in two ways:\n *\n * - subscribing to an event using `onTick(callback: () => void)` function\n * that pushes notification every second with the current timestamp\n * - or pulling data directly using function `now()`\n */\n\nimport { Emitter, subscribe, Unsubscribe } from './emitter';\n\nconst emitter = new Emitter();\n\nlet serverTimestamp: number = 0;\nlet lastTickTimestamp: number = 0;\nlet tickTimeoutId: ReturnType<typeof setTimeout>;\n\n/**\n * Returns local timestamp in seconds\n */\nfunction getCurrentTimestamp(): number {\n return Date.now() / 1000;\n}\n\n/**\n * Normalizes the timestamp to reduce fluctuations due to `setTimeout` delays.\n * Ensures the fractional part is around 0.5 to avoid skipping a second.\n *\n * Returns half-second timestamp. It is used to be sure that timestamp will not\n * fluctuate more than in 1 second after each tick due to longer delays.\n * https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified\n *\n * For example if the initial timestamp has a fractional part 0.9999 then with\n * the setTimeout (tick) longer than specified we might jump over a one second.\n * Lets imaging setTimeout took 1.0002 second, then our timestamp will be 2.0001.\n * Thats why we are trying to keep fractional part in the middle of the second.\n */\nfunction getMiddleTimestamp(timestamp: number): number {\n return Math.floor(timestamp) + 0.5;\n}\n\n/**\n * Calculates the delay for the next tick to keep timestamps stable.\n */\nfunction calculateNextTickDelay(): number {\n const expectedNextTick = getMiddleTimestamp(serverTimestamp) + 1;\n\n return (expectedNextTick - serverTimestamp) * 1000;\n}\n\n/**\n * Main function that maintains current timestamp\n */\nexport function tick() {\n clearTimeout(tickTimeoutId);\n\n const currentTimestamp = getCurrentTimestamp();\n const timeSinceLastTick = currentTimestamp - lastTickTimestamp;\n\n serverTimestamp += timeSinceLastTick;\n lastTickTimestamp = currentTimestamp;\n\n tickTimeoutId = setTimeout(tick, calculateNextTickDelay());\n\n emitter.emit('tick', serverTimestamp);\n}\n\n/**\n * @internal\n *\n * Sets or updates current timestamp\n *\n * @param timestamp - Current timestamp in seconds\n */\nexport function setTimestamp(timestamp: number): void {\n lastTickTimestamp = getCurrentTimestamp();\n serverTimestamp = getMiddleTimestamp(timestamp);\n}\n\n/**\n * Returns current timestamp that is preserved by `tick()` function\n *\n * @returns Current timestamp in seconds\n */\nexport function now(): number {\n return Math.floor(serverTimestamp);\n}\n\n/**\n * Subscribes listener to the timestamp increment\n *\n * @param callback - A handler that executes when the timestamp is incremented\n *\n * @returns A function that unsubscribes the listener\n */\nexport function onTick(callback: (timestamp: number) => void): Unsubscribe {\n return subscribe(emitter, 'tick', callback);\n}\n\n// Initially timestamp is set based on a local date\n// Later on it can be overriden outside at any moment\n// in our case it is populated with the server timestamp\n// which comes from Enmasse session handshake message\nsetTimestamp(getCurrentTimestamp());\n\n// Kicking in timestamp maintaining\ntick();\n","/**\n * @license\n * @monterosa/sdk-util\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Calculate percentage of each value in the array.\n *\n * It uses Hamilton's method, also known as the method of largest remainder.\n * It is a system used for distributing vote percentages among different\n * options (like candidates or choices) based on their vote counts. It ensures\n * that each option receives at least its lower quota of percentage points, and\n * any remaining percentage points are allocated to those with the largest\n * fractional remainders. This method is used in the US Electoral College.\n *\n * @param values - Array of number values to calculate percentage for\n * @returns Array of percentages, where the sum of the array is 100%\n */\nexport const calculatePercentage = (values: number[]): number[] => {\n // Calculate sum of all votes\n const sum = values.reduce((memo, value) => memo + value, 0);\n\n // create array of hashes\n const results = values.map((value, idx) => {\n const percentage = (100 * value) / sum || 0;\n\n return {\n idx,\n votes: value,\n percentage: Math.floor(percentage),\n remainder: percentage % 1,\n };\n });\n\n // Sum them all up - this can't be higher than 100%\n let total = results.reduce((memo, { percentage }) => memo + percentage, 0);\n\n total = total || 100;\n\n // Calculate number of percent that we are missing\n const delta = 100 - total;\n\n // Order all options by remainder\n results.sort((a, b) => {\n if (a.remainder !== b.remainder) {\n return b.remainder - a.remainder;\n }\n\n return a.idx - b.idx;\n });\n\n // Distribute delta to highest remainder options\n for (let i = 0; i < delta; i++) {\n results[i].percentage += 1;\n }\n\n // Restore options order\n results.sort((a, b) => a.idx - b.idx);\n\n return results.map((item) => item.percentage);\n};\n"],"names":["now"],"mappings":";;AAAA;;;;;;;;;;;IAmBE;QAFiB,aAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;QAG1D,IAAI,CAAC,OAAO,GAAG,IAAI,EAAuB,CAAC;KAC5C;IAED,oBAAE,GAAF,UAAG,KAAa,EAAE,OAAgB;QAAlC,iBASC;QARC,IAAM,WAAW,GAAgB,UAAC,IAAI;YACpC,OAAO,gBAAK,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG;SACnD,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAEpC,OAAO,cAAM,OAAA,KAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,GAAA,CAAC;KACvC;IAED,qBAAG,GAAH,UAAI,KAAa,EAAE,OAAiB;QAClC,IAAI,OAAO,KAAK,SAAS,EAAE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AI,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,EAAE;YAC/B,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;SAClC;QAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;KACtB,CAAC,CAAC;;IAGH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;QAC9B,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC;KAC5B;;IAGD,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAA,CAAC,CAAC;IAEtC,OAAO,OAAO,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,UAAU,GAAA,CAAC,CAAC;AAChD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monterosa/sdk-util",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
4
4
|
"description": "Monterosa JS SDK / Utils",
|
|
5
5
|
"author": "Monterosa <hello@monterosa.co.uk> (https://www.monterosa.co/)",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "9751b80f19b914b0b0bbe356b816efddf4ce828b"
|
|
43
43
|
}
|