@selfcommunity/utils 0.2.0-alpha.1 → 0.2.0-alpha.11
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/cjs/index.d.ts +5 -5
- package/lib/cjs/index.js +9 -30
- package/lib/cjs/utils/array.d.ts +7 -1
- package/lib/cjs/utils/array.js +23 -2
- package/lib/cjs/utils/browser.d.ts +1 -1
- package/lib/cjs/utils/browser.js +10 -5
- package/lib/cjs/utils/cache.d.ts +15 -5
- package/lib/cjs/utils/cache.js +10 -5
- package/lib/cjs/utils/image.d.ts +0 -1
- package/lib/cjs/utils/image.js +0 -1
- package/lib/cjs/utils/localStorage.d.ts +33 -0
- package/lib/cjs/utils/localStorage.js +101 -0
- package/lib/cjs/utils/logger.d.ts +0 -1
- package/lib/cjs/utils/logger.js +0 -1
- package/lib/cjs/utils/number.d.ts +0 -1
- package/lib/cjs/utils/number.js +0 -1
- package/lib/cjs/utils/object.d.ts +5 -1
- package/lib/cjs/utils/object.js +9 -2
- package/lib/cjs/utils/string.d.ts +0 -1
- package/lib/cjs/utils/string.js +0 -1
- package/lib/cjs/utils/url.d.ts +0 -1
- package/lib/cjs/utils/url.js +0 -1
- package/lib/cjs/utils/websocket.d.ts +0 -1
- package/lib/cjs/utils/websocket.js +0 -1
- package/lib/cjs/utils/window.d.ts +0 -1
- package/lib/cjs/utils/window.js +0 -1
- package/lib/esm/index.d.ts +5 -5
- package/lib/esm/index.js +5 -5
- package/lib/esm/utils/array.d.ts +7 -1
- package/lib/esm/utils/array.js +21 -1
- package/lib/esm/utils/browser.d.ts +1 -1
- package/lib/esm/utils/browser.js +8 -4
- package/lib/esm/utils/cache.d.ts +15 -5
- package/lib/esm/utils/cache.js +10 -5
- package/lib/esm/utils/image.d.ts +0 -1
- package/lib/esm/utils/image.js +0 -1
- package/lib/esm/utils/localStorage.d.ts +33 -0
- package/lib/esm/utils/localStorage.js +97 -0
- package/lib/esm/utils/logger.d.ts +0 -1
- package/lib/esm/utils/logger.js +0 -1
- package/lib/esm/utils/number.d.ts +0 -1
- package/lib/esm/utils/number.js +0 -1
- package/lib/esm/utils/object.d.ts +5 -1
- package/lib/esm/utils/object.js +7 -1
- package/lib/esm/utils/string.d.ts +0 -1
- package/lib/esm/utils/string.js +0 -1
- package/lib/esm/utils/url.d.ts +0 -1
- package/lib/esm/utils/url.js +0 -1
- package/lib/esm/utils/websocket.d.ts +0 -1
- package/lib/esm/utils/websocket.js +0 -1
- package/lib/esm/utils/window.d.ts +0 -1
- package/lib/esm/utils/window.js +0 -1
- package/lib/umd/utils.js +1 -2
- package/lib/umd/utils.js.LICENSE.txt +1 -1
- package/package.json +16 -15
- package/lib/cjs/index.d.ts.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/utils/array.d.ts.map +0 -1
- package/lib/cjs/utils/array.js.map +0 -1
- package/lib/cjs/utils/browser.d.ts.map +0 -1
- package/lib/cjs/utils/browser.js.map +0 -1
- package/lib/cjs/utils/cache.d.ts.map +0 -1
- package/lib/cjs/utils/cache.js.map +0 -1
- package/lib/cjs/utils/image.d.ts.map +0 -1
- package/lib/cjs/utils/image.js.map +0 -1
- package/lib/cjs/utils/logger.d.ts.map +0 -1
- package/lib/cjs/utils/logger.js.map +0 -1
- package/lib/cjs/utils/number.d.ts.map +0 -1
- package/lib/cjs/utils/number.js.map +0 -1
- package/lib/cjs/utils/object.d.ts.map +0 -1
- package/lib/cjs/utils/object.js.map +0 -1
- package/lib/cjs/utils/string.d.ts.map +0 -1
- package/lib/cjs/utils/string.js.map +0 -1
- package/lib/cjs/utils/url.d.ts.map +0 -1
- package/lib/cjs/utils/url.js.map +0 -1
- package/lib/cjs/utils/websocket.d.ts.map +0 -1
- package/lib/cjs/utils/websocket.js.map +0 -1
- package/lib/cjs/utils/window.d.ts.map +0 -1
- package/lib/cjs/utils/window.js.map +0 -1
- package/lib/esm/index.d.ts.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/utils/array.d.ts.map +0 -1
- package/lib/esm/utils/array.js.map +0 -1
- package/lib/esm/utils/browser.d.ts.map +0 -1
- package/lib/esm/utils/browser.js.map +0 -1
- package/lib/esm/utils/cache.d.ts.map +0 -1
- package/lib/esm/utils/cache.js.map +0 -1
- package/lib/esm/utils/image.d.ts.map +0 -1
- package/lib/esm/utils/image.js.map +0 -1
- package/lib/esm/utils/logger.d.ts.map +0 -1
- package/lib/esm/utils/logger.js.map +0 -1
- package/lib/esm/utils/number.d.ts.map +0 -1
- package/lib/esm/utils/number.js.map +0 -1
- package/lib/esm/utils/object.d.ts.map +0 -1
- package/lib/esm/utils/object.js.map +0 -1
- package/lib/esm/utils/string.d.ts.map +0 -1
- package/lib/esm/utils/string.js.map +0 -1
- package/lib/esm/utils/url.d.ts.map +0 -1
- package/lib/esm/utils/url.js.map +0 -1
- package/lib/esm/utils/websocket.d.ts.map +0 -1
- package/lib/esm/utils/websocket.js.map +0 -1
- package/lib/esm/utils/window.d.ts.map +0 -1
- package/lib/esm/utils/window.js.map +0 -1
- package/lib/umd/utils.js.map +0 -1
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify } from './utils/string';
|
|
2
2
|
import { isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter } from './utils/url';
|
|
3
3
|
import { getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering } from './utils/window';
|
|
4
|
-
import { mergeDeep, isObject, objectWithoutProperties } from './utils/object';
|
|
4
|
+
import { mergeDeep, isObject, objectWithoutProperties, isFunc } from './utils/object';
|
|
5
5
|
import { isInteger } from './utils/number';
|
|
6
|
-
import { arraysEqual } from './utils/array';
|
|
7
|
-
import { loadVersionBrowser } from './utils/browser';
|
|
6
|
+
import { arraysEqual, groupBy } from './utils/array';
|
|
7
|
+
import { loadVersionBrowser, iOS } from './utils/browser';
|
|
8
|
+
import { LocalStorageDB } from './utils/localStorage';
|
|
8
9
|
import LRUCache, { LruCache, LruCacheType, CacheStrategies } from './utils/cache';
|
|
9
10
|
import { Logger } from './utils/logger';
|
|
10
11
|
import WSClient, { WSClientType, WSClientPropTypes } from './utils/websocket';
|
|
@@ -12,5 +13,4 @@ import { resizeImage } from './utils/image';
|
|
|
12
13
|
/**
|
|
13
14
|
* Export all utilities
|
|
14
15
|
*/
|
|
15
|
-
export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, Logger, mergeDeep, isObject, objectWithoutProperties, isInteger, arraysEqual, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser, LRUCache, LruCache, LruCacheType, CacheStrategies, resizeImage };
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
|
16
|
+
export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, LruCacheType, CacheStrategies, resizeImage };
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.resizeImage = exports.CacheStrategies = exports.LruCache = exports.LRUCache = exports.loadVersionBrowser = exports.WSClient = exports.arraysEqual = exports.isInteger = exports.objectWithoutProperties = exports.isObject = exports.mergeDeep = exports.Logger = 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.resizeImage = exports.CacheStrategies = exports.LruCache = exports.LRUCache = exports.LocalStorageDB = exports.iOS = exports.loadVersionBrowser = exports.WSClient = exports.groupBy = exports.arraysEqual = exports.isInteger = exports.isFunc = exports.objectWithoutProperties = exports.isObject = exports.mergeDeep = exports.Logger = 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
|
+
const tslib_1 = require("tslib");
|
|
30
5
|
const string_1 = require("./utils/string");
|
|
31
6
|
Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return string_1.capitalize; } });
|
|
32
7
|
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return string_1.isString; } });
|
|
@@ -54,20 +29,24 @@ const object_1 = require("./utils/object");
|
|
|
54
29
|
Object.defineProperty(exports, "mergeDeep", { enumerable: true, get: function () { return object_1.mergeDeep; } });
|
|
55
30
|
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return object_1.isObject; } });
|
|
56
31
|
Object.defineProperty(exports, "objectWithoutProperties", { enumerable: true, get: function () { return object_1.objectWithoutProperties; } });
|
|
32
|
+
Object.defineProperty(exports, "isFunc", { enumerable: true, get: function () { return object_1.isFunc; } });
|
|
57
33
|
const number_1 = require("./utils/number");
|
|
58
34
|
Object.defineProperty(exports, "isInteger", { enumerable: true, get: function () { return number_1.isInteger; } });
|
|
59
35
|
const array_1 = require("./utils/array");
|
|
60
36
|
Object.defineProperty(exports, "arraysEqual", { enumerable: true, get: function () { return array_1.arraysEqual; } });
|
|
37
|
+
Object.defineProperty(exports, "groupBy", { enumerable: true, get: function () { return array_1.groupBy; } });
|
|
61
38
|
const browser_1 = require("./utils/browser");
|
|
62
39
|
Object.defineProperty(exports, "loadVersionBrowser", { enumerable: true, get: function () { return browser_1.loadVersionBrowser; } });
|
|
63
|
-
|
|
40
|
+
Object.defineProperty(exports, "iOS", { enumerable: true, get: function () { return browser_1.iOS; } });
|
|
41
|
+
const localStorage_1 = require("./utils/localStorage");
|
|
42
|
+
Object.defineProperty(exports, "LocalStorageDB", { enumerable: true, get: function () { return localStorage_1.LocalStorageDB; } });
|
|
43
|
+
const cache_1 = tslib_1.__importStar(require("./utils/cache"));
|
|
64
44
|
exports.LRUCache = cache_1.default;
|
|
65
45
|
Object.defineProperty(exports, "LruCache", { enumerable: true, get: function () { return cache_1.LruCache; } });
|
|
66
46
|
Object.defineProperty(exports, "CacheStrategies", { enumerable: true, get: function () { return cache_1.CacheStrategies; } });
|
|
67
47
|
const logger_1 = require("./utils/logger");
|
|
68
48
|
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
69
|
-
const websocket_1 = __importDefault(require("./utils/websocket"));
|
|
49
|
+
const websocket_1 = tslib_1.__importDefault(require("./utils/websocket"));
|
|
70
50
|
exports.WSClient = websocket_1.default;
|
|
71
51
|
const image_1 = require("./utils/image");
|
|
72
52
|
Object.defineProperty(exports, "resizeImage", { enumerable: true, get: function () { return image_1.resizeImage; } });
|
|
73
|
-
//# sourceMappingURL=index.js.map
|
package/lib/cjs/utils/array.d.ts
CHANGED
|
@@ -5,4 +5,10 @@
|
|
|
5
5
|
* @return boolean
|
|
6
6
|
*/
|
|
7
7
|
export declare const arraysEqual: (a: any, b: any) => boolean;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Group items from an array together by some criteria or value.
|
|
10
|
+
* @param {Array} arr The array to group items from
|
|
11
|
+
* @param {String|Function} criteria The criteria to group by
|
|
12
|
+
* @return {Object} The grouped object
|
|
13
|
+
*/
|
|
14
|
+
export declare const groupBy: (arr: any, criteria: any) => any;
|
package/lib/cjs/utils/array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.arraysEqual = void 0;
|
|
3
|
+
exports.groupBy = exports.arraysEqual = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Check if two arrays are equal
|
|
6
6
|
* @param a
|
|
@@ -25,4 +25,25 @@ const arraysEqual = (a, b) => {
|
|
|
25
25
|
return true;
|
|
26
26
|
};
|
|
27
27
|
exports.arraysEqual = arraysEqual;
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Group items from an array together by some criteria or value.
|
|
30
|
+
* @param {Array} arr The array to group items from
|
|
31
|
+
* @param {String|Function} criteria The criteria to group by
|
|
32
|
+
* @return {Object} The grouped object
|
|
33
|
+
*/
|
|
34
|
+
const groupBy = (arr, criteria) => {
|
|
35
|
+
return arr.reduce(function (obj, item) {
|
|
36
|
+
// Check if the criteria is a function to run on the item or a property of it
|
|
37
|
+
let key = typeof criteria === 'function' ? criteria(item) : item[criteria];
|
|
38
|
+
// If the key doesn't exist yet, create it
|
|
39
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
40
|
+
if (!obj.hasOwnProperty(key)) {
|
|
41
|
+
obj[key] = [];
|
|
42
|
+
}
|
|
43
|
+
// Push the value to the object
|
|
44
|
+
obj[key].push(item);
|
|
45
|
+
// Return the object to the next item in the loop
|
|
46
|
+
return obj;
|
|
47
|
+
}, {});
|
|
48
|
+
};
|
|
49
|
+
exports.groupBy = groupBy;
|
package/lib/cjs/utils/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadVersionBrowser = void 0;
|
|
3
|
+
exports.iOS = exports.loadVersionBrowser = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Get browser version to track on backend
|
|
6
6
|
* @return {{name: string, version: null}|{name: string, version: string}|{name: *, version: *}|{name: string, version}}
|
|
@@ -31,7 +31,7 @@ const loadVersionBrowser = () => {
|
|
|
31
31
|
browsername = brand.substr(brand.indexOf(' ') + 1);
|
|
32
32
|
return {
|
|
33
33
|
name: browsername,
|
|
34
|
-
version: browserversion
|
|
34
|
+
version: browserversion
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -40,7 +40,7 @@ const loadVersionBrowser = () => {
|
|
|
40
40
|
if (chromeVersion !== null) {
|
|
41
41
|
return {
|
|
42
42
|
name: 'chrome',
|
|
43
|
-
version: chromeVersion
|
|
43
|
+
version: chromeVersion
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -67,8 +67,13 @@ const loadVersionBrowser = () => {
|
|
|
67
67
|
}
|
|
68
68
|
return {
|
|
69
69
|
name: M[0],
|
|
70
|
-
version: M[1]
|
|
70
|
+
version: M[1]
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
73
|
exports.loadVersionBrowser = loadVersionBrowser;
|
|
74
|
-
|
|
74
|
+
const iOS = () => {
|
|
75
|
+
return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform) ||
|
|
76
|
+
// iPad on iOS 13 detection
|
|
77
|
+
(navigator.userAgent.includes('Mac') && 'ontouchend' in document));
|
|
78
|
+
};
|
|
79
|
+
exports.iOS = iOS;
|
package/lib/cjs/utils/cache.d.ts
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* LruCache interface
|
|
3
3
|
*/
|
|
4
4
|
export interface LruCacheType<T> {
|
|
5
|
-
get: (key: string, value?: T
|
|
6
|
-
|
|
5
|
+
get: (key: string, value?: T, options?: {
|
|
6
|
+
noSsr: boolean;
|
|
7
|
+
}) => T;
|
|
8
|
+
set: (key: string, value: T, options?: {
|
|
9
|
+
noSsr: boolean;
|
|
10
|
+
}) => void;
|
|
7
11
|
hasKey: (key: string) => boolean;
|
|
8
12
|
delete: (key: string) => void;
|
|
9
13
|
deleteKeys: (keys: string[]) => void;
|
|
@@ -17,6 +21,7 @@ export interface LruCacheType<T> {
|
|
|
17
21
|
export declare class LruCache<T> {
|
|
18
22
|
private values;
|
|
19
23
|
private maxEntries;
|
|
24
|
+
private ssr;
|
|
20
25
|
/**
|
|
21
26
|
* Initialize Cache
|
|
22
27
|
* @param maxEntries
|
|
@@ -26,14 +31,20 @@ export declare class LruCache<T> {
|
|
|
26
31
|
* Get a key from the map store
|
|
27
32
|
* @param key
|
|
28
33
|
* @param value
|
|
34
|
+
* @param options
|
|
29
35
|
*/
|
|
30
|
-
get(key: string, value?: T
|
|
36
|
+
get(key: string, value?: T, options?: {
|
|
37
|
+
noSsr: boolean;
|
|
38
|
+
}): T;
|
|
31
39
|
/**
|
|
32
40
|
* Set a key in the store
|
|
33
41
|
* @param key
|
|
34
42
|
* @param value
|
|
43
|
+
* @param options
|
|
35
44
|
*/
|
|
36
|
-
set(key: string, value: T
|
|
45
|
+
set(key: string, value: T, options?: {
|
|
46
|
+
noSsr: boolean;
|
|
47
|
+
}): void;
|
|
37
48
|
/**
|
|
38
49
|
* Check if key is in cache
|
|
39
50
|
* @param key
|
|
@@ -77,4 +88,3 @@ export declare enum CacheStrategies {
|
|
|
77
88
|
*/
|
|
78
89
|
declare const cache: LruCacheType<any>;
|
|
79
90
|
export default cache;
|
|
80
|
-
//# sourceMappingURL=cache.d.ts.map
|
package/lib/cjs/utils/cache.js
CHANGED
|
@@ -12,7 +12,8 @@ class LruCache {
|
|
|
12
12
|
constructor(maxEntries = 10000) {
|
|
13
13
|
this.values = new Map();
|
|
14
14
|
this.maxEntries = maxEntries;
|
|
15
|
-
|
|
15
|
+
this.ssr = typeof window === 'undefined';
|
|
16
|
+
if (!this.ssr) {
|
|
16
17
|
window['__viewSCCache'] = this.values;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -20,8 +21,9 @@ class LruCache {
|
|
|
20
21
|
* Get a key from the map store
|
|
21
22
|
* @param key
|
|
22
23
|
* @param value
|
|
24
|
+
* @param options
|
|
23
25
|
*/
|
|
24
|
-
get(key, value) {
|
|
26
|
+
get(key, value, options = { noSsr: true }) {
|
|
25
27
|
const hasKey = this.values.has(key);
|
|
26
28
|
let entry;
|
|
27
29
|
if (hasKey) {
|
|
@@ -33,7 +35,7 @@ class LruCache {
|
|
|
33
35
|
else if (value) {
|
|
34
36
|
// insert value if passed
|
|
35
37
|
entry = value;
|
|
36
|
-
this.values.set(key, entry);
|
|
38
|
+
!(this.ssr && options.noSsr) && this.values.set(key, entry);
|
|
37
39
|
}
|
|
38
40
|
return entry;
|
|
39
41
|
}
|
|
@@ -41,8 +43,12 @@ class LruCache {
|
|
|
41
43
|
* Set a key in the store
|
|
42
44
|
* @param key
|
|
43
45
|
* @param value
|
|
46
|
+
* @param options
|
|
44
47
|
*/
|
|
45
|
-
set(key, value) {
|
|
48
|
+
set(key, value, options = { noSsr: true }) {
|
|
49
|
+
if (this.ssr && options.noSsr) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
46
52
|
if (this.values.size >= this.maxEntries) {
|
|
47
53
|
// least-recently used cache eviction strategy
|
|
48
54
|
const keyToDelete = this.values.keys().next().value;
|
|
@@ -119,4 +125,3 @@ var CacheStrategies;
|
|
|
119
125
|
*/
|
|
120
126
|
const cache = new LruCache();
|
|
121
127
|
exports.default = cache;
|
|
122
|
-
//# sourceMappingURL=cache.js.map
|
package/lib/cjs/utils/image.d.ts
CHANGED
package/lib/cjs/utils/image.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manage window.localStorage
|
|
3
|
+
*/
|
|
4
|
+
export declare class LocalStorageDB {
|
|
5
|
+
/**
|
|
6
|
+
* Set a key in window.localStorage
|
|
7
|
+
* @param key
|
|
8
|
+
* @param value
|
|
9
|
+
*/
|
|
10
|
+
static set(key: any, value: any): void;
|
|
11
|
+
/**
|
|
12
|
+
* Get a key from window.localStorage, else return null
|
|
13
|
+
* @param key
|
|
14
|
+
*/
|
|
15
|
+
static get(key: any): any;
|
|
16
|
+
/**
|
|
17
|
+
* Get all keys
|
|
18
|
+
*/
|
|
19
|
+
static getAll(): any[];
|
|
20
|
+
/**
|
|
21
|
+
* Remove a single item from window.localStorage
|
|
22
|
+
* @param key
|
|
23
|
+
*/
|
|
24
|
+
static remove(key: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* Clear all keys from window.localStorage
|
|
27
|
+
*/
|
|
28
|
+
static clearAll(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Check if localStorage is supported
|
|
31
|
+
*/
|
|
32
|
+
static checkifSupport(): boolean;
|
|
33
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalStorageDB = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Manage window.localStorage
|
|
6
|
+
*/
|
|
7
|
+
class LocalStorageDB {
|
|
8
|
+
/**
|
|
9
|
+
* Set a key in window.localStorage
|
|
10
|
+
* @param key
|
|
11
|
+
* @param value
|
|
12
|
+
*/
|
|
13
|
+
static set(key, value) {
|
|
14
|
+
if (this.checkifSupport()) {
|
|
15
|
+
try {
|
|
16
|
+
window.localStorage.setItem(key, value);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.error(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.error('No support. Use a fallback such as browser cookies or store on the server.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get a key from window.localStorage, else return null
|
|
28
|
+
* @param key
|
|
29
|
+
*/
|
|
30
|
+
static get(key) {
|
|
31
|
+
try {
|
|
32
|
+
let data = window.localStorage.getItem(key);
|
|
33
|
+
if (data && typeof data === 'object') {
|
|
34
|
+
return JSON.parse(data);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get all keys
|
|
46
|
+
*/
|
|
47
|
+
static getAll() {
|
|
48
|
+
let array = [];
|
|
49
|
+
for (let i = 0; i < window.localStorage.length; i++) {
|
|
50
|
+
let key = localStorage.key(i);
|
|
51
|
+
array.push(this.get(key));
|
|
52
|
+
}
|
|
53
|
+
return array;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Remove a single item from window.localStorage
|
|
57
|
+
* @param key
|
|
58
|
+
*/
|
|
59
|
+
static remove(key) {
|
|
60
|
+
try {
|
|
61
|
+
window.localStorage.removeItem(key);
|
|
62
|
+
if (window.localStorage.length == 0) {
|
|
63
|
+
this.clearAll();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
console.error(e);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (this.get(key)) {
|
|
71
|
+
delete window.localStorage[key];
|
|
72
|
+
if (window.localStorage.length == 0) {
|
|
73
|
+
this.clearAll();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Clear all keys from window.localStorage
|
|
80
|
+
*/
|
|
81
|
+
static clearAll() {
|
|
82
|
+
try {
|
|
83
|
+
window.localStorage.clear();
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
console.error(e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if localStorage is supported
|
|
91
|
+
*/
|
|
92
|
+
static checkifSupport() {
|
|
93
|
+
try {
|
|
94
|
+
return 'localStorage' in window && window['localStorage'] !== null;
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.LocalStorageDB = LocalStorageDB;
|
package/lib/cjs/utils/logger.js
CHANGED
package/lib/cjs/utils/number.js
CHANGED
|
@@ -16,4 +16,8 @@ export declare function mergeDeep(target: object, source: object): object;
|
|
|
16
16
|
* @param keys
|
|
17
17
|
*/
|
|
18
18
|
export declare function objectWithoutProperties<T>(obj: T | null, keys: string[]): T;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Check if v is a func
|
|
21
|
+
* @param v
|
|
22
|
+
*/
|
|
23
|
+
export declare function isFunc(v: any): boolean;
|
package/lib/cjs/utils/object.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.objectWithoutProperties = exports.mergeDeep = exports.isObject = void 0;
|
|
3
|
+
exports.isFunc = exports.objectWithoutProperties = exports.mergeDeep = exports.isObject = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Check if v is an object
|
|
6
6
|
* @param v
|
|
@@ -50,4 +50,11 @@ function objectWithoutProperties(obj, keys) {
|
|
|
50
50
|
return target;
|
|
51
51
|
}
|
|
52
52
|
exports.objectWithoutProperties = objectWithoutProperties;
|
|
53
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Check if v is a func
|
|
55
|
+
* @param v
|
|
56
|
+
*/
|
|
57
|
+
function isFunc(v) {
|
|
58
|
+
return typeof v === 'function';
|
|
59
|
+
}
|
|
60
|
+
exports.isFunc = isFunc;
|
package/lib/cjs/utils/string.js
CHANGED
package/lib/cjs/utils/url.d.ts
CHANGED
package/lib/cjs/utils/url.js
CHANGED
|
@@ -2,4 +2,3 @@ export declare function getWindowWidth(): number;
|
|
|
2
2
|
export declare function getWindowHeight(): number;
|
|
3
3
|
export declare function getHighestSafeWindowContext(self?: Window & typeof globalThis): any;
|
|
4
4
|
export declare function isClientSideRendering(): boolean;
|
|
5
|
-
//# sourceMappingURL=window.d.ts.map
|
package/lib/cjs/utils/window.js
CHANGED
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify } from './utils/string';
|
|
2
2
|
import { isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter } from './utils/url';
|
|
3
3
|
import { getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering } from './utils/window';
|
|
4
|
-
import { mergeDeep, isObject, objectWithoutProperties } from './utils/object';
|
|
4
|
+
import { mergeDeep, isObject, objectWithoutProperties, isFunc } from './utils/object';
|
|
5
5
|
import { isInteger } from './utils/number';
|
|
6
|
-
import { arraysEqual } from './utils/array';
|
|
7
|
-
import { loadVersionBrowser } from './utils/browser';
|
|
6
|
+
import { arraysEqual, groupBy } from './utils/array';
|
|
7
|
+
import { loadVersionBrowser, iOS } from './utils/browser';
|
|
8
|
+
import { LocalStorageDB } from './utils/localStorage';
|
|
8
9
|
import LRUCache, { LruCache, LruCacheType, CacheStrategies } from './utils/cache';
|
|
9
10
|
import { Logger } from './utils/logger';
|
|
10
11
|
import WSClient, { WSClientType, WSClientPropTypes } from './utils/websocket';
|
|
@@ -12,5 +13,4 @@ import { resizeImage } from './utils/image';
|
|
|
12
13
|
/**
|
|
13
14
|
* Export all utilities
|
|
14
15
|
*/
|
|
15
|
-
export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, Logger, mergeDeep, isObject, objectWithoutProperties, isInteger, arraysEqual, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser, LRUCache, LruCache, LruCacheType, CacheStrategies, resizeImage };
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
|
16
|
+
export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, WSClient, WSClientType, WSClientPropTypes, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, LruCacheType, CacheStrategies, resizeImage };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify } from './utils/string';
|
|
2
2
|
import { isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter } from './utils/url';
|
|
3
3
|
import { getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering } from './utils/window';
|
|
4
|
-
import { mergeDeep, isObject, objectWithoutProperties } from './utils/object';
|
|
4
|
+
import { mergeDeep, isObject, objectWithoutProperties, isFunc } from './utils/object';
|
|
5
5
|
import { isInteger } from './utils/number';
|
|
6
|
-
import { arraysEqual } from './utils/array';
|
|
7
|
-
import { loadVersionBrowser } from './utils/browser';
|
|
6
|
+
import { arraysEqual, groupBy } from './utils/array';
|
|
7
|
+
import { loadVersionBrowser, iOS } from './utils/browser';
|
|
8
|
+
import { LocalStorageDB } from './utils/localStorage';
|
|
8
9
|
import LRUCache, { LruCache, CacheStrategies } from './utils/cache';
|
|
9
10
|
import { Logger } from './utils/logger';
|
|
10
11
|
import WSClient from './utils/websocket';
|
|
@@ -12,5 +13,4 @@ import { resizeImage } from './utils/image';
|
|
|
12
13
|
/**
|
|
13
14
|
* Export all utilities
|
|
14
15
|
*/
|
|
15
|
-
export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, Logger, mergeDeep, isObject, objectWithoutProperties, isInteger, arraysEqual, WSClient, loadVersionBrowser, LRUCache, LruCache, CacheStrategies, resizeImage };
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
16
|
+
export { capitalize, isString, stripHtml, camelCase, copyTextToClipboard, fallbackCopyTextToClipboard, random, slugify, isValidUrl, isValidUrls, urlReplacer, getDomain, appendURLSearchParams, urlB64ToUint8Array, getQueryStringParameter, updateQueryStringParameter, getHighestSafeWindowContext, getWindowWidth, getWindowHeight, isClientSideRendering, Logger, mergeDeep, isObject, objectWithoutProperties, isFunc, isInteger, arraysEqual, groupBy, WSClient, loadVersionBrowser, iOS, LocalStorageDB, LRUCache, LruCache, CacheStrategies, resizeImage };
|
package/lib/esm/utils/array.d.ts
CHANGED
|
@@ -5,4 +5,10 @@
|
|
|
5
5
|
* @return boolean
|
|
6
6
|
*/
|
|
7
7
|
export declare const arraysEqual: (a: any, b: any) => boolean;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Group items from an array together by some criteria or value.
|
|
10
|
+
* @param {Array} arr The array to group items from
|
|
11
|
+
* @param {String|Function} criteria The criteria to group by
|
|
12
|
+
* @return {Object} The grouped object
|
|
13
|
+
*/
|
|
14
|
+
export declare const groupBy: (arr: any, criteria: any) => any;
|
package/lib/esm/utils/array.js
CHANGED
|
@@ -21,4 +21,24 @@ export const arraysEqual = (a, b) => {
|
|
|
21
21
|
}
|
|
22
22
|
return true;
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Group items from an array together by some criteria or value.
|
|
26
|
+
* @param {Array} arr The array to group items from
|
|
27
|
+
* @param {String|Function} criteria The criteria to group by
|
|
28
|
+
* @return {Object} The grouped object
|
|
29
|
+
*/
|
|
30
|
+
export const groupBy = (arr, criteria) => {
|
|
31
|
+
return arr.reduce(function (obj, item) {
|
|
32
|
+
// Check if the criteria is a function to run on the item or a property of it
|
|
33
|
+
let key = typeof criteria === 'function' ? criteria(item) : item[criteria];
|
|
34
|
+
// If the key doesn't exist yet, create it
|
|
35
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
36
|
+
if (!obj.hasOwnProperty(key)) {
|
|
37
|
+
obj[key] = [];
|
|
38
|
+
}
|
|
39
|
+
// Push the value to the object
|
|
40
|
+
obj[key].push(item);
|
|
41
|
+
// Return the object to the next item in the loop
|
|
42
|
+
return obj;
|
|
43
|
+
}, {});
|
|
44
|
+
};
|