@koine/browser 2.0.0-beta.2 → 2.0.0-beta.21
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/createStorage.d.ts +0 -42
- package/createStorage.js +24 -74
- package/getZonedDate.d.ts +0 -14
- package/getZonedDate.js +7 -28
- package/gtagPageview.d.ts +0 -3
- package/gtagPageview.js +4 -24
- package/index.d.ts +17 -15
- package/index.js +17 -33
- package/isIE.d.ts +0 -5
- package/isIE.js +4 -14
- package/isMobile.d.ts +0 -5
- package/isMobile.js +4 -16
- package/listenUrlSearch.d.ts +3 -0
- package/listenUrlSearch.js +55 -0
- package/listenUrlSearchParams.d.ts +2 -0
- package/listenUrlSearchParams.js +12 -0
- package/navigateToHash.d.ts +0 -6
- package/navigateToHash.js +4 -15
- package/navigateToHashParams.d.ts +1 -7
- package/navigateToHashParams.js +5 -17
- package/navigateToMergedHashParams.d.ts +1 -6
- package/navigateToMergedHashParams.js +5 -16
- package/navigateToMergedParams.d.ts +1 -7
- package/navigateToMergedParams.js +5 -17
- package/navigateToParams.d.ts +1 -8
- package/navigateToParams.js +7 -20
- package/navigateToUrl.d.ts +0 -5
- package/navigateToUrl.js +2 -11
- package/navigateWithoutUrlParam.d.ts +0 -6
- package/navigateWithoutUrlParam.js +6 -17
- package/package.json +62 -12
- package/redirectTo.d.ts +1 -7
- package/redirectTo.js +5 -17
- package/storage.d.ts +0 -3
- package/storage.js +5 -12
- package/storageClient.d.ts +0 -3
- package/storageClient.js +20 -34
- package/README.md +0 -1
- package/createStorage.mjs +0 -143
- package/getZonedDate.mjs +0 -37
- package/gtagPageview.mjs +0 -30
- package/index.mjs +0 -15
- package/isIE.mjs +0 -18
- package/isMobile.mjs +0 -16
- package/navigateToHash.mjs +0 -13
- package/navigateToHashParams.mjs +0 -22
- package/navigateToMergedHashParams.mjs +0 -14
- package/navigateToMergedParams.mjs +0 -14
- package/navigateToParams.mjs +0 -19
- package/navigateToUrl.mjs +0 -12
- package/navigateWithoutUrlParam.mjs +0 -19
- package/redirectTo.mjs +0 -15
- package/storage.mjs +0 -9
- package/storageClient.mjs +0 -103
package/createStorage.d.ts
CHANGED
|
@@ -1,54 +1,12 @@
|
|
|
1
1
|
export type CreateStorageConfig = Record<string, any>;
|
|
2
|
-
/**
|
|
3
|
-
* Utility to create a storage instance to interact with `localStorage` using
|
|
4
|
-
* encrypted (encoded) key/values.
|
|
5
|
-
*/
|
|
6
2
|
export declare const createStorage: <T extends CreateStorageConfig>(config: Partial<T>, useSessionStorage?: boolean) => {
|
|
7
|
-
/**
|
|
8
|
-
* Get all storage value (it uses `localStorage.get()`).
|
|
9
|
-
*
|
|
10
|
-
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
11
|
-
* On ssr or if the given `key` argument is not found `defaultValue` is
|
|
12
|
-
* returned, otherwise `null`.
|
|
13
|
-
*/
|
|
14
3
|
get<TKey extends Extract<keyof T, string>>(key: TKey, defaultValue?: T[TKey] | null | undefined): T[TKey] | null;
|
|
15
|
-
/**
|
|
16
|
-
* Get all storage values (it uses `localStorage.get()`).
|
|
17
|
-
*
|
|
18
|
-
* `undefined` and `null` values are not returned.
|
|
19
|
-
*/
|
|
20
4
|
getAll(defaultValues?: Partial<T> | undefined): T;
|
|
21
|
-
/**
|
|
22
|
-
* Set a storage value (it uses `localStorage.set()`).
|
|
23
|
-
*
|
|
24
|
-
* Non-string values are stringified with `JSON.stringify()`
|
|
25
|
-
*/
|
|
26
5
|
set<TKey_1 extends Extract<keyof T, string>>(key: TKey_1, value?: T[TKey_1] | undefined): void;
|
|
27
|
-
/**
|
|
28
|
-
* Set all given storage values (it uses `localStorage.set()`).
|
|
29
|
-
*
|
|
30
|
-
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
31
|
-
* and `null` values are removed from the storage
|
|
32
|
-
*/
|
|
33
6
|
setMany(newValues: Partial<T>): void;
|
|
34
|
-
/**
|
|
35
|
-
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
36
|
-
*/
|
|
37
7
|
has<TKey_2 extends Extract<keyof T, string>>(key: TKey_2): any;
|
|
38
|
-
/**
|
|
39
|
-
* Remove a storage value (it uses `localStorage.remove()`).
|
|
40
|
-
*/
|
|
41
8
|
remove<TKey_3 extends Extract<keyof T, string>>(key: TKey_3): void;
|
|
42
|
-
/**
|
|
43
|
-
* Clear all storage values (it uses `localStorage.remove()`).
|
|
44
|
-
*/
|
|
45
9
|
clear(): void;
|
|
46
|
-
/**
|
|
47
|
-
* Watch a storage value changes, this needs to be executed only in browser
|
|
48
|
-
* context (it uses `window.addEventListener("storage")`).
|
|
49
|
-
*
|
|
50
|
-
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
51
|
-
*/
|
|
52
10
|
watch: <TKey_4 extends keyof T>(keyToWatch: TKey_4, onRemoved?: () => void, onAdded?: () => void) => () => void | undefined;
|
|
53
11
|
};
|
|
54
12
|
export default createStorage;
|
package/createStorage.js
CHANGED
|
@@ -1,43 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var isBrowser_1 = tslib_1.__importDefault(require("@koine/utils/isBrowser"));
|
|
8
|
-
var isNullOrUndefined_1 = tslib_1.__importDefault(require("@koine/utils/isNullOrUndefined"));
|
|
9
|
-
var noop_1 = tslib_1.__importDefault(require("@koine/utils/noop"));
|
|
10
|
-
var on_1 = tslib_1.__importDefault(require("@koine/dom/on"));
|
|
11
|
-
var storage_1 = tslib_1.__importDefault(require("./storage"));
|
|
12
|
-
/**
|
|
13
|
-
* Utility to create a storage instance to interact with `localStorage` using
|
|
14
|
-
* encrypted (encoded) key/values.
|
|
15
|
-
*/
|
|
16
|
-
var createStorage = function (config, useSessionStorage) {
|
|
17
|
-
var client = useSessionStorage ? storage_1.default.s : storage_1.default.l;
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { decode, encode, isBrowser, isNullOrUndefined, noop, } from "@koine/utils";
|
|
3
|
+
import { on } from "@koine/dom";
|
|
4
|
+
import storage from "./storage.js";
|
|
5
|
+
export var createStorage = function (config, useSessionStorage) {
|
|
6
|
+
var client = useSessionStorage ? storage.s : storage.l;
|
|
18
7
|
var keys = Object.keys(config).reduce(function (map, key) {
|
|
19
8
|
var _a;
|
|
20
|
-
return (
|
|
9
|
+
return (__assign(__assign({}, map), (_a = {}, _a[key] = encode(key), _a)));
|
|
21
10
|
}, {});
|
|
22
11
|
return {
|
|
23
|
-
/**
|
|
24
|
-
* Get all storage value (it uses `localStorage.get()`).
|
|
25
|
-
*
|
|
26
|
-
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
27
|
-
* On ssr or if the given `key` argument is not found `defaultValue` is
|
|
28
|
-
* returned, otherwise `null`.
|
|
29
|
-
*/
|
|
30
12
|
get: function (key, defaultValue) {
|
|
31
|
-
return client.get(keys[key],
|
|
13
|
+
return client.get(keys[key], decode, defaultValue);
|
|
32
14
|
},
|
|
33
|
-
/**
|
|
34
|
-
* Get all storage values (it uses `localStorage.get()`).
|
|
35
|
-
*
|
|
36
|
-
* `undefined` and `null` values are not returned.
|
|
37
|
-
*/
|
|
38
15
|
getAll: function (defaultValues) {
|
|
39
|
-
if (!
|
|
40
|
-
if (process.env["NODE_ENV"]
|
|
16
|
+
if (!isBrowser) {
|
|
17
|
+
if (process.env["NODE_ENV"] === "development") {
|
|
41
18
|
console.log("[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.");
|
|
42
19
|
}
|
|
43
20
|
return {};
|
|
@@ -46,7 +23,7 @@ var createStorage = function (config, useSessionStorage) {
|
|
|
46
23
|
for (var key in keys) {
|
|
47
24
|
var value = this.get(key);
|
|
48
25
|
var defaultValue = defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues[key];
|
|
49
|
-
if (!(
|
|
26
|
+
if (!isNullOrUndefined(value)) {
|
|
50
27
|
all[key] = value;
|
|
51
28
|
}
|
|
52
29
|
else if (defaultValue) {
|
|
@@ -55,30 +32,19 @@ var createStorage = function (config, useSessionStorage) {
|
|
|
55
32
|
}
|
|
56
33
|
return all;
|
|
57
34
|
},
|
|
58
|
-
/**
|
|
59
|
-
* Set a storage value (it uses `localStorage.set()`).
|
|
60
|
-
*
|
|
61
|
-
* Non-string values are stringified with `JSON.stringify()`
|
|
62
|
-
*/
|
|
63
35
|
set: function (key, value) {
|
|
64
|
-
client.set(keys[key], value,
|
|
36
|
+
client.set(keys[key], value, encode);
|
|
65
37
|
},
|
|
66
|
-
/**
|
|
67
|
-
* Set all given storage values (it uses `localStorage.set()`).
|
|
68
|
-
*
|
|
69
|
-
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
70
|
-
* and `null` values are removed from the storage
|
|
71
|
-
*/
|
|
72
38
|
setMany: function (newValues) {
|
|
73
|
-
if (process.env["NODE_ENV"]
|
|
74
|
-
if (!
|
|
39
|
+
if (process.env["NODE_ENV"] === "development") {
|
|
40
|
+
if (!isBrowser) {
|
|
75
41
|
console.log("[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.");
|
|
76
42
|
}
|
|
77
43
|
}
|
|
78
|
-
if (
|
|
44
|
+
if (isBrowser) {
|
|
79
45
|
for (var key in newValues) {
|
|
80
46
|
var value = newValues[key];
|
|
81
|
-
if (!(
|
|
47
|
+
if (!isNullOrUndefined(value)) {
|
|
82
48
|
this.set(key, value);
|
|
83
49
|
}
|
|
84
50
|
else {
|
|
@@ -87,45 +53,30 @@ var createStorage = function (config, useSessionStorage) {
|
|
|
87
53
|
}
|
|
88
54
|
}
|
|
89
55
|
},
|
|
90
|
-
/**
|
|
91
|
-
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
92
|
-
*/
|
|
93
56
|
has: function (key) {
|
|
94
57
|
return client.has(keys[key]);
|
|
95
58
|
},
|
|
96
|
-
/**
|
|
97
|
-
* Remove a storage value (it uses `localStorage.remove()`).
|
|
98
|
-
*/
|
|
99
59
|
remove: function (key) {
|
|
100
60
|
client.remove(keys[key]);
|
|
101
61
|
},
|
|
102
|
-
/**
|
|
103
|
-
* Clear all storage values (it uses `localStorage.remove()`).
|
|
104
|
-
*/
|
|
105
62
|
clear: function () {
|
|
106
|
-
if (process.env["NODE_ENV"]
|
|
107
|
-
if (!
|
|
63
|
+
if (process.env["NODE_ENV"] === "development") {
|
|
64
|
+
if (!isBrowser) {
|
|
108
65
|
console.log("[@koine/utils:createStorage] attempt to use 'clear' outside of browser.");
|
|
109
66
|
}
|
|
110
67
|
}
|
|
111
|
-
if (
|
|
68
|
+
if (isBrowser) {
|
|
112
69
|
for (var key in keys) {
|
|
113
70
|
client.remove(keys[key]);
|
|
114
71
|
}
|
|
115
72
|
}
|
|
116
73
|
},
|
|
117
|
-
/**
|
|
118
|
-
* Watch a storage value changes, this needs to be executed only in browser
|
|
119
|
-
* context (it uses `window.addEventListener("storage")`).
|
|
120
|
-
*
|
|
121
|
-
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
122
|
-
*/
|
|
123
74
|
watch: function (keyToWatch, onRemoved, onAdded) {
|
|
124
|
-
if (!
|
|
125
|
-
if (process.env["NODE_ENV"]
|
|
75
|
+
if (!isBrowser) {
|
|
76
|
+
if (process.env["NODE_ENV"] === "development") {
|
|
126
77
|
console.log("[@koine/utils:createStorage] attempt to use 'watch' outside of browser.");
|
|
127
78
|
}
|
|
128
|
-
return
|
|
79
|
+
return noop;
|
|
129
80
|
}
|
|
130
81
|
var handler = function (event) {
|
|
131
82
|
var key = event.key, oldValue = event.oldValue, newValue = event.newValue;
|
|
@@ -138,10 +89,9 @@ var createStorage = function (config, useSessionStorage) {
|
|
|
138
89
|
}
|
|
139
90
|
}
|
|
140
91
|
};
|
|
141
|
-
var listener = (
|
|
92
|
+
var listener = on(window, "storage", handler);
|
|
142
93
|
return listener;
|
|
143
94
|
},
|
|
144
95
|
};
|
|
145
96
|
};
|
|
146
|
-
|
|
147
|
-
exports.default = exports.createStorage;
|
|
97
|
+
export default createStorage;
|
package/getZonedDate.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It returns a `Date` object from a date `string` adjusted on the user timeZone,
|
|
3
|
-
* if a timeZone is not provided we try getting it from the `Intl` browwser native
|
|
4
|
-
* API. It gracefully falls back returning a _non-timezone-based_ `Date`.
|
|
5
|
-
*
|
|
6
|
-
* @category date
|
|
7
|
-
*
|
|
8
|
-
* @resources
|
|
9
|
-
* - to get the timeZone client side see [this article](https://attacomsian.com/blog/javascript-current-timezone)
|
|
10
|
-
* - for converting the date based on the time zone [date-fns docs](https://date-fns.org/v2.27.0/docs/Time-Zones) and [date-fns-tz docs](https://github.com/marnusw/date-fns-tz)
|
|
11
|
-
*
|
|
12
|
-
* @param dateString A parseable date as string, `Z` is automatically suffixed if not present to correctly get time zone based time from a UTC date.
|
|
13
|
-
* @param timeZone Optionally pass a timeZone (e.g. from user preference or from the server), it falls back trying to read it from the `Intl` browwser native API.
|
|
14
|
-
*/
|
|
15
1
|
export declare function getZonedDate(dateString?: string, timeZone?: string): Date;
|
|
16
2
|
export default getZonedDate;
|
package/getZonedDate.js
CHANGED
|
@@ -1,42 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var utcToZonedTime_1 = tslib_1.__importDefault(require("date-fns-tz/utcToZonedTime"));
|
|
6
|
-
var isBrowser_1 = tslib_1.__importDefault(require("@koine/utils/isBrowser"));
|
|
7
|
-
/**
|
|
8
|
-
* It returns a `Date` object from a date `string` adjusted on the user timeZone,
|
|
9
|
-
* if a timeZone is not provided we try getting it from the `Intl` browwser native
|
|
10
|
-
* API. It gracefully falls back returning a _non-timezone-based_ `Date`.
|
|
11
|
-
*
|
|
12
|
-
* @category date
|
|
13
|
-
*
|
|
14
|
-
* @resources
|
|
15
|
-
* - to get the timeZone client side see [this article](https://attacomsian.com/blog/javascript-current-timezone)
|
|
16
|
-
* - for converting the date based on the time zone [date-fns docs](https://date-fns.org/v2.27.0/docs/Time-Zones) and [date-fns-tz docs](https://github.com/marnusw/date-fns-tz)
|
|
17
|
-
*
|
|
18
|
-
* @param dateString A parseable date as string, `Z` is automatically suffixed if not present to correctly get time zone based time from a UTC date.
|
|
19
|
-
* @param timeZone Optionally pass a timeZone (e.g. from user preference or from the server), it falls back trying to read it from the `Intl` browwser native API.
|
|
20
|
-
*/
|
|
21
|
-
function getZonedDate(dateString, timeZone) {
|
|
1
|
+
import utcToZonedTime from "date-fns-tz/utcToZonedTime";
|
|
2
|
+
import { isBrowser } from "@koine/utils";
|
|
3
|
+
export function getZonedDate(dateString, timeZone) {
|
|
22
4
|
if (dateString === void 0) { dateString = ""; }
|
|
23
5
|
if (!dateString.endsWith("Z"))
|
|
24
6
|
dateString += "Z";
|
|
25
|
-
if (!timeZone &&
|
|
7
|
+
if (!timeZone && isBrowser) {
|
|
26
8
|
try {
|
|
27
9
|
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
28
10
|
}
|
|
29
11
|
catch (e) {
|
|
30
|
-
if (process.env["NODE_ENV"]
|
|
12
|
+
if (process.env["NODE_ENV"] === "development") {
|
|
31
13
|
console.warn("[@koine/utils:getZonedDate] failed reading timeZone, error", e);
|
|
32
14
|
}
|
|
33
|
-
// no need to do anything here, it just means `Intl` failed, probably
|
|
34
|
-
// because the browser does not support it
|
|
35
15
|
}
|
|
36
16
|
}
|
|
37
17
|
return timeZone
|
|
38
|
-
? (
|
|
18
|
+
? utcToZonedTime(new Date(dateString), timeZone)
|
|
39
19
|
: new Date(dateString);
|
|
40
20
|
}
|
|
41
|
-
|
|
42
|
-
exports.default = getZonedDate;
|
|
21
|
+
export default getZonedDate;
|
package/gtagPageview.d.ts
CHANGED
|
@@ -3,8 +3,5 @@ export type GtmPageviewArgs = [
|
|
|
3
3
|
page_title?: string,
|
|
4
4
|
page_location?: string
|
|
5
5
|
];
|
|
6
|
-
/**
|
|
7
|
-
* @category analytics-google
|
|
8
|
-
*/
|
|
9
6
|
export declare const gtagPageview: (page_path?: string | undefined, page_title?: string | undefined, page_location?: string | undefined) => void;
|
|
10
7
|
export default gtagPageview;
|
package/gtagPageview.js
CHANGED
|
@@ -1,35 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.gtagPageview = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var isUndefined_1 = tslib_1.__importDefault(require("@koine/utils/isUndefined"));
|
|
6
|
-
/**
|
|
7
|
-
* @category analytics-google
|
|
8
|
-
*/
|
|
9
|
-
var gtagPageview = function () {
|
|
1
|
+
import { isUndefined } from "@koine/utils";
|
|
2
|
+
export var gtagPageview = function () {
|
|
10
3
|
var args = [];
|
|
11
4
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
5
|
args[_i] = arguments[_i];
|
|
13
6
|
}
|
|
14
|
-
if (!(
|
|
7
|
+
if (!isUndefined(window) && !isUndefined(window.gtag)) {
|
|
15
8
|
window.gtag("event", "page_view", {
|
|
16
9
|
page_path: args[0] || location.pathname,
|
|
17
10
|
page_title: args[1] || document.title,
|
|
18
11
|
page_location: args[2] || location.href,
|
|
19
|
-
// send_to: '<GA_MEASUREMENT_ID>'
|
|
20
12
|
});
|
|
21
13
|
}
|
|
22
14
|
};
|
|
23
|
-
|
|
24
|
-
exports.default = exports.gtagPageview;
|
|
25
|
-
// export type GtmEventArgs = [
|
|
26
|
-
// eventCategory?: string,
|
|
27
|
-
// eventAction?: string,
|
|
28
|
-
// eventLabel?: string,
|
|
29
|
-
// eventValue?: string
|
|
30
|
-
// ];
|
|
31
|
-
// export const event = (...args: GtmEventArgs) => {
|
|
32
|
-
// if (!isUndefined(window) && !isUndefined(window.gtag)) {
|
|
33
|
-
// window.gtag("send", "event", ...args);
|
|
34
|
-
// }
|
|
35
|
-
// };
|
|
15
|
+
export default gtagPageview;
|
package/index.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
export { createStorage, type CreateStorageConfig } from "./createStorage";
|
|
2
|
-
export { getZonedDate } from "./getZonedDate";
|
|
3
|
-
export { gtagPageview, type GtmPageviewArgs } from "./gtagPageview";
|
|
4
|
-
export { isIE } from "./isIE";
|
|
5
|
-
export { isMobile } from "./isMobile";
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
1
|
+
export { createStorage, type CreateStorageConfig } from "./createStorage.js";
|
|
2
|
+
export { getZonedDate } from "./getZonedDate.js";
|
|
3
|
+
export { gtagPageview, type GtmPageviewArgs } from "./gtagPageview.js";
|
|
4
|
+
export { isIE } from "./isIE.js";
|
|
5
|
+
export { isMobile } from "./isMobile.js";
|
|
6
|
+
export { listenUrlSearch } from "./listenUrlSearch.js";
|
|
7
|
+
export { listenUrlSearchParams } from "./listenUrlSearchParams.js";
|
|
8
|
+
export { navigateToHash } from "./navigateToHash.js";
|
|
9
|
+
export { navigateToHashParams } from "./navigateToHashParams.js";
|
|
10
|
+
export { navigateToMergedHashParams } from "./navigateToMergedHashParams.js";
|
|
11
|
+
export { navigateToMergedParams } from "./navigateToMergedParams.js";
|
|
12
|
+
export { navigateToParams } from "./navigateToParams.js";
|
|
13
|
+
export { navigateToUrl } from "./navigateToUrl.js";
|
|
14
|
+
export { navigateWithoutUrlParam } from "./navigateWithoutUrlParam.js";
|
|
15
|
+
export { redirectTo } from "./redirectTo.js";
|
|
16
|
+
export { storage } from "./storage.js";
|
|
17
|
+
export { storageClient, type StorageClientConfig } from "./storageClient.js";
|
package/index.js
CHANGED
|
@@ -1,33 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var navigateToMergedHashParams_1 = require("./navigateToMergedHashParams");
|
|
19
|
-
Object.defineProperty(exports, "navigateToMergedHashParams", { enumerable: true, get: function () { return navigateToMergedHashParams_1.navigateToMergedHashParams; } });
|
|
20
|
-
var navigateToMergedParams_1 = require("./navigateToMergedParams");
|
|
21
|
-
Object.defineProperty(exports, "navigateToMergedParams", { enumerable: true, get: function () { return navigateToMergedParams_1.navigateToMergedParams; } });
|
|
22
|
-
var navigateToParams_1 = require("./navigateToParams");
|
|
23
|
-
Object.defineProperty(exports, "navigateToParams", { enumerable: true, get: function () { return navigateToParams_1.navigateToParams; } });
|
|
24
|
-
var navigateToUrl_1 = require("./navigateToUrl");
|
|
25
|
-
Object.defineProperty(exports, "navigateToUrl", { enumerable: true, get: function () { return navigateToUrl_1.navigateToUrl; } });
|
|
26
|
-
var navigateWithoutUrlParam_1 = require("./navigateWithoutUrlParam");
|
|
27
|
-
Object.defineProperty(exports, "navigateWithoutUrlParam", { enumerable: true, get: function () { return navigateWithoutUrlParam_1.navigateWithoutUrlParam; } });
|
|
28
|
-
var redirectTo_1 = require("./redirectTo");
|
|
29
|
-
Object.defineProperty(exports, "redirectTo", { enumerable: true, get: function () { return redirectTo_1.redirectTo; } });
|
|
30
|
-
var storage_1 = require("./storage");
|
|
31
|
-
Object.defineProperty(exports, "storage", { enumerable: true, get: function () { return storage_1.storage; } });
|
|
32
|
-
var storageClient_1 = require("./storageClient");
|
|
33
|
-
Object.defineProperty(exports, "storageClient", { enumerable: true, get: function () { return storageClient_1.storageClient; } });
|
|
1
|
+
export { createStorage } from "./createStorage.js";
|
|
2
|
+
export { getZonedDate } from "./getZonedDate.js";
|
|
3
|
+
export { gtagPageview } from "./gtagPageview.js";
|
|
4
|
+
export { isIE } from "./isIE.js";
|
|
5
|
+
export { isMobile } from "./isMobile.js";
|
|
6
|
+
export { listenUrlSearch } from "./listenUrlSearch.js";
|
|
7
|
+
export { listenUrlSearchParams } from "./listenUrlSearchParams.js";
|
|
8
|
+
export { navigateToHash } from "./navigateToHash.js";
|
|
9
|
+
export { navigateToHashParams } from "./navigateToHashParams.js";
|
|
10
|
+
export { navigateToMergedHashParams } from "./navigateToMergedHashParams.js";
|
|
11
|
+
export { navigateToMergedParams } from "./navigateToMergedParams.js";
|
|
12
|
+
export { navigateToParams } from "./navigateToParams.js";
|
|
13
|
+
export { navigateToUrl } from "./navigateToUrl.js";
|
|
14
|
+
export { navigateWithoutUrlParam } from "./navigateWithoutUrlParam.js";
|
|
15
|
+
export { redirectTo } from "./redirectTo.js";
|
|
16
|
+
export { storage } from "./storage.js";
|
|
17
|
+
export { storageClient } from "./storageClient.js";
|
package/isIE.d.ts
CHANGED
package/isIE.js
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isIE = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var isServer_1 = tslib_1.__importDefault(require("@koine/utils/isServer"));
|
|
6
|
-
/**
|
|
7
|
-
* @category detect
|
|
8
|
-
* @category is
|
|
9
|
-
* @see https://stackoverflow.com/a/21712356/12285349
|
|
10
|
-
*/
|
|
11
|
-
function isIE(ssrValue) {
|
|
1
|
+
import { isServer } from "@koine/utils";
|
|
2
|
+
export function isIE(ssrValue) {
|
|
12
3
|
if (ssrValue === void 0) { ssrValue = true; }
|
|
13
|
-
if (
|
|
4
|
+
if (isServer) {
|
|
14
5
|
return ssrValue;
|
|
15
6
|
}
|
|
16
7
|
var ua = window.navigator.userAgent;
|
|
@@ -19,5 +10,4 @@ function isIE(ssrValue) {
|
|
|
19
10
|
}
|
|
20
11
|
return false;
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
exports.default = isIE;
|
|
13
|
+
export default isIE;
|
package/isMobile.d.ts
CHANGED
package/isMobile.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isMobile = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var isServer_1 = tslib_1.__importDefault(require("@koine/utils/isServer"));
|
|
6
|
-
/**
|
|
7
|
-
* @category detect
|
|
8
|
-
* @category is
|
|
9
|
-
* @see https://stackoverflow.com/a/3540295
|
|
10
|
-
*/
|
|
11
|
-
function isMobile(ssrValue) {
|
|
1
|
+
import { isServer } from "@koine/utils";
|
|
2
|
+
export function isMobile(ssrValue) {
|
|
12
3
|
if (ssrValue === void 0) { ssrValue = true; }
|
|
13
|
-
if (
|
|
4
|
+
if (isServer) {
|
|
14
5
|
return ssrValue;
|
|
15
6
|
}
|
|
16
7
|
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(window.navigator.userAgent);
|
|
17
|
-
// return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
|
|
18
|
-
// || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4)
|
|
19
8
|
}
|
|
20
|
-
|
|
21
|
-
exports.default = isMobile;
|
|
9
|
+
export default isMobile;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { __values } from "tslib";
|
|
2
|
+
import { isBrowser } from "@koine/utils";
|
|
3
|
+
import { on } from "@koine/dom";
|
|
4
|
+
function extendHistoryMethod(fn, runHandlers, before) {
|
|
5
|
+
return function interceptor() {
|
|
6
|
+
var args = [];
|
|
7
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
8
|
+
args[_i] = arguments[_i];
|
|
9
|
+
}
|
|
10
|
+
if (before) {
|
|
11
|
+
runHandlers();
|
|
12
|
+
return fn.apply(this, args);
|
|
13
|
+
}
|
|
14
|
+
var result = fn.apply(this, args);
|
|
15
|
+
runHandlers();
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var prevSearch = isBrowser ? location.search : "";
|
|
20
|
+
function runHandlers() {
|
|
21
|
+
var e_1, _a;
|
|
22
|
+
var newSearch = location.search;
|
|
23
|
+
if (newSearch !== prevSearch) {
|
|
24
|
+
var listeners = history.__.h.values();
|
|
25
|
+
try {
|
|
26
|
+
for (var listeners_1 = __values(listeners), listeners_1_1 = listeners_1.next(); !listeners_1_1.done; listeners_1_1 = listeners_1.next()) {
|
|
27
|
+
var listener = listeners_1_1.value;
|
|
28
|
+
listener(prevSearch, newSearch);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
32
|
+
finally {
|
|
33
|
+
try {
|
|
34
|
+
if (listeners_1_1 && !listeners_1_1.done && (_a = listeners_1.return)) _a.call(listeners_1);
|
|
35
|
+
}
|
|
36
|
+
finally { if (e_1) throw e_1.error; }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
prevSearch = newSearch;
|
|
40
|
+
}
|
|
41
|
+
export function listenUrlSearch(handler) {
|
|
42
|
+
if (!history.__) {
|
|
43
|
+
history.pushState = extendHistoryMethod(history.pushState, runHandlers);
|
|
44
|
+
history.replaceState = extendHistoryMethod(history.replaceState, runHandlers);
|
|
45
|
+
on(window, "popstate", runHandlers);
|
|
46
|
+
history.__ = { h: new Set() };
|
|
47
|
+
}
|
|
48
|
+
if (!history.__.h.has(handler)) {
|
|
49
|
+
history.__.h.add(handler);
|
|
50
|
+
}
|
|
51
|
+
return function () {
|
|
52
|
+
history.__.h.delete(handler);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export default listenUrlSearch;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import listenUrlSearch from "./listenUrlSearch.js";
|
|
2
|
+
export var listenUrlSearchParams = function (paramName, handler) {
|
|
3
|
+
return listenUrlSearch(function (prevSearch, newSearch) {
|
|
4
|
+
var prevParams = new URLSearchParams(prevSearch);
|
|
5
|
+
var newParams = new URLSearchParams(newSearch);
|
|
6
|
+
var newValue = newParams.get(paramName);
|
|
7
|
+
if (prevParams.get(paramName) !== newValue) {
|
|
8
|
+
handler(newValue);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export default listenUrlSearchParams;
|
package/navigateToHash.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It updates the browser's location hash by replacing the history state.
|
|
3
|
-
* The non-silent standard way would simply be `location.hash = "#new-hash"`
|
|
4
|
-
*
|
|
5
|
-
* @category location
|
|
6
|
-
*/
|
|
7
1
|
export declare function navigateToHash(hash?: string): void;
|
|
8
2
|
export default navigateToHash;
|
package/navigateToHash.js
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.navigateToHash = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var navigateToUrl_1 = tslib_1.__importDefault(require("./navigateToUrl"));
|
|
6
|
-
/**
|
|
7
|
-
* It updates the browser's location hash by replacing the history state.
|
|
8
|
-
* The non-silent standard way would simply be `location.hash = "#new-hash"`
|
|
9
|
-
*
|
|
10
|
-
* @category location
|
|
11
|
-
*/
|
|
12
|
-
function navigateToHash(hash) {
|
|
1
|
+
import navigateToUrl from "./navigateToUrl.js";
|
|
2
|
+
export function navigateToHash(hash) {
|
|
13
3
|
if (hash === void 0) { hash = ""; }
|
|
14
4
|
var pathname = location.pathname, search = location.search;
|
|
15
|
-
(
|
|
5
|
+
navigateToUrl(pathname + (search ? "?" + search : "") + (hash ? "#" + hash : ""), true);
|
|
16
6
|
}
|
|
17
|
-
|
|
18
|
-
exports.default = navigateToHash;
|
|
7
|
+
export default navigateToHash;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
/**
|
|
3
|
-
* It updates the `location.hash` with the given query params, it uses `location.hash`
|
|
4
|
-
* if a second argument `hash` is not provded
|
|
5
|
-
*
|
|
6
|
-
* @category location
|
|
7
|
-
*/
|
|
1
|
+
import { type AnyQueryParams } from "@koine/utils";
|
|
8
2
|
export declare function navigateToHashParams(params?: string | AnyQueryParams, hash?: string): string;
|
|
9
3
|
export default navigateToHashParams;
|