New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@selfcommunity/utils

Package Overview
Dependencies
Maintainers
1
Versions
549
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@selfcommunity/utils - npm Package Compare versions

Comparing version

to
0.1.5-alpha.0

lib/cjs/utils/browser.js

36

lib/cjs/index.js

@@ -11,2 +11,5 @@ "use strict";

exports.camelCase = _string.camelCase;
exports.copyTextToClipboard = _string.copyTextToClipboard;
exports.fallbackCopyTextToClipboard = _string.fallbackCopyTextToClipboard;
exports.random = _string.random;

@@ -18,2 +21,33 @@ var _url = require("./utils/url");

exports.urlReplacer = _url.urlReplacer;
exports.getDomain = _url.getDomain;
exports.getDomain = _url.getDomain;
exports.appendURLSearchParams = _url.appendURLSearchParams;
exports.urlB64ToUint8Array = _url.urlB64ToUint8Array;
var _window = require("./utils/window");
exports.getHighestSafeWindowContext = _window.getHighestSafeWindowContext;
exports.getWindowWidth = _window.getWindowWidth;
exports.getWindowHeight = _window.getWindowHeight;
var _object = require("./utils/object");
exports.mergeDeep = _object.mergeDeep;
exports.isObject = _object.isObject;
var _browser = require("./utils/browser");
exports.loadVersionBrowser = _browser.loadVersionBrowser;
var _logger = require("./utils/logger");
exports.Logger = _logger.Logger;
var _websocket = _interopRequireWildcard(require("./utils/websocket"));
exports.WSClient = _websocket.default;
exports.WSClientType = _websocket.WSClientType;
exports.WSClientPropTypes = _websocket.WSClientPropTypes;
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

@@ -6,3 +6,6 @@ "use strict";

exports.capitalize = capitalize;
exports.copyTextToClipboard = copyTextToClipboard;
exports.fallbackCopyTextToClipboard = fallbackCopyTextToClipboard;
exports.isString = isString;
exports.random = random;
exports.stripHtml = stripHtml;

@@ -58,2 +61,56 @@

return str.replace(/<[^>]*>?/gm, '').trim();
}
function random() {
return (Math.random() + 1).toString(36).substring(7);
}
/**
* Fallback if navigator.clipboard doensn't exist
* @param text
* @returns {Promise<void>}
*/
function fallbackCopyTextToClipboard(text) {
let textArea = document.createElement('textarea');
textArea.value = text; // Avoid scrolling to bottom
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.position = 'fixed';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
document.body.removeChild(textArea);
return Promise.resolve();
} catch (err) {
document.body.removeChild(textArea);
return Promise.reject(err);
}
}
/**
* Copy text to clipboard
* @param text
* @returns {Promise<void>}
*
* Ex.
* copyTextToClipboard(text).then(
* function () {
* console.log('Async: Copying to clipboard was successful!');
* },
* function (err) {
* console.error('Async: Could not copy text: ', err);
* });
*/
function copyTextToClipboard(text) {
if (!navigator.clipboard) {
return fallbackCopyTextToClipboard(text);
}
return navigator.clipboard.writeText(text);
}
"use strict";
exports.__esModule = true;
exports.urlReplacer = exports.isValidUrls = exports.isValidUrl = exports.getDomain = void 0;
exports.appendURLSearchParams = appendURLSearchParams;
exports.urlReplacer = exports.urlB64ToUint8Array = exports.isValidUrls = exports.isValidUrl = exports.getDomain = void 0;

@@ -69,3 +70,44 @@ /**

};
/**
* Append params
* @param baseUrl
* @param queryParams
*/
exports.isValidUrls = isValidUrls;
exports.isValidUrls = isValidUrls;
function appendURLSearchParams(baseUrl, queryParams) {
let _url = baseUrl;
if (queryParams.length && _url) {
const key = Object.keys(queryParams[0])[0];
_url += (_url.split('?')[1] ? '&' : '?') + `${key}=${queryParams[0][key]}`;
queryParams.slice(1).map(p => {
const key = Object.keys(p)[0];
_url += `&${key}=${p[key]}`;
});
}
return _url;
}
/**
* Take the application server's public key, which is Base64 URL-safe encoded,
* and convert it to a UInt8Array, because this is the expected input of the subscribe()
*/
const urlB64ToUint8Array = base64String => {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
};
exports.urlB64ToUint8Array = urlB64ToUint8Array;

11

lib/esm/index.d.ts

@@ -1,7 +0,12 @@

import { capitalize, isString, stripHtml, camelCase } from './utils/string';
import { isValidUrl, isValidUrls, urlReplacer, getDomain } from './utils/url';
import { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random } from './utils/string';
import { isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array } from './utils/url';
import { getHighestSafeWindowContext, getWindowWidth, getWindowHeight } from './utils/window';
import { mergeDeep, isObject } from './utils/object';
import { loadVersionBrowser } from './utils/browser';
import { Logger } from './utils/logger';
import WSClient, { WSClientType, WSClientPropTypes } from './utils/websocket';
/**
* Export all utilities
*/
export { capitalize, isString, stripHtml, camelCase, isValidUrl, isValidUrls, urlReplacer, getDomain };
export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, Logger, mergeDeep, isObject, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser };
//# sourceMappingURL=index.d.ts.map

@@ -11,2 +11,5 @@ "use strict";

exports.camelCase = _string.camelCase;
exports.copyTextToClipboard = _string.copyTextToClipboard;
exports.fallbackCopyTextToClipboard = _string.fallbackCopyTextToClipboard;
exports.random = _string.random;

@@ -18,2 +21,33 @@ var _url = require("./utils/url");

exports.urlReplacer = _url.urlReplacer;
exports.getDomain = _url.getDomain;
exports.getDomain = _url.getDomain;
exports.appendURLSearchParams = _url.appendURLSearchParams;
exports.urlB64ToUint8Array = _url.urlB64ToUint8Array;
var _window = require("./utils/window");
exports.getHighestSafeWindowContext = _window.getHighestSafeWindowContext;
exports.getWindowWidth = _window.getWindowWidth;
exports.getWindowHeight = _window.getWindowHeight;
var _object = require("./utils/object");
exports.mergeDeep = _object.mergeDeep;
exports.isObject = _object.isObject;
var _browser = require("./utils/browser");
exports.loadVersionBrowser = _browser.loadVersionBrowser;
var _logger = require("./utils/logger");
exports.Logger = _logger.Logger;
var _websocket = _interopRequireWildcard(require("./utils/websocket"));
exports.WSClient = _websocket.default;
exports.WSClientType = _websocket.WSClientType;
exports.WSClientPropTypes = _websocket.WSClientPropTypes;
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

@@ -21,2 +21,24 @@ /**

export declare function stripHtml(str: string): string;
export declare function random(): string;
/**
* Fallback if navigator.clipboard doensn't exist
* @param text
* @returns {Promise<void>}
*/
export declare function fallbackCopyTextToClipboard(text: any): Promise<void>;
/**
* Copy text to clipboard
* @param text
* @returns {Promise<void>}
*
* Ex.
* copyTextToClipboard(text).then(
* function () {
* console.log('Async: Copying to clipboard was successful!');
* },
* function (err) {
* console.error('Async: Could not copy text: ', err);
* });
*/
export declare function copyTextToClipboard(text: any): Promise<void>;
//# sourceMappingURL=string.d.ts.map

@@ -6,3 +6,6 @@ "use strict";

exports.capitalize = capitalize;
exports.copyTextToClipboard = copyTextToClipboard;
exports.fallbackCopyTextToClipboard = fallbackCopyTextToClipboard;
exports.isString = isString;
exports.random = random;
exports.stripHtml = stripHtml;

@@ -58,2 +61,56 @@

return str.replace(/<[^>]*>?/gm, '').trim();
}
function random() {
return (Math.random() + 1).toString(36).substring(7);
}
/**
* Fallback if navigator.clipboard doensn't exist
* @param text
* @returns {Promise<void>}
*/
function fallbackCopyTextToClipboard(text) {
let textArea = document.createElement('textarea');
textArea.value = text; // Avoid scrolling to bottom
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.position = 'fixed';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
document.body.removeChild(textArea);
return Promise.resolve();
} catch (err) {
document.body.removeChild(textArea);
return Promise.reject(err);
}
}
/**
* Copy text to clipboard
* @param text
* @returns {Promise<void>}
*
* Ex.
* copyTextToClipboard(text).then(
* function () {
* console.log('Async: Copying to clipboard was successful!');
* },
* function (err) {
* console.error('Async: Could not copy text: ', err);
* });
*/
function copyTextToClipboard(text) {
if (!navigator.clipboard) {
return fallbackCopyTextToClipboard(text);
}
return navigator.clipboard.writeText(text);
}

@@ -22,2 +22,13 @@ /**

export declare const isValidUrls: (value: string, delimiter: string) => boolean;
/**
* Append params
* @param baseUrl
* @param queryParams
*/
export declare function appendURLSearchParams(baseUrl: string, queryParams: Record<string, string | number>[]): string;
/**
* Take the application server's public key, which is Base64 URL-safe encoded,
* and convert it to a UInt8Array, because this is the expected input of the subscribe()
*/
export declare const urlB64ToUint8Array: (base64String: any) => Uint8Array;
//# sourceMappingURL=url.d.ts.map
"use strict";
exports.__esModule = true;
exports.urlReplacer = exports.isValidUrls = exports.isValidUrl = exports.getDomain = void 0;
exports.appendURLSearchParams = appendURLSearchParams;
exports.urlReplacer = exports.urlB64ToUint8Array = exports.isValidUrls = exports.isValidUrl = exports.getDomain = void 0;

@@ -69,3 +70,44 @@ /**

};
/**
* Append params
* @param baseUrl
* @param queryParams
*/
exports.isValidUrls = isValidUrls;
exports.isValidUrls = isValidUrls;
function appendURLSearchParams(baseUrl, queryParams) {
let _url = baseUrl;
if (queryParams.length && _url) {
const key = Object.keys(queryParams[0])[0];
_url += (_url.split('?')[1] ? '&' : '?') + `${key}=${queryParams[0][key]}`;
queryParams.slice(1).map(p => {
const key = Object.keys(p)[0];
_url += `&${key}=${p[key]}`;
});
}
return _url;
}
/**
* Take the application server's public key, which is Base64 URL-safe encoded,
* and convert it to a UInt8Array, because this is the expected input of the subscribe()
*/
const urlB64ToUint8Array = base64String => {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
};
exports.urlB64ToUint8Array = urlB64ToUint8Array;
/*! For license information please see utils.js.LICENSE.txt */
!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={884:(e,t)=>{t.__esModule=!0,t.camelCase=function(e){return e.toLowerCase().replace(/[-_]+/g," ").replace(/[^\w\s]/g,"").replace(/ (.)/g,(e=>e.toUpperCase())).replace(/ /g,"")},t.capitalize=function(e){let t="",r=e.split(" ");for(let e=0;e<r.length;e++)t+=r[e].substring(0,1).toUpperCase()+r[e].substring(1,r[e].length);return t},t.isString=function(e){return"string"==typeof e||e instanceof String},t.stripHtml=function(e){return e.replace(/<[^>]*>?/gm,"").trim()}},735:(e,t)=>{t.__esModule=!0,t.urlReplacer=t.isValidUrls=t.isValidUrl=t.getDomain=void 0,t.urlReplacer=e=>t=>function(e,t){const r=/\$\(([^)]+)?\)/g;let i=r.exec(e);for(;i;)e=e.replace(i[0],t[i[1]]),r.lastIndex=0,i=r.exec(e);return e}(e,t),t.getDomain=e=>{const t=e.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);return t&&t[1]?t[1]:""};const r=e=>/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(e);t.isValidUrl=r,t.isValidUrls=(e,t)=>e.trim().split(t).every(r)}},t={};function r(i){var l=t[i];if(void 0!==l)return l.exports;var s=t[i]={exports:{}};return e[i](s,s.exports,r),s.exports}var i={};return(()=>{var e=i;e.__esModule=!0;var t=r(884);e.capitalize=t.capitalize,e.isString=t.isString,e.stripHtml=t.stripHtml,e.camelCase=t.camelCase;var l=r(735);e.isValidUrl=l.isValidUrl,e.isValidUrls=l.isValidUrls,e.urlReplacer=l.urlReplacer,e.getDomain=l.getDomain})(),i})()));
!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={285:(e,t)=>{t.__esModule=!0,t.loadVersionBrowser=void 0,t.loadVersionBrowser=()=>{if("userAgentData"in navigator){const e=navigator.userAgentData;let t,n,o=null;for(let i=0;i<e.brands.length;i++){const r=e.brands[i].brand;if(n=e.brands[i].version,null!==r.match(/opera|chrome|edge|safari|firefox|msie|trident/i)){if(null===r.match(/chrome/i))return t=r.substr(r.indexOf(" ")+1),{name:t,version:n};o=n}}if(null!==o)return{name:"chrome",version:o}}let e,t=navigator.userAgent,n=t.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(n[1])?(e=/\brv[ :]+(\d+)/g.exec(t)||[],{name:"IE",version:e[1]||""}):"Chrome"===n[1]&&(e=t.match(/\bOPR\/(\d+)/),null!=e)?{name:"Opera",version:e[1]}:(n=n[2]?[n[1],n[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(e=t.match(/version\/(\d+)/i))&&n.splice(1,1,e[1]),{name:n[0],version:n[1]})}},502:(e,t)=>{t.__esModule=!0,t.Logger=void 0,t.Logger=class{static info(e,t){console.info(`%c[${e}]`,"color:#008080",` ${t}`)}static warn(e,t){console.warn(`%c[${e}]`,"color:#008080",` ${t}`)}static error(e,t){console.error(`%c[${e}]`,"color:#008080",` ${t}`)}static log(e,t){console.log(`%c[${e}]`,"color:#008080",` ${t}`)}static debug(e,t){console.debug(`%c[${e}]`,"color:#008080",` ${t}`)}}},297:(e,t)=>{function n(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e}t.__esModule=!0,t.isObject=n,t.mergeDeep=function e(t,o){let i=Object.assign({},t);return n(t)&&n(o)&&Object.keys(o).forEach((r=>{n(o[r])?r in t?i[r]=e(t[r],o[r]):Object.assign(i,{[r]:o[r]}):Object.assign(i,{[r]:o[r]})})),i}},884:(e,t)=>{function n(e){let 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,(e=>e.toUpperCase())).replace(/ /g,"")},t.capitalize=function(e){let t="",n=e.split(" ");for(let e=0;e<n.length;e++)t+=n[e].substring(0,1).toUpperCase()+n[e].substring(1,n[e].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.stripHtml=function(e){return e.replace(/<[^>]*>?/gm,"").trim()}},735:(e,t)=>{t.__esModule=!0,t.appendURLSearchParams=function(e,t){let n=e;if(t.length&&n){const e=Object.keys(t[0])[0];n+=(n.split("?")[1]?"&":"?")+`${e}=${t[0][e]}`,t.slice(1).map((e=>{const t=Object.keys(e)[0];n+=`&${t}=${e[t]}`}))}return n},t.urlReplacer=t.urlB64ToUint8Array=t.isValidUrls=t.isValidUrl=t.getDomain=void 0,t.urlReplacer=e=>t=>function(e,t){const n=/\$\(([^)]+)?\)/g;let o=n.exec(e);for(;o;)e=e.replace(o[0],t[o[1]]),n.lastIndex=0,o=n.exec(e);return e}(e,t),t.getDomain=e=>{const t=e.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);return t&&t[1]?t[1]:""};const n=e=>/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(e);t.isValidUrl=n,t.isValidUrls=(e,t)=>e.trim().split(t).every(n),t.urlB64ToUint8Array=e=>{const t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),n=window.atob(t),o=new Uint8Array(n.length);for(let e=0;e<n.length;++e)o[e]=n.charCodeAt(e);return o}},507:(e,t)=>{t.__esModule=!0,t.default=void 0;class n{constructor(e){this._attempts=1,this._heartbeatInterval=null,this._missedHeartbeats=0,this.isValidOptions(e)&&(this._cfg=Object.assign({},{heartbeatMsg:null,debug:!1,mustReconnect:!0},e),this.connect())}static getInstance(e){return this._instance=this._instance||new n(e),this._instance}connect(){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 ${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()}}isValidOptions(e){let 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)}tryToReconnect(){if(this._cfg.mustReconnect&&!this._timer){this._cfg.debug&&console.info("Reconnecting...");let e=this.generateInteval(this._attempts);this._timer=setTimeout(this.reconnect.bind(this),e)}}reconnect(){this._attempts++,this.connect()}sendHeartbeat(){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: ${e.message}`),this.isClosing()||this.isClosed()||this.close()}}onOpen(){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()}onClose(e){this._cfg.debug&&console.info("Connection closed!"),"function"==typeof this._cfg.disconnected&&this._cfg.disconnected(e),this.tryToReconnect()}onError(e){this._cfg.debug&&console.error("Websocket connection is broken!"),this._cfg.debug&&console.error(e)}onMessage(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)}generateInteval(e){let t=1e3*(Math.pow(2,e)-1);return t>3e4&&(t=3e4),Math.random()*t}sendMessage(e){this._ws&&this._ws.send(e)}getState(){return this._ws&&this._ws.readyState}isConnecting(){return this._ws&&0===this._ws.readyState}isConnected(){return this._ws&&1===this._ws.readyState}isClosing(){return this._ws&&2===this._ws.readyState}isClosed(){return this._ws&&3===this._ws.readyState}close(){clearInterval(this._heartbeatInterval),this._cfg.mustReconnect=!1,this.isClosing()&&this.isClosed()||(this._ws.close(),this._cfg.debug&&console.error("Websocket closed."))}}t.default=n},449:(e,t,n)=>{t.__esModule=!0,t.getHighestSafeWindowContext=function e(t=n.g.window.self){return t===n.g.window.top||(()=>{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={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,n),r.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 o={};return(()=>{var e=o;e.__esModule=!0;var t=n(884);e.capitalize=t.capitalize,e.isString=t.isString,e.stripHtml=t.stripHtml,e.camelCase=t.camelCase,e.copyTextToClipboard=t.copyTextToClipboard,e.fallbackCopyTextToClipboard=t.fallbackCopyTextToClipboard,e.random=t.random;var i=n(735);e.isValidUrl=i.isValidUrl,e.isValidUrls=i.isValidUrls,e.urlReplacer=i.urlReplacer,e.getDomain=i.getDomain,e.appendURLSearchParams=i.appendURLSearchParams,e.urlB64ToUint8Array=i.urlB64ToUint8Array;var r=n(449);e.getHighestSafeWindowContext=r.getHighestSafeWindowContext,e.getWindowWidth=r.getWindowWidth,e.getWindowHeight=r.getWindowHeight;var s=n(297);e.mergeDeep=s.mergeDeep,e.isObject=s.isObject;var a=n(285);e.loadVersionBrowser=a.loadVersionBrowser;var c=n(502);e.Logger=c.Logger;var l=function(e,t){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=d(t);if(n&&n.has(e))return n.get(e);var o={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var s=i?Object.getOwnPropertyDescriptor(e,r):null;s&&(s.get||s.set)?Object.defineProperty(o,r,s):o[r]=e[r]}return o.default=e,n&&n.set(e,o),o}(n(507));function d(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(d=function(e){return e?n:t})(e)}e.WSClient=l.default,e.WSClientType=l.WSClientType,e.WSClientPropTypes=l.WSClientPropTypes})(),o})()));
//# sourceMappingURL=utils.js.map
{
"name": "@selfcommunity/utils",
"version": "0.1.4",
"version": "0.1.5-alpha.0",
"license": "MIT",

@@ -104,3 +104,3 @@ "private": false,

},
"gitHead": "054ebdf2fe6993fa65a81e204cd34c678958e047"
"gitHead": "ce47fd80ccb32a7129728396883790828a3722cd"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet