@selfcommunity/utils 1.0.19-alpha.0 → 1.1.0-alpha.0

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.
@@ -10,7 +10,8 @@ import LRUCache, { LruCache, LruCacheType, CacheStrategies } from './utils/cache
10
10
  import { Logger } from './utils/logger';
11
11
  import WSClient, { WSClientType, WSClientPropTypes } from './utils/websocket';
12
12
  import { resizeImage } from './utils/image';
13
+ import { getPeriodRange, LeaderboardPeriod } from './utils/leaderboard';
13
14
  /**
14
15
  * Export utilities
15
16
  */
16
- export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, handleOpenWindow, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, sortByAttr, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, LruCacheType, CacheStrategies, resizeImage, isPWA };
17
+ export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, handleOpenWindow, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, sortByAttr, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, LruCacheType, CacheStrategies, resizeImage, isPWA, getPeriodRange, LeaderboardPeriod };
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPWA = exports.resizeImage = exports.CacheStrategies = exports.LruCache = exports.LRUCache = exports.LocalStorageDB = exports.iOS = exports.loadVersionBrowser = exports.WSClient = exports.sortByAttr = exports.groupBy = exports.arraysEqual = exports.isInteger = exports.isFunc = exports.objectWithoutProperties = exports.isObject = exports.mergeDeep = exports.Logger = exports.handleOpenWindow = exports.isClientSideRendering = exports.getWindowHeight = exports.getWindowWidth = exports.getHighestSafeWindowContext = exports.updateQueryStringParameter = exports.getQueryStringParameter = exports.urlB64ToUint8Array = exports.appendURLSearchParams = exports.getDomain = exports.urlReplacer = exports.isValidUrls = exports.isValidUrl = exports.slugify = exports.random = exports.fallbackCopyTextToClipboard = exports.copyTextToClipboard = exports.camelCase = exports.stripHtml = exports.isString = exports.capitalize = void 0;
3
+ exports.getPeriodRange = exports.isPWA = exports.resizeImage = exports.CacheStrategies = exports.LruCache = exports.LRUCache = exports.LocalStorageDB = exports.iOS = exports.loadVersionBrowser = exports.WSClient = exports.sortByAttr = exports.groupBy = exports.arraysEqual = exports.isInteger = exports.isFunc = exports.objectWithoutProperties = exports.isObject = exports.mergeDeep = exports.Logger = exports.handleOpenWindow = exports.isClientSideRendering = exports.getWindowHeight = exports.getWindowWidth = exports.getHighestSafeWindowContext = exports.updateQueryStringParameter = exports.getQueryStringParameter = exports.urlB64ToUint8Array = exports.appendURLSearchParams = exports.getDomain = exports.urlReplacer = exports.isValidUrls = exports.isValidUrl = exports.slugify = exports.random = exports.fallbackCopyTextToClipboard = exports.copyTextToClipboard = exports.camelCase = exports.stripHtml = exports.isString = exports.capitalize = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const string_1 = require("./utils/string");
6
6
  Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return string_1.capitalize; } });
@@ -53,3 +53,5 @@ const websocket_1 = tslib_1.__importDefault(require("./utils/websocket"));
53
53
  exports.WSClient = websocket_1.default;
54
54
  const image_1 = require("./utils/image");
55
55
  Object.defineProperty(exports, "resizeImage", { enumerable: true, get: function () { return image_1.resizeImage; } });
56
+ const leaderboard_1 = require("./utils/leaderboard");
57
+ Object.defineProperty(exports, "getPeriodRange", { enumerable: true, get: function () { return leaderboard_1.getPeriodRange; } });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The period a leaderboard refers to
3
+ */
4
+ export type LeaderboardPeriod = 'week' | 'month' | 'year';
5
+ /**
6
+ * Computes the (inclusive) reputation date range the given period refers to
7
+ * @param period
8
+ */
9
+ export declare function getPeriodRange(period: LeaderboardPeriod): {
10
+ reputed_at_from: string;
11
+ reputed_at_to: string;
12
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPeriodRange = void 0;
4
+ /**
5
+ * Formats the given date as `yyyy-MM-dd` (in the local timezone)
6
+ * @param date
7
+ */
8
+ function formatDate(date) {
9
+ const month = `${date.getMonth() + 1}`.padStart(2, '0');
10
+ const day = `${date.getDate()}`.padStart(2, '0');
11
+ return `${date.getFullYear()}-${month}-${day}`;
12
+ }
13
+ /**
14
+ * Computes the (inclusive) reputation date range the given period refers to
15
+ * @param period
16
+ */
17
+ function getPeriodRange(period) {
18
+ const now = new Date();
19
+ const year = now.getFullYear();
20
+ const month = now.getMonth();
21
+ const day = now.getDate();
22
+ let from;
23
+ let to;
24
+ switch (period) {
25
+ case 'week': {
26
+ // Weeks start on monday
27
+ const weekDay = (now.getDay() + 6) % 7;
28
+ from = new Date(year, month, day - weekDay);
29
+ to = new Date(year, month, day - weekDay + 6);
30
+ break;
31
+ }
32
+ case 'year':
33
+ from = new Date(year, 0, 1);
34
+ to = new Date(year, 11, 31);
35
+ break;
36
+ default:
37
+ from = new Date(year, month, 1);
38
+ to = new Date(year, month + 1, 0);
39
+ break;
40
+ }
41
+ return { reputed_at_from: formatDate(from), reputed_at_to: formatDate(to) };
42
+ }
43
+ exports.getPeriodRange = getPeriodRange;
@@ -10,7 +10,8 @@ import LRUCache, { LruCache, LruCacheType, CacheStrategies } from './utils/cache
10
10
  import { Logger } from './utils/logger';
11
11
  import WSClient, { WSClientType, WSClientPropTypes } from './utils/websocket';
12
12
  import { resizeImage } from './utils/image';
13
+ import { getPeriodRange, LeaderboardPeriod } from './utils/leaderboard';
13
14
  /**
14
15
  * Export utilities
15
16
  */
16
- export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, handleOpenWindow, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, sortByAttr, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, LruCacheType, CacheStrategies, resizeImage, isPWA };
17
+ export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, handleOpenWindow, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, sortByAttr, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, LruCacheType, CacheStrategies, resizeImage, isPWA, getPeriodRange, LeaderboardPeriod };
package/lib/esm/index.js CHANGED
@@ -10,7 +10,8 @@ import LRUCache, { LruCache, CacheStrategies } from './utils/cache';
10
10
  import { Logger } from './utils/logger';
11
11
  import WSClient from './utils/websocket';
12
12
  import { resizeImage } from './utils/image';
13
+ import { getPeriodRange } from './utils/leaderboard';
13
14
  /**
14
15
  * Export utilities
15
16
  */
16
- export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, handleOpenWindow, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, sortByAttr, WSClient, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, CacheStrategies, resizeImage, isPWA };
17
+ export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, handleOpenWindow, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, sortByAttr, WSClient, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, CacheStrategies, resizeImage, isPWA, getPeriodRange };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The period a leaderboard refers to
3
+ */
4
+ export type LeaderboardPeriod = 'week' | 'month' | 'year';
5
+ /**
6
+ * Computes the (inclusive) reputation date range the given period refers to
7
+ * @param period
8
+ */
9
+ export declare function getPeriodRange(period: LeaderboardPeriod): {
10
+ reputed_at_from: string;
11
+ reputed_at_to: string;
12
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Formats the given date as `yyyy-MM-dd` (in the local timezone)
3
+ * @param date
4
+ */
5
+ function formatDate(date) {
6
+ const month = `${date.getMonth() + 1}`.padStart(2, '0');
7
+ const day = `${date.getDate()}`.padStart(2, '0');
8
+ return `${date.getFullYear()}-${month}-${day}`;
9
+ }
10
+ /**
11
+ * Computes the (inclusive) reputation date range the given period refers to
12
+ * @param period
13
+ */
14
+ export function getPeriodRange(period) {
15
+ const now = new Date();
16
+ const year = now.getFullYear();
17
+ const month = now.getMonth();
18
+ const day = now.getDate();
19
+ let from;
20
+ let to;
21
+ switch (period) {
22
+ case 'week': {
23
+ // Weeks start on monday
24
+ const weekDay = (now.getDay() + 6) % 7;
25
+ from = new Date(year, month, day - weekDay);
26
+ to = new Date(year, month, day - weekDay + 6);
27
+ break;
28
+ }
29
+ case 'year':
30
+ from = new Date(year, 0, 1);
31
+ to = new Date(year, 11, 31);
32
+ break;
33
+ default:
34
+ from = new Date(year, month, 1);
35
+ to = new Date(year, month + 1, 0);
36
+ break;
37
+ }
38
+ return { reputed_at_from: formatDate(from), reputed_at_to: formatDate(to) };
39
+ }
package/lib/umd/utils.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see utils.js.LICENSE.txt */
2
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SelfCommunityUtils=t():e.SelfCommunityUtils=t()}(self,()=>(()=>{"use strict";var e={700(e,t){t.__esModule=!0,t.sortByAttr=t.groupBy=t.arraysEqual=void 0,t.arraysEqual=function(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;++n)if(e[n]!==t[n])return!1;return!0},t.groupBy=function(e,t){return e.reduce(function(e,n){var r="function"==typeof t?t(n):n[t];return e.hasOwnProperty(r)||(e[r]=[]),e[r].push(n),e},{})},t.sortByAttr=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!Array.isArray(e))return e;var r=n?function(e,n){return e[t]-n[t]}:function(e,n){return n[t]-e[t]};return e.sort(r)}},401(e,t){t.__esModule=!0,t.loadVersionBrowser=t.isPWA=t.iOS=void 0,t.loadVersionBrowser=function(){if("userAgentData"in navigator){for(var e,t=navigator.userAgentData,n=null,r=0;r<t.brands.length;r++){var o=t.brands[r].brand;if(e=t.brands[r].version,null!==o.match(/opera|chrome|edge|safari|firefox|msie|trident/i)){if(null===o.match(/chrome/i))return{name:o.substr(o.indexOf(" ")+1),version:e};n=e}}if(null!==n)return{name:"chrome",version:n}}var i,a=navigator.userAgent,s=a.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(s[1])?{name:"IE",version:(i=/\brv[ :]+(\d+)/g.exec(a)||[])[1]||""}:"Chrome"===s[1]&&null!=(i=a.match(/\bOPR\/(\d+)/))?{name:"Opera",version:i[1]}:(s=s[2]?[s[1],s[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(i=a.match(/version\/(\d+)/i))&&s.splice(1,1,i[1]),{name:s[0],version:s[1]})},t.iOS=function(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document},t.isPWA=function(){var e=!0===window.navigator.standalone,t=window.matchMedia("(display-mode: standalone)").matches;return e||t}},587(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}t.__esModule=!0,t.default=t.LruCache=t.CacheStrategies=void 0;var i=t.LruCache=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e4;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.values=new Map,this.maxEntries=void 0,this.ssr=void 0,this.maxEntries=t,this.ssr="undefined"==typeof window,this.ssr||(window.__viewSCCache=this.values)},t=[{key:"get",value:function(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{noSsr:!0};return this.values.has(e)?(n=this.values.get(e),this.values.delete(e),this.values.set(e,n)):t&&(n=t,(!this.ssr||!r.noSsr)&&this.values.set(e,n)),n}},{key:"set",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{noSsr:!0};if(!this.ssr||!n.noSsr){if(this.values.size>=this.maxEntries){var r=this.values.keys().next().value;this.values.delete(r)}this.values.set(e,t)}}},{key:"hasKey",value:function(e){return this.values.has(e)}},{key:"delete",value:function(e){this.values.has(e)&&this.values.delete(e)}},{key:"deleteKeys",value:function(e){var t=this;e.forEach(function(e){t.values.has(e)&&t.values.delete(e)})}},{key:"deleteKeysWithPrefix",value:function(e){var t=this;this.values.forEach(function(n,r){r.startsWith(e)&&t.values.delete(r)})}},{key:"clean",value:function(){this.values=new Map}},{key:"evaluate",value:function(){console.log(this.values)}}],t&&r(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}(),a=(t.CacheStrategies=function(e){return e.CACHE_FIRST="Cache-first",e.NETWORK_ONLY="Network-only",e.STALE_WHILE_REVALIDATE="Stale-While-Revalidate",e}({}),new i);t.default=a},500(e,t){t.__esModule=!0,t.resizeImage=void 0,t.resizeImage=function(e){return new Promise(function(t,n){var r=new FileReader;r.onload=function(e){var n=new Image;n.onload=function(e){var r=document.createElement("canvas"),o=1920,i=n.width,a=n.height;i>a?i>o&&(a*=o/i,i=o):a>o&&(i*=o/a,a=o),r.width=i,r.height=a,r.getContext("2d").drawImage(n,0,0,i,a),t(function(e){var t;t=e.split(",")[0].indexOf("base64")>=0?atob(e.split(",")[1]):unescape(e.split(",")[1]);for(var n=e.split(",")[0].split(":")[1].split(";")[0],r=new Uint8Array(t.length),o=0;o<t.length;o++)r[o]=t.charCodeAt(o);return new Blob([r],{type:n})}(r.toDataURL("image/jpeg")))},n.src=e.target.result},r.onerror=n,r.readAsDataURL(e)})}},89(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}t.__esModule=!0,t.LocalStorageDB=void 0,t.LocalStorageDB=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},t=[{key:"set",value:function(e,t){if(this.checkifSupport())try{window.localStorage.setItem(e,t)}catch(e){console.error(e)}else console.error("No support. Use a fallback such as browser cookies or store on the server.")}},{key:"get",value:function(e){try{var t=window.localStorage.getItem(e);return t&&"object"===n(t)?JSON.parse(t):t}catch(e){return null}}},{key:"getAll",value:function(){for(var e=[],t=0;t<window.localStorage.length;t++){var n=localStorage.key(t);e.push(this.get(n))}return e}},{key:"remove",value:function(e){try{window.localStorage.removeItem(e),0==window.localStorage.length&&this.clearAll()}catch(e){console.error(e)}finally{this.get(e)&&(delete window.localStorage[e],0==window.localStorage.length&&this.clearAll())}}},{key:"clearAll",value:function(){try{window.localStorage.clear()}catch(e){console.error(e)}}},{key:"checkifSupport",value:function(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}}],null&&r(e.prototype,null),t&&r(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}()},549(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}t.__esModule=!0,t.Logger=void 0,t.Logger=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},t=[{key:"info",value:function(e,t){console.info("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}},{key:"warn",value:function(e,t){console.warn("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}},{key:"error",value:function(e,t){console.error("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}},{key:"log",value:function(e,t){console.log("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}},{key:"debug",value:function(e,t){console.debug("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}}],null&&r(e.prototype,null),t&&r(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}()},136(e,t){t.__esModule=!0,t.isInteger=function(e){return!isNaN(e)&&parseInt(String(Number(e)))==e&&!isNaN(parseInt(String(e),10))}},294(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e){return"object"===n(e)&&!Array.isArray(e)&&null!==e}t.__esModule=!0,t.isFunc=function(e){return"function"==typeof e},t.isObject=r,t.mergeDeep=function e(t,o){var i=Object.assign({},t);return r(t)&&r(o)&&Object.keys(o).forEach(function(a){var s,c,l;r(o[a])&&a in t?i[a]=e(t[a],o[a]):Object.assign(i,(s={},c=a,l=o[a],(c=function(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}(c))in s?Object.defineProperty(s,c,{value:l,enumerable:!0,configurable:!0,writable:!0}):s[c]=l,s))}),i},t.objectWithoutProperties=function(e,t){var n=e?Object.assign({},e):null;return t.forEach(function(e){n&&e in n&&delete n[e]}),n}},696(e,t){function n(e){var t=document.createElement("textarea");t.value=e,t.style.top="0",t.style.left="0",t.style.position="fixed",document.body.appendChild(t),t.focus(),t.select();try{return document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch(e){return document.body.removeChild(t),Promise.reject(e)}}t.__esModule=!0,t.camelCase=function(e){return e.toLowerCase().replace(/[-_]+/g," ").replace(/[^\w\s]/g,"").replace(/ (.)/g,function(e){return e.toUpperCase()}).replace(/ /g,"")},t.capitalize=function(e){for(var t="",n=e.split(" "),r=0;r<n.length;r++)t+=n[r].substring(0,1).toUpperCase()+n[r].substring(1,n[r].length);return t},t.copyTextToClipboard=function(e){return navigator.clipboard?navigator.clipboard.writeText(e):n(e)},t.fallbackCopyTextToClipboard=n,t.isString=function(e){return"string"==typeof e||e instanceof String},t.random=function(){return(Math.random()+1).toString(36).substring(7)},t.slugify=function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")},t.stripHtml=function(e){return e.replace(/<[^>]*>?/gm,"").trim()}},560(e,t){t.__esModule=!0,t.appendURLSearchParams=function(e,t){var n=e;if(t.length&&n){var r=Object.keys(t[0])[0];n+=(n.split("?")[1]?"&":"?")+"".concat(r,"=").concat(t[0][r]),t.slice(1).map(function(e){var t=Object.keys(e)[0];n+="&".concat(t,"=").concat(e[t])})}return n},t.urlReplacer=t.urlB64ToUint8Array=t.updateQueryStringParameter=t.isValidUrls=t.isValidUrl=t.getQueryStringParameter=t.getDomain=void 0,t.urlReplacer=function(e){return function(t){return function(e,t){for(var n=/\$\(([^)]+)?\)/g,r=n.exec(e);r;)e=e.replace(r[0],t[r[1]]),n.lastIndex=0,r=n.exec(e);return e}(e,t)}},t.getDomain=function(e){var t=e.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);return t&&t[1]?t[1]:""};var n=t.isValidUrl=function(e){return/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(e)};t.isValidUrls=function(e,t){return e.trim().split(t).every(n)},t.urlB64ToUint8Array=function(e){for(var t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),n=window.atob(t),r=new Uint8Array(n.length),o=0;o<n.length;++o)r[o]=n.charCodeAt(o);return r},t.getQueryStringParameter=function(e,t){return e&&t?new URL(e).searchParams.get(t):null},t.updateQueryStringParameter=function(e,t,n){if(e&&t&&n){var r=new RegExp("([?&])"+t+"=.*?(&|$)","i"),o=-1!==e.indexOf("?")?"&":"?";return e.match(r)?e.replace(r,"$1"+t+"="+n+"$2"):e+o+t+"="+n}return e}},206(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}t.__esModule=!0,t.default=void 0,(t.default=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._cfg=void 0,this._ws=void 0,this._timer=void 0,this._attempts=1,this._heartbeatInterval=null,this._missedHeartbeats=0,this.isValidOptions(t)&&(this._cfg=Object.assign({},{heartbeatMsg:null,debug:!1,mustReconnect:!0},t),this.connect())}return t=e,n=[{key:"connect",value:function(){try{if(this._ws&&(this.isConnecting()||this.isConnected()))return void(this._cfg.debug&&console.info("Websocket is connecting or already connected."));"function"==typeof this._cfg.connecting&&this._cfg.connecting(),this._cfg.debug&&console.info("Connecting to ".concat(this._cfg.uri," ...")),this._ws=new WebSocket(this._cfg.uri,this._cfg.protocols),this._ws.onopen=this.onOpen.bind(this),this._ws.onmessage=this.onMessage.bind(this),this._ws.onerror=this.onError.bind(this),this._ws.onclose=this.onClose.bind(this),this._timer=null}catch(e){console.error(e),this.tryToReconnect()}}},{key:"isValidOptions",value:function(e){var t=!1;return e?(e.uri||(console.error("Invalid WSClient Uri options."),t=!0),e&&e.connecting&&"function"!=typeof e.connecting&&(console.error("Invalid WSClient connecting options."),t=!0),e&&e.connected&&"function"!=typeof e.connected&&(console.error("Invalid WSClient connected options."),t=!0),e&&e.receiveMessage&&"function"!=typeof e.receiveMessage&&(console.error("Invalid WSClient receiveMessage options."),t=!0),e&&e.disconnected&&"function"!=typeof e.disconnected&&(console.error("Invalid WSClient connecting options."),t=!0),e&&e.heartbeatMsg&&"string"!=typeof e.heartbeatMsg&&(console.error("Invalid WSClient heartbeatMsg options."),t=!0),e&&e.debug&&"boolean"!=typeof e.debug&&(console.error("Invalid WSClient debug options."),t=!0),!t):(console.error("Invalid WSClient options."),t)}},{key:"tryToReconnect",value:function(){if(this._cfg.mustReconnect&&!this._timer){this._cfg.debug&&console.info("Reconnecting...");var e=this.generateInterval(this._attempts);this._timer=setTimeout(this.reconnect.bind(this),e)}}},{key:"reconnect",value:function(){this._attempts++,this.connect()}},{key:"sendHeartbeat",value:function(){try{if(this._missedHeartbeats++,this._missedHeartbeats>3)throw new Error("Too many missed heartbeats.");this._ws.send(this._cfg.heartbeatMsg)}catch(e){clearInterval(this._heartbeatInterval),this._heartbeatInterval=null,this._cfg.debug&&console.warn("Closing connection. Reason: ".concat(e.message)),this.isClosing()||this.isClosed()||this.close()}}},{key:"onOpen",value:function(){this._cfg.debug&&console.info("Connected!"),this._attempts=1,this._cfg.heartbeatMsg&&null===this._heartbeatInterval&&(this._missedHeartbeats=0,this._heartbeatInterval=setInterval(this.sendHeartbeat.bind(this),5e3)),"function"==typeof this._cfg.connected&&this._cfg.connected()}},{key:"onClose",value:function(e){this._cfg.debug&&console.info("Connection closed!"),"function"==typeof this._cfg.disconnected&&this._cfg.disconnected(e),this.tryToReconnect()}},{key:"onError",value:function(e){this._cfg.debug&&console.error("Websocket connection is broken!"),this._cfg.debug&&console.error(e)}},{key:"onMessage",value:function(e){if(this._cfg.heartbeatMsg&&e.data===this._cfg.heartbeatMsg)this._missedHeartbeats=0;else if("function"==typeof this._cfg.receiveMessage)return this._cfg.receiveMessage(e.data)}},{key:"generateInterval",value:function(e){var t=1e3*(Math.pow(2,e)-1);return t>3e4&&(t=3e4),Math.random()*t}},{key:"sendMessage",value:function(e){this._ws&&this._ws.send(e)}},{key:"getState",value:function(){return this._ws&&this._ws.readyState}},{key:"isConnecting",value:function(){return this._ws&&0===this._ws.readyState}},{key:"isConnected",value:function(){return this._ws&&1===this._ws.readyState}},{key:"isClosing",value:function(){return this._ws&&2===this._ws.readyState}},{key:"isClosed",value:function(){return this._ws&&3===this._ws.readyState}},{key:"close",value:function(){clearInterval(this._heartbeatInterval),this._cfg.mustReconnect=!1,this.isClosing()&&this.isClosed()||(this._ws.close(),this._cfg.debug&&console.error("Websocket closed."))}}],o=[{key:"getInstance",value:function(t){return this._instance=this._instance||new e(t),this._instance}}],n&&r(t.prototype,n),o&&r(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n,o}())._instance=void 0},437(e,t,n){t.__esModule=!0,t.getHighestSafeWindowContext=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n.g.window.self;return t===n.g.window.top||function(){try{return n.g.window.location.hostname!==n.g.window.parent.location.hostname}catch(e){return!0}}()?t:e(t.parent)},t.getWindowHeight=function(){return void 0!==n.g.window?n.g.window.innerHeight:0},t.getWindowWidth=function(){return void 0!==n.g.window?n.g.window.innerWidth:0},t.handleOpenWindow=void 0,t.isClientSideRendering=function(){return"undefined"!=typeof window},t.handleOpenWindow=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"_blank";if(e){var n=window.open(e,t);return n&&n.focus(),n}return null}}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();var r={};return(()=>{var e=r;function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}e.__esModule=!0;var o=n(696);e.capitalize=o.capitalize,e.isString=o.isString,e.stripHtml=o.stripHtml,e.camelCase=o.camelCase,e.copyTextToClipboard=o.copyTextToClipboard,e.fallbackCopyTextToClipboard=o.fallbackCopyTextToClipboard,e.random=o.random,e.slugify=o.slugify;var i=n(560);e.isValidUrl=i.isValidUrl,e.isValidUrls=i.isValidUrls,e.urlReplacer=i.urlReplacer,e.getDomain=i.getDomain,e.appendURLSearchParams=i.appendURLSearchParams,e.urlB64ToUint8Array=i.urlB64ToUint8Array,e.getQueryStringParameter=i.getQueryStringParameter,e.updateQueryStringParameter=i.updateQueryStringParameter;var a=n(437);e.getHighestSafeWindowContext=a.getHighestSafeWindowContext,e.getWindowWidth=a.getWindowWidth,e.getWindowHeight=a.getWindowHeight,e.isClientSideRendering=a.isClientSideRendering,e.handleOpenWindow=a.handleOpenWindow;var s=n(294);e.mergeDeep=s.mergeDeep,e.isObject=s.isObject,e.objectWithoutProperties=s.objectWithoutProperties,e.isFunc=s.isFunc;var c=n(136);e.isInteger=c.isInteger;var l=n(700);e.arraysEqual=l.arraysEqual,e.groupBy=l.groupBy,e.sortByAttr=l.sortByAttr;var u=n(401);e.loadVersionBrowser=u.loadVersionBrowser,e.iOS=u.iOS,e.isPWA=u.isPWA;var f=n(89);e.LocalStorageDB=f.LocalStorageDB;var d=p(n(587));e.LRUCache=d.default,e.LruCache=d.LruCache,e.LruCacheType=d.LruCacheType,e.CacheStrategies=d.CacheStrategies;var h=n(549);e.Logger=h.Logger;var g=p(n(206));e.WSClient=g.default,e.WSClientType=g.WSClientType,e.WSClientPropTypes=g.WSClientPropTypes;var y=n(500);function p(e,n){if("function"==typeof WeakMap)var r=new WeakMap,o=new WeakMap;return(p=function(e,n){if(!n&&e&&e.__esModule)return e;var i,a,s={__proto__:null,default:e};if(null===e||"object"!=t(e)&&"function"!=typeof e)return s;if(i=n?o:r){if(i.has(e))return i.get(e);i.set(e,s)}for(var c in e)"default"!==c&&{}.hasOwnProperty.call(e,c)&&((a=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,c))&&(a.get||a.set)?i(s,c,a):s[c]=e[c]);return s})(e,n)}e.resizeImage=y.resizeImage})(),r})());
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SelfCommunityUtils=t():e.SelfCommunityUtils=t()}(self,()=>(()=>{"use strict";var e={700(e,t){t.__esModule=!0,t.sortByAttr=t.groupBy=t.arraysEqual=void 0,t.arraysEqual=function(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;++n)if(e[n]!==t[n])return!1;return!0},t.groupBy=function(e,t){return e.reduce(function(e,n){var r="function"==typeof t?t(n):n[t];return e.hasOwnProperty(r)||(e[r]=[]),e[r].push(n),e},{})},t.sortByAttr=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!Array.isArray(e))return e;var r=n?function(e,n){return e[t]-n[t]}:function(e,n){return n[t]-e[t]};return e.sort(r)}},401(e,t){t.__esModule=!0,t.loadVersionBrowser=t.isPWA=t.iOS=void 0,t.loadVersionBrowser=function(){if("userAgentData"in navigator){for(var e,t=navigator.userAgentData,n=null,r=0;r<t.brands.length;r++){var o=t.brands[r].brand;if(e=t.brands[r].version,null!==o.match(/opera|chrome|edge|safari|firefox|msie|trident/i)){if(null===o.match(/chrome/i))return{name:o.substr(o.indexOf(" ")+1),version:e};n=e}}if(null!==n)return{name:"chrome",version:n}}var i,a=navigator.userAgent,s=a.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(s[1])?{name:"IE",version:(i=/\brv[ :]+(\d+)/g.exec(a)||[])[1]||""}:"Chrome"===s[1]&&null!=(i=a.match(/\bOPR\/(\d+)/))?{name:"Opera",version:i[1]}:(s=s[2]?[s[1],s[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(i=a.match(/version\/(\d+)/i))&&s.splice(1,1,i[1]),{name:s[0],version:s[1]})},t.iOS=function(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document},t.isPWA=function(){var e=!0===window.navigator.standalone,t=window.matchMedia("(display-mode: standalone)").matches;return e||t}},587(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}t.__esModule=!0,t.default=t.LruCache=t.CacheStrategies=void 0;var i=t.LruCache=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e4;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.values=new Map,this.maxEntries=void 0,this.ssr=void 0,this.maxEntries=t,this.ssr="undefined"==typeof window,this.ssr||(window.__viewSCCache=this.values)},t=[{key:"get",value:function(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{noSsr:!0};return this.values.has(e)?(n=this.values.get(e),this.values.delete(e),this.values.set(e,n)):t&&(n=t,(!this.ssr||!r.noSsr)&&this.values.set(e,n)),n}},{key:"set",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{noSsr:!0};if(!this.ssr||!n.noSsr){if(this.values.size>=this.maxEntries){var r=this.values.keys().next().value;this.values.delete(r)}this.values.set(e,t)}}},{key:"hasKey",value:function(e){return this.values.has(e)}},{key:"delete",value:function(e){this.values.has(e)&&this.values.delete(e)}},{key:"deleteKeys",value:function(e){var t=this;e.forEach(function(e){t.values.has(e)&&t.values.delete(e)})}},{key:"deleteKeysWithPrefix",value:function(e){var t=this;this.values.forEach(function(n,r){r.startsWith(e)&&t.values.delete(r)})}},{key:"clean",value:function(){this.values=new Map}},{key:"evaluate",value:function(){console.log(this.values)}}],t&&r(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}(),a=(t.CacheStrategies=function(e){return e.CACHE_FIRST="Cache-first",e.NETWORK_ONLY="Network-only",e.STALE_WHILE_REVALIDATE="Stale-While-Revalidate",e}({}),new i);t.default=a},500(e,t){t.__esModule=!0,t.resizeImage=void 0,t.resizeImage=function(e){return new Promise(function(t,n){var r=new FileReader;r.onload=function(e){var n=new Image;n.onload=function(e){var r=document.createElement("canvas"),o=1920,i=n.width,a=n.height;i>a?i>o&&(a*=o/i,i=o):a>o&&(i*=o/a,a=o),r.width=i,r.height=a,r.getContext("2d").drawImage(n,0,0,i,a),t(function(e){var t;t=e.split(",")[0].indexOf("base64")>=0?atob(e.split(",")[1]):unescape(e.split(",")[1]);for(var n=e.split(",")[0].split(":")[1].split(";")[0],r=new Uint8Array(t.length),o=0;o<t.length;o++)r[o]=t.charCodeAt(o);return new Blob([r],{type:n})}(r.toDataURL("image/jpeg")))},n.src=e.target.result},r.onerror=n,r.readAsDataURL(e)})}},254(e,t){function n(e){var t="".concat(e.getMonth()+1).padStart(2,"0"),n="".concat(e.getDate()).padStart(2,"0");return"".concat(e.getFullYear(),"-").concat(t,"-").concat(n)}t.__esModule=!0,t.getPeriodRange=function(e){var t,r,o=new Date,i=o.getFullYear(),a=o.getMonth(),s=o.getDate();switch(e){case"week":var c=(o.getDay()+6)%7;t=new Date(i,a,s-c),r=new Date(i,a,s-c+6);break;case"year":t=new Date(i,0,1),r=new Date(i,11,31);break;default:t=new Date(i,a,1),r=new Date(i,a+1,0)}return{reputed_at_from:n(t),reputed_at_to:n(r)}}},89(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}t.__esModule=!0,t.LocalStorageDB=void 0,t.LocalStorageDB=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},t=[{key:"set",value:function(e,t){if(this.checkifSupport())try{window.localStorage.setItem(e,t)}catch(e){console.error(e)}else console.error("No support. Use a fallback such as browser cookies or store on the server.")}},{key:"get",value:function(e){try{var t=window.localStorage.getItem(e);return t&&"object"===n(t)?JSON.parse(t):t}catch(e){return null}}},{key:"getAll",value:function(){for(var e=[],t=0;t<window.localStorage.length;t++){var n=localStorage.key(t);e.push(this.get(n))}return e}},{key:"remove",value:function(e){try{window.localStorage.removeItem(e),0==window.localStorage.length&&this.clearAll()}catch(e){console.error(e)}finally{this.get(e)&&(delete window.localStorage[e],0==window.localStorage.length&&this.clearAll())}}},{key:"clearAll",value:function(){try{window.localStorage.clear()}catch(e){console.error(e)}}},{key:"checkifSupport",value:function(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}}],null&&r(e.prototype,null),t&&r(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}()},549(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}t.__esModule=!0,t.Logger=void 0,t.Logger=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},t=[{key:"info",value:function(e,t){console.info("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}},{key:"warn",value:function(e,t){console.warn("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}},{key:"error",value:function(e,t){console.error("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}},{key:"log",value:function(e,t){console.log("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}},{key:"debug",value:function(e,t){console.debug("%c[".concat(e,"]"),"color:#008080"," ".concat(t))}}],null&&r(e.prototype,null),t&&r(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}()},136(e,t){t.__esModule=!0,t.isInteger=function(e){return!isNaN(e)&&parseInt(String(Number(e)))==e&&!isNaN(parseInt(String(e),10))}},294(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e){return"object"===n(e)&&!Array.isArray(e)&&null!==e}t.__esModule=!0,t.isFunc=function(e){return"function"==typeof e},t.isObject=r,t.mergeDeep=function e(t,o){var i=Object.assign({},t);return r(t)&&r(o)&&Object.keys(o).forEach(function(a){var s,c,l;r(o[a])&&a in t?i[a]=e(t[a],o[a]):Object.assign(i,(s={},c=a,l=o[a],(c=function(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}(c))in s?Object.defineProperty(s,c,{value:l,enumerable:!0,configurable:!0,writable:!0}):s[c]=l,s))}),i},t.objectWithoutProperties=function(e,t){var n=e?Object.assign({},e):null;return t.forEach(function(e){n&&e in n&&delete n[e]}),n}},696(e,t){function n(e){var t=document.createElement("textarea");t.value=e,t.style.top="0",t.style.left="0",t.style.position="fixed",document.body.appendChild(t),t.focus(),t.select();try{return document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch(e){return document.body.removeChild(t),Promise.reject(e)}}t.__esModule=!0,t.camelCase=function(e){return e.toLowerCase().replace(/[-_]+/g," ").replace(/[^\w\s]/g,"").replace(/ (.)/g,function(e){return e.toUpperCase()}).replace(/ /g,"")},t.capitalize=function(e){for(var t="",n=e.split(" "),r=0;r<n.length;r++)t+=n[r].substring(0,1).toUpperCase()+n[r].substring(1,n[r].length);return t},t.copyTextToClipboard=function(e){return navigator.clipboard?navigator.clipboard.writeText(e):n(e)},t.fallbackCopyTextToClipboard=n,t.isString=function(e){return"string"==typeof e||e instanceof String},t.random=function(){return(Math.random()+1).toString(36).substring(7)},t.slugify=function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")},t.stripHtml=function(e){return e.replace(/<[^>]*>?/gm,"").trim()}},560(e,t){t.__esModule=!0,t.appendURLSearchParams=function(e,t){var n=e;if(t.length&&n){var r=Object.keys(t[0])[0];n+=(n.split("?")[1]?"&":"?")+"".concat(r,"=").concat(t[0][r]),t.slice(1).map(function(e){var t=Object.keys(e)[0];n+="&".concat(t,"=").concat(e[t])})}return n},t.urlReplacer=t.urlB64ToUint8Array=t.updateQueryStringParameter=t.isValidUrls=t.isValidUrl=t.getQueryStringParameter=t.getDomain=void 0,t.urlReplacer=function(e){return function(t){return function(e,t){for(var n=/\$\(([^)]+)?\)/g,r=n.exec(e);r;)e=e.replace(r[0],t[r[1]]),n.lastIndex=0,r=n.exec(e);return e}(e,t)}},t.getDomain=function(e){var t=e.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);return t&&t[1]?t[1]:""};var n=t.isValidUrl=function(e){return/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(e)};t.isValidUrls=function(e,t){return e.trim().split(t).every(n)},t.urlB64ToUint8Array=function(e){for(var t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),n=window.atob(t),r=new Uint8Array(n.length),o=0;o<n.length;++o)r[o]=n.charCodeAt(o);return r},t.getQueryStringParameter=function(e,t){return e&&t?new URL(e).searchParams.get(t):null},t.updateQueryStringParameter=function(e,t,n){if(e&&t&&n){var r=new RegExp("([?&])"+t+"=.*?(&|$)","i"),o=-1!==e.indexOf("?")?"&":"?";return e.match(r)?e.replace(r,"$1"+t+"="+n+"$2"):e+o+t+"="+n}return e}},206(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function o(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}t.__esModule=!0,t.default=void 0,(t.default=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._cfg=void 0,this._ws=void 0,this._timer=void 0,this._attempts=1,this._heartbeatInterval=null,this._missedHeartbeats=0,this.isValidOptions(t)&&(this._cfg=Object.assign({},{heartbeatMsg:null,debug:!1,mustReconnect:!0},t),this.connect())}return t=e,n=[{key:"connect",value:function(){try{if(this._ws&&(this.isConnecting()||this.isConnected()))return void(this._cfg.debug&&console.info("Websocket is connecting or already connected."));"function"==typeof this._cfg.connecting&&this._cfg.connecting(),this._cfg.debug&&console.info("Connecting to ".concat(this._cfg.uri," ...")),this._ws=new WebSocket(this._cfg.uri,this._cfg.protocols),this._ws.onopen=this.onOpen.bind(this),this._ws.onmessage=this.onMessage.bind(this),this._ws.onerror=this.onError.bind(this),this._ws.onclose=this.onClose.bind(this),this._timer=null}catch(e){console.error(e),this.tryToReconnect()}}},{key:"isValidOptions",value:function(e){var t=!1;return e?(e.uri||(console.error("Invalid WSClient Uri options."),t=!0),e&&e.connecting&&"function"!=typeof e.connecting&&(console.error("Invalid WSClient connecting options."),t=!0),e&&e.connected&&"function"!=typeof e.connected&&(console.error("Invalid WSClient connected options."),t=!0),e&&e.receiveMessage&&"function"!=typeof e.receiveMessage&&(console.error("Invalid WSClient receiveMessage options."),t=!0),e&&e.disconnected&&"function"!=typeof e.disconnected&&(console.error("Invalid WSClient connecting options."),t=!0),e&&e.heartbeatMsg&&"string"!=typeof e.heartbeatMsg&&(console.error("Invalid WSClient heartbeatMsg options."),t=!0),e&&e.debug&&"boolean"!=typeof e.debug&&(console.error("Invalid WSClient debug options."),t=!0),!t):(console.error("Invalid WSClient options."),t)}},{key:"tryToReconnect",value:function(){if(this._cfg.mustReconnect&&!this._timer){this._cfg.debug&&console.info("Reconnecting...");var e=this.generateInterval(this._attempts);this._timer=setTimeout(this.reconnect.bind(this),e)}}},{key:"reconnect",value:function(){this._attempts++,this.connect()}},{key:"sendHeartbeat",value:function(){try{if(this._missedHeartbeats++,this._missedHeartbeats>3)throw new Error("Too many missed heartbeats.");this._ws.send(this._cfg.heartbeatMsg)}catch(e){clearInterval(this._heartbeatInterval),this._heartbeatInterval=null,this._cfg.debug&&console.warn("Closing connection. Reason: ".concat(e.message)),this.isClosing()||this.isClosed()||this.close()}}},{key:"onOpen",value:function(){this._cfg.debug&&console.info("Connected!"),this._attempts=1,this._cfg.heartbeatMsg&&null===this._heartbeatInterval&&(this._missedHeartbeats=0,this._heartbeatInterval=setInterval(this.sendHeartbeat.bind(this),5e3)),"function"==typeof this._cfg.connected&&this._cfg.connected()}},{key:"onClose",value:function(e){this._cfg.debug&&console.info("Connection closed!"),"function"==typeof this._cfg.disconnected&&this._cfg.disconnected(e),this.tryToReconnect()}},{key:"onError",value:function(e){this._cfg.debug&&console.error("Websocket connection is broken!"),this._cfg.debug&&console.error(e)}},{key:"onMessage",value:function(e){if(this._cfg.heartbeatMsg&&e.data===this._cfg.heartbeatMsg)this._missedHeartbeats=0;else if("function"==typeof this._cfg.receiveMessage)return this._cfg.receiveMessage(e.data)}},{key:"generateInterval",value:function(e){var t=1e3*(Math.pow(2,e)-1);return t>3e4&&(t=3e4),Math.random()*t}},{key:"sendMessage",value:function(e){this._ws&&this._ws.send(e)}},{key:"getState",value:function(){return this._ws&&this._ws.readyState}},{key:"isConnecting",value:function(){return this._ws&&0===this._ws.readyState}},{key:"isConnected",value:function(){return this._ws&&1===this._ws.readyState}},{key:"isClosing",value:function(){return this._ws&&2===this._ws.readyState}},{key:"isClosed",value:function(){return this._ws&&3===this._ws.readyState}},{key:"close",value:function(){clearInterval(this._heartbeatInterval),this._cfg.mustReconnect=!1,this.isClosing()&&this.isClosed()||(this._ws.close(),this._cfg.debug&&console.error("Websocket closed."))}}],o=[{key:"getInstance",value:function(t){return this._instance=this._instance||new e(t),this._instance}}],n&&r(t.prototype,n),o&&r(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n,o}())._instance=void 0},437(e,t,n){t.__esModule=!0,t.getHighestSafeWindowContext=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n.g.window.self;return t===n.g.window.top||function(){try{return n.g.window.location.hostname!==n.g.window.parent.location.hostname}catch(e){return!0}}()?t:e(t.parent)},t.getWindowHeight=function(){return void 0!==n.g.window?n.g.window.innerHeight:0},t.getWindowWidth=function(){return void 0!==n.g.window?n.g.window.innerWidth:0},t.handleOpenWindow=void 0,t.isClientSideRendering=function(){return"undefined"!=typeof window},t.handleOpenWindow=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"_blank";if(e){var n=window.open(e,t);return n&&n.focus(),n}return null}}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();var r={};return(()=>{var e=r;function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}e.__esModule=!0;var o=n(696);e.capitalize=o.capitalize,e.isString=o.isString,e.stripHtml=o.stripHtml,e.camelCase=o.camelCase,e.copyTextToClipboard=o.copyTextToClipboard,e.fallbackCopyTextToClipboard=o.fallbackCopyTextToClipboard,e.random=o.random,e.slugify=o.slugify;var i=n(560);e.isValidUrl=i.isValidUrl,e.isValidUrls=i.isValidUrls,e.urlReplacer=i.urlReplacer,e.getDomain=i.getDomain,e.appendURLSearchParams=i.appendURLSearchParams,e.urlB64ToUint8Array=i.urlB64ToUint8Array,e.getQueryStringParameter=i.getQueryStringParameter,e.updateQueryStringParameter=i.updateQueryStringParameter;var a=n(437);e.getHighestSafeWindowContext=a.getHighestSafeWindowContext,e.getWindowWidth=a.getWindowWidth,e.getWindowHeight=a.getWindowHeight,e.isClientSideRendering=a.isClientSideRendering,e.handleOpenWindow=a.handleOpenWindow;var s=n(294);e.mergeDeep=s.mergeDeep,e.isObject=s.isObject,e.objectWithoutProperties=s.objectWithoutProperties,e.isFunc=s.isFunc;var c=n(136);e.isInteger=c.isInteger;var l=n(700);e.arraysEqual=l.arraysEqual,e.groupBy=l.groupBy,e.sortByAttr=l.sortByAttr;var u=n(401);e.loadVersionBrowser=u.loadVersionBrowser,e.iOS=u.iOS,e.isPWA=u.isPWA;var f=n(89);e.LocalStorageDB=f.LocalStorageDB;var d=v(n(587));e.LRUCache=d.default,e.LruCache=d.LruCache,e.LruCacheType=d.LruCacheType,e.CacheStrategies=d.CacheStrategies;var h=n(549);e.Logger=h.Logger;var g=v(n(206));e.WSClient=g.default,e.WSClientType=g.WSClientType,e.WSClientPropTypes=g.WSClientPropTypes;var y=n(500);e.resizeImage=y.resizeImage;var p=n(254);function v(e,n){if("function"==typeof WeakMap)var r=new WeakMap,o=new WeakMap;return(v=function(e,n){if(!n&&e&&e.__esModule)return e;var i,a,s={__proto__:null,default:e};if(null===e||"object"!=t(e)&&"function"!=typeof e)return s;if(i=n?o:r){if(i.has(e))return i.get(e);i.set(e,s)}for(var c in e)"default"!==c&&{}.hasOwnProperty.call(e,c)&&((a=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,c))&&(a.get||a.set)?i(s,c,a):s[c]=e[c]);return s})(e,n)}e.getPeriodRange=p.getPeriodRange,e.LeaderboardPeriod=p.LeaderboardPeriod})(),r})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfcommunity/utils",
3
- "version": "1.0.19-alpha.0",
3
+ "version": "1.1.0-alpha.0",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "main": "./lib/cjs/index.js",
@@ -100,5 +100,5 @@
100
100
  "bugs": {
101
101
  "url": "https://github.com/selfcommunity/community-js/issues"
102
102
  },
103
- "gitHead": "24e9da465088d02e5be404618b7ab730f0dfd62b"
103
+ "gitHead": "80e5fcbf2d28754ccec09692726d1336a3f9a985"
104
104
  }