@selfcommunity/utils 0.2.64-payments.247 → 0.2.64-react-17.0.1.107
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/lib/umd/utils.js +1 -1
- package/package.json +2 -2
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={615:(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)}},391:(e,t)=>{t.__esModule=!0,t.loadVersionBrowser=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}},614:(e,t)=>{function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}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,r.key,r)}}t.__esModule=!0,t.default=t.LruCache=t.CacheStrategies=void 0;var o,i=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e4;n(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},o=this.values.has(e);return o?(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}();t.LruCache=i,t.CacheStrategies=o,function(e){e.CACHE_FIRST="Cache-first",e.NETWORK_ONLY="Network-only",e.STALE_WHILE_REVALIDATE="Stale-While-Revalidate"}(o||(t.CacheStrategies=o={}));var a=new i;t.default=a},501:(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)}))}},925:(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,r.key,r)}}t.__esModule=!0,t.LocalStorageDB=void 0;var o=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}();t.LocalStorageDB=o},184:(e,t)=>{function n(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,r.key,r)}}t.__esModule=!0,t.Logger=void 0;var r=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&&n(e.prototype,null),t&&n(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();t.Logger=r},829:(e,t)=>{t.__esModule=!0,t.isInteger=function(e){return!isNaN(e)&&parseInt(String(Number(e)))==e&&!isNaN(parseInt(String(e),10))}},378:(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,n){var o=Object.assign({},t);return r(t)&&r(n)&&Object.keys(n).forEach((function(i){r(n[i])&&i in t?o[i]=e(t[i],n[i]):Object.assign(o,function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}({},i,n[i]))})),o},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}},153:(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()}},449:(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=function(e){return/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(e)};t.isValidUrl=n,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}},250:(e,t)=>{function n(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,r.key,r)}}t.__esModule=!0,t.default=void 0;var r=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,o=[{key:"getInstance",value:function(t){return this._instance=this._instance||new e(t),this._instance}}],(r=[{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."))}}])&&n(t.prototype,r),o&&n(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,o}();t.default=r,r._instance=void 0},138:(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||r()?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};var r=function(){try{return n.g.window.location.hostname!==n.g.window.parent.location.hostname}catch(e){return!0}};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(153);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(449);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(138);e.getHighestSafeWindowContext=a.getHighestSafeWindowContext,e.getWindowWidth=a.getWindowWidth,e.getWindowHeight=a.getWindowHeight,e.isClientSideRendering=a.isClientSideRendering,e.handleOpenWindow=a.handleOpenWindow;var s=n(378);e.mergeDeep=s.mergeDeep,e.isObject=s.isObject,e.objectWithoutProperties=s.objectWithoutProperties,e.isFunc=s.isFunc;var c=n(829);e.isInteger=c.isInteger;var l=n(615);e.arraysEqual=l.arraysEqual,e.groupBy=l.groupBy,e.sortByAttr=l.sortByAttr;var u=n(391);e.loadVersionBrowser=u.loadVersionBrowser,e.iOS=u.iOS;var f=n(925);e.LocalStorageDB=f.LocalStorageDB;var d=y(n(614));e.LRUCache=d.default,e.LruCache=d.LruCache,e.LruCacheType=d.LruCacheType,e.CacheStrategies=d.CacheStrategies;var h=n(184);e.Logger=h.Logger;var g=y(n(250));e.WSClient=g.default,e.WSClientType=g.WSClientType,e.WSClientPropTypes=g.WSClientPropTypes;var p=n(501);function v(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(v=function(e){return e?n:t})(e)}function y(e,n){if(!n&&e&&e.__esModule)return e;if(null===e||"object"!==t(e)&&"function"!=typeof e)return{default:e};var r=v(n);if(r&&r.has(e))return r.get(e);var o={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if("default"!==a&&Object.prototype.hasOwnProperty.call(e,a)){var s=i?Object.getOwnPropertyDescriptor(e,a):null;s&&(s.get||s.set)?Object.defineProperty(o,a,s):o[a]=e[a]}return o.default=e,r&&r.set(e,o),o}e.resizeImage=p.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={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}()},136:(e,t)=>{t.__esModule=!0,t.isInteger=function(e){return!isNaN(e)&&parseInt(String(Number(e)))==e&&!isNaN(parseInt(String(e),10))}},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},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}},401:(e,t)=>{t.__esModule=!0,t.loadVersionBrowser=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}},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||r()?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};var r=function(){try{return n.g.window.location.hostname!==n.g.window.parent.location.hostname}catch(e){return!0}};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}},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)})}},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}()},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}},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},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()}},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)}}},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;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})());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfcommunity/utils",
|
|
3
|
-
"version": "0.2.64-
|
|
3
|
+
"version": "0.2.64-react-17.0.1.107+357f84a57",
|
|
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": "
|
|
103
|
+
"gitHead": "357f84a579da81caeeb311f00f1c479bd1283629"
|
|
104
104
|
}
|