@koine/browser 2.0.0-beta.4 → 2.0.0-beta.41
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/README.md +1 -1
- package/createStorage.d.ts +1 -44
- package/getZonedDate.d.ts +1 -16
- package/gtagPageview.d.ts +1 -5
- package/index.cjs.d.ts +1 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +58 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +2 -0
- package/index.esm.js +38 -0
- package/isIE.d.ts +1 -7
- package/isMobile.d.ts +1 -7
- package/listenUrlSearch.d.ts +3 -0
- package/listenUrlSearchParams.d.ts +1 -0
- package/navigateToHash.d.ts +1 -8
- package/navigateToHashParams.d.ts +2 -9
- package/navigateToMergedHashParams.d.ts +2 -8
- package/navigateToMergedParams.d.ts +2 -9
- package/navigateToParams.d.ts +2 -10
- package/navigateToUrl.d.ts +1 -7
- package/navigateWithoutUrlParam.d.ts +1 -8
- package/package.json +15 -12
- package/redirectTo.d.ts +2 -9
- package/storage.d.ts +1 -5
- package/storageClient.d.ts +1 -5
- package/createStorage.js +0 -146
- package/createStorage.mjs +0 -130
- package/getZonedDate.js +0 -37
- package/getZonedDate.mjs +0 -31
- package/gtagPageview.js +0 -41
- package/gtagPageview.mjs +0 -23
- package/index.js +0 -72
- package/index.mjs +0 -15
- package/isIE.js +0 -31
- package/isIE.mjs +0 -16
- package/isMobile.js +0 -29
- package/isMobile.mjs +0 -14
- package/navigateToHash.js +0 -25
- package/navigateToHash.mjs +0 -11
- package/navigateToHashParams.js +0 -33
- package/navigateToHashParams.mjs +0 -19
- package/navigateToMergedHashParams.js +0 -26
- package/navigateToMergedHashParams.mjs +0 -11
- package/navigateToMergedParams.js +0 -26
- package/navigateToMergedParams.mjs +0 -12
- package/navigateToParams.js +0 -30
- package/navigateToParams.mjs +0 -17
- package/navigateToUrl.js +0 -28
- package/navigateToUrl.mjs +0 -10
- package/navigateWithoutUrlParam.js +0 -32
- package/navigateWithoutUrlParam.mjs +0 -18
- package/redirectTo.js +0 -28
- package/redirectTo.mjs +0 -14
- package/storage.js +0 -25
- package/storage.mjs +0 -8
- package/storageClient.js +0 -112
- package/storageClient.mjs +0 -95
package/navigateToParams.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import buildUrlQueryString from "@koine/utils/buildUrlQueryString";
|
|
2
|
-
import isBrowser from "@koine/utils/isBrowser";
|
|
3
|
-
import navigateToUrl from "./navigateToUrl";
|
|
4
|
-
/**
|
|
5
|
-
* Change current URL query parameters, it uses `history`.
|
|
6
|
-
*
|
|
7
|
-
* @category location
|
|
8
|
-
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
9
|
-
* @returns The query string with initial `?`
|
|
10
|
-
*/ export function navigateToParams(params = {}, replace) {
|
|
11
|
-
const queryString = typeof params === "string" ? params : buildUrlQueryString(params);
|
|
12
|
-
if (isBrowser) {
|
|
13
|
-
navigateToUrl(location.pathname + queryString, replace);
|
|
14
|
-
}
|
|
15
|
-
return queryString;
|
|
16
|
-
}
|
|
17
|
-
export default navigateToParams;
|
package/navigateToUrl.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It updates the browser's location URL with global `history` object
|
|
3
|
-
*
|
|
4
|
-
* @category location
|
|
5
|
-
*/ "use strict";
|
|
6
|
-
Object.defineProperty(exports, "__esModule", {
|
|
7
|
-
value: true
|
|
8
|
-
});
|
|
9
|
-
function _export(target, all) {
|
|
10
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: all[name]
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
_export(exports, {
|
|
16
|
-
navigateToUrl: function() {
|
|
17
|
-
return navigateToUrl;
|
|
18
|
-
},
|
|
19
|
-
default: function() {
|
|
20
|
-
return _default;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
function navigateToUrl(url = "", replace) {
|
|
24
|
-
if (url) {
|
|
25
|
-
history[replace ? "replaceState" : "pushState"](history.state, "", url);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const _default = navigateToUrl;
|
package/navigateToUrl.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It updates the browser's location URL with global `history` object
|
|
3
|
-
*
|
|
4
|
-
* @category location
|
|
5
|
-
*/ export function navigateToUrl(url = "", replace) {
|
|
6
|
-
if (url) {
|
|
7
|
-
history[replace ? "replaceState" : "pushState"](history.state, "", url);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export default navigateToUrl;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
navigateWithoutUrlParam: function() {
|
|
13
|
-
return navigateWithoutUrlParam;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _getUrlQueryParams = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/getUrlQueryParams"));
|
|
21
|
-
const _navigateToParams = /*#__PURE__*/ _interop_require_default._(require("./navigateToParams"));
|
|
22
|
-
function navigateWithoutUrlParam(paramName, replace) {
|
|
23
|
-
const params = {};
|
|
24
|
-
const currentParams = (0, _getUrlQueryParams.default)();
|
|
25
|
-
for(const key in currentParams){
|
|
26
|
-
if (key !== paramName) {
|
|
27
|
-
params[key] = currentParams[key];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return (0, _navigateToParams.default)(params, replace);
|
|
31
|
-
}
|
|
32
|
-
const _default = navigateWithoutUrlParam;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import getUrlQueryParams from "@koine/utils/getUrlQueryParams";
|
|
2
|
-
import navigateToParams from "./navigateToParams";
|
|
3
|
-
/**
|
|
4
|
-
* Remove URL query parameter, it uses `history`
|
|
5
|
-
*
|
|
6
|
-
* @category location
|
|
7
|
-
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
8
|
-
*/ export function navigateWithoutUrlParam(paramName, replace) {
|
|
9
|
-
const params = {};
|
|
10
|
-
const currentParams = getUrlQueryParams();
|
|
11
|
-
for(const key in currentParams){
|
|
12
|
-
if (key !== paramName) {
|
|
13
|
-
params[key] = currentParams[key];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return navigateToParams(params, replace);
|
|
17
|
-
}
|
|
18
|
-
export default navigateWithoutUrlParam;
|
package/redirectTo.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
redirectTo: function() {
|
|
13
|
-
return redirectTo;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _buildUrlQueryString = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/buildUrlQueryString"));
|
|
21
|
-
const _isBrowser = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isBrowser"));
|
|
22
|
-
function redirectTo(url, params) {
|
|
23
|
-
if (_isBrowser.default) {
|
|
24
|
-
const queryString = (0, _buildUrlQueryString.default)(params);
|
|
25
|
-
location.href = url.replace(/\?+$/g, "") + queryString;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const _default = redirectTo;
|
package/redirectTo.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import buildUrlQueryString from "@koine/utils/buildUrlQueryString";
|
|
2
|
-
import isBrowser from "@koine/utils/isBrowser";
|
|
3
|
-
/**
|
|
4
|
-
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
5
|
-
* marks from the given URL, it uses `location`
|
|
6
|
-
*
|
|
7
|
-
* @category location
|
|
8
|
-
*/ export function redirectTo(url, params) {
|
|
9
|
-
if (isBrowser) {
|
|
10
|
-
const queryString = buildUrlQueryString(params);
|
|
11
|
-
location.href = url.replace(/\?+$/g, "") + queryString;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export default redirectTo;
|
package/storage.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
storage: function() {
|
|
13
|
-
return storage;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _storageClient = /*#__PURE__*/ _interop_require_default._(require("./storageClient"));
|
|
21
|
-
const storage = {
|
|
22
|
-
l: (0, _storageClient.default)(),
|
|
23
|
-
s: (0, _storageClient.default)(true)
|
|
24
|
-
};
|
|
25
|
-
const _default = storage;
|
package/storage.mjs
DELETED
package/storageClient.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
storageClient: function() {
|
|
13
|
-
return storageClient;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _isBrowser = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isBrowser"));
|
|
21
|
-
const _isString = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isString"));
|
|
22
|
-
const methodsMap = {
|
|
23
|
-
g: "getItem",
|
|
24
|
-
s: "setItem",
|
|
25
|
-
r: "removeItem"
|
|
26
|
-
};
|
|
27
|
-
const storageClient = (useSessionStorage)=>{
|
|
28
|
-
const nativeMethod = (method, key, value)=>_isBrowser.default ? window[useSessionStorage ? "sessionStorage" : "localStorage"][methodsMap[method]](key, value) : ()=>{
|
|
29
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
30
|
-
console.warn(`[@koine/utils:storageClient]: ${useSessionStorage ? "sessionStorage" : "localStorage"} does not exists outside of browser.`);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const get = (key, transform, defaultValue)=>{
|
|
34
|
-
let value = defaultValue ?? null;
|
|
35
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
36
|
-
if (!_isBrowser.default) {
|
|
37
|
-
console.log(`[@koine/utils:storage] called 'get' outside of browser with default value '${JSON.stringify(defaultValue)}'.`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (_isBrowser.default) {
|
|
41
|
-
let stored = nativeMethod("g", key);
|
|
42
|
-
if (stored) {
|
|
43
|
-
stored = transform ? transform(stored) : stored;
|
|
44
|
-
try {
|
|
45
|
-
const parsed = JSON.parse(stored);
|
|
46
|
-
if (parsed) value = parsed;
|
|
47
|
-
} catch (_e) {
|
|
48
|
-
value = stored;
|
|
49
|
-
// if (process.env["NODE_ENV"] !== "production") {
|
|
50
|
-
// console.warn(
|
|
51
|
-
// `[@koine/utils:storage]: 'get' failed to parse stored value as JSON. Plain '${stored}' value is returned.`
|
|
52
|
-
// );
|
|
53
|
-
// }
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return value;
|
|
58
|
-
};
|
|
59
|
-
const set = (key, value, transform = (value)=>value)=>{
|
|
60
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
61
|
-
if (!_isBrowser.default) {
|
|
62
|
-
console.log(`[@koine/utils:storage] called 'set' outside of browser does not work.`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (_isBrowser.default) {
|
|
66
|
-
try {
|
|
67
|
-
const transformedValue = (0, _isString.default)(value) ? transform(value) : transform(JSON.stringify(value));
|
|
68
|
-
nativeMethod("s", key, transformedValue);
|
|
69
|
-
} catch (_e) {
|
|
70
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
71
|
-
console.warn(`[@koine/utils:createStorage]: 'set' error.`, _e);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const remove = (key)=>{
|
|
77
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
78
|
-
if (!_isBrowser.default) {
|
|
79
|
-
console.log(`[@koine/utils:storage] called 'remove' outside of browser does not work.`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (_isBrowser.default) {
|
|
83
|
-
try {
|
|
84
|
-
nativeMethod("r", key);
|
|
85
|
-
} catch (_e) {
|
|
86
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
87
|
-
console.warn(`[@koine/utils:createStorage]: 'remove' error.`, _e);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
const has = (key, defaultValue)=>{
|
|
93
|
-
let value = defaultValue ?? false;
|
|
94
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
95
|
-
if (!_isBrowser.default) {
|
|
96
|
-
console.log(`[@koine/utils:storage] called 'has' outside of browser with default value '${JSON.stringify(defaultValue)}'.`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (_isBrowser.default) {
|
|
100
|
-
const stored = nativeMethod("g", key);
|
|
101
|
-
value = stored ?? false;
|
|
102
|
-
}
|
|
103
|
-
return value;
|
|
104
|
-
};
|
|
105
|
-
return {
|
|
106
|
-
get,
|
|
107
|
-
set,
|
|
108
|
-
remove,
|
|
109
|
-
has
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
const _default = storageClient;
|
package/storageClient.mjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import isBrowser from "@koine/utils/isBrowser";
|
|
2
|
-
import isString from "@koine/utils/isString";
|
|
3
|
-
const methodsMap = {
|
|
4
|
-
g: "getItem",
|
|
5
|
-
s: "setItem",
|
|
6
|
-
r: "removeItem"
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Super minifiable `local/session Storage` client creator with SSR safety
|
|
10
|
-
*/ export const storageClient = (useSessionStorage)=>{
|
|
11
|
-
const nativeMethod = (method, key, value)=>isBrowser ? window[useSessionStorage ? "sessionStorage" : "localStorage"][methodsMap[method]](key, value) : ()=>{
|
|
12
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
13
|
-
console.warn(`[@koine/utils:storageClient]: ${useSessionStorage ? "sessionStorage" : "localStorage"} does not exists outside of browser.`);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const get = (key, transform, defaultValue)=>{
|
|
17
|
-
let value = defaultValue ?? null;
|
|
18
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
19
|
-
if (!isBrowser) {
|
|
20
|
-
console.log(`[@koine/utils:storage] called 'get' outside of browser with default value '${JSON.stringify(defaultValue)}'.`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (isBrowser) {
|
|
24
|
-
let stored = nativeMethod("g", key);
|
|
25
|
-
if (stored) {
|
|
26
|
-
stored = transform ? transform(stored) : stored;
|
|
27
|
-
try {
|
|
28
|
-
const parsed = JSON.parse(stored);
|
|
29
|
-
if (parsed) value = parsed;
|
|
30
|
-
} catch (_e) {
|
|
31
|
-
value = stored;
|
|
32
|
-
// if (process.env["NODE_ENV"] !== "production") {
|
|
33
|
-
// console.warn(
|
|
34
|
-
// `[@koine/utils:storage]: 'get' failed to parse stored value as JSON. Plain '${stored}' value is returned.`
|
|
35
|
-
// );
|
|
36
|
-
// }
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return value;
|
|
41
|
-
};
|
|
42
|
-
const set = (key, value, transform = (value)=>value)=>{
|
|
43
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
44
|
-
if (!isBrowser) {
|
|
45
|
-
console.log(`[@koine/utils:storage] called 'set' outside of browser does not work.`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (isBrowser) {
|
|
49
|
-
try {
|
|
50
|
-
const transformedValue = isString(value) ? transform(value) : transform(JSON.stringify(value));
|
|
51
|
-
nativeMethod("s", key, transformedValue);
|
|
52
|
-
} catch (_e) {
|
|
53
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
54
|
-
console.warn(`[@koine/utils:createStorage]: 'set' error.`, _e);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const remove = (key)=>{
|
|
60
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
61
|
-
if (!isBrowser) {
|
|
62
|
-
console.log(`[@koine/utils:storage] called 'remove' outside of browser does not work.`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (isBrowser) {
|
|
66
|
-
try {
|
|
67
|
-
nativeMethod("r", key);
|
|
68
|
-
} catch (_e) {
|
|
69
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
70
|
-
console.warn(`[@koine/utils:createStorage]: 'remove' error.`, _e);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const has = (key, defaultValue)=>{
|
|
76
|
-
let value = defaultValue ?? false;
|
|
77
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
78
|
-
if (!isBrowser) {
|
|
79
|
-
console.log(`[@koine/utils:storage] called 'has' outside of browser with default value '${JSON.stringify(defaultValue)}'.`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (isBrowser) {
|
|
83
|
-
const stored = nativeMethod("g", key);
|
|
84
|
-
value = stored ?? false;
|
|
85
|
-
}
|
|
86
|
-
return value;
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
get,
|
|
90
|
-
set,
|
|
91
|
-
remove,
|
|
92
|
-
has
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
export default storageClient;
|