@koine/browser 2.0.0-alpha.4 → 2.0.0-beta.10
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 +5 -0
- package/createStorage.js +94 -94
- package/createStorage.mjs +59 -69
- package/getZonedDate.js +28 -33
- package/getZonedDate.mjs +6 -12
- package/gtagPageview.js +33 -27
- package/gtagPageview.mjs +13 -20
- package/index.js +71 -32
- package/isIE.js +23 -15
- package/isIE.mjs +2 -4
- package/isMobile.js +24 -16
- package/isMobile.mjs +3 -5
- package/navigateToHash.js +23 -16
- package/navigateToHash.mjs +2 -4
- package/navigateToHashParams.js +26 -20
- package/navigateToHashParams.mjs +5 -8
- package/navigateToMergedHashParams.js +24 -17
- package/navigateToMergedHashParams.mjs +2 -5
- package/navigateToMergedParams.js +24 -17
- package/navigateToMergedParams.mjs +2 -4
- package/navigateToParams.js +26 -20
- package/navigateToParams.mjs +3 -5
- package/navigateToUrl.js +20 -8
- package/navigateToUrl.mjs +1 -3
- package/navigateWithoutUrlParam.js +25 -17
- package/navigateWithoutUrlParam.mjs +4 -5
- package/package.json +9 -7
- package/redirectTo.js +23 -15
- package/redirectTo.mjs +3 -4
- package/storage.d.ts +2 -0
- package/storage.js +23 -11
- package/storage.mjs +4 -3
- package/storageClient.d.ts +5 -0
- package/storageClient.js +70 -66
- package/storageClient.mjs +43 -49
package/createStorage.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category storage
|
|
3
|
+
*/
|
|
1
4
|
export type CreateStorageConfig = Record<string, any>;
|
|
2
5
|
/**
|
|
3
6
|
* Utility to create a storage instance to interact with `localStorage` using
|
|
4
7
|
* encrypted (encoded) key/values.
|
|
8
|
+
*
|
|
9
|
+
* @category storage
|
|
5
10
|
*/
|
|
6
11
|
export declare const createStorage: <T extends CreateStorageConfig>(config: Partial<T>, useSessionStorage?: boolean) => {
|
|
7
12
|
/**
|
package/createStorage.js
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
createStorage: function() {
|
|
13
|
+
return createStorage;
|
|
14
|
+
},
|
|
15
|
+
default: function() {
|
|
16
|
+
return _default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
+
const _decode = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/decode"));
|
|
21
|
+
const _encode = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/encode"));
|
|
22
|
+
const _isBrowser = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isBrowser"));
|
|
23
|
+
const _isNullOrUndefined = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isNullOrUndefined"));
|
|
24
|
+
const _noop = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/noop"));
|
|
25
|
+
const _on = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/on"));
|
|
26
|
+
const _storage = /*#__PURE__*/ _interop_require_default._(require("./storage"));
|
|
27
|
+
const createStorage = (config, useSessionStorage)=>{
|
|
28
|
+
const client = useSessionStorage ? _storage.default.s : _storage.default.l;
|
|
29
|
+
const keys = Object.keys(config).reduce((map, key)=>({
|
|
30
|
+
...map,
|
|
31
|
+
[key]: (0, _encode.default)(key)
|
|
32
|
+
}), {});
|
|
22
33
|
return {
|
|
23
34
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return client.get(keys[key], decode_1.default, defaultValue);
|
|
35
|
+
* Get all storage value (it uses `localStorage.get()`).
|
|
36
|
+
*
|
|
37
|
+
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
38
|
+
* On ssr or if the given `key` argument is not found `defaultValue` is
|
|
39
|
+
* returned, otherwise `null`.
|
|
40
|
+
*/ get (key, defaultValue) {
|
|
41
|
+
return client.get(keys[key], _decode.default, defaultValue);
|
|
32
42
|
},
|
|
33
43
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!isBrowser_1.default) {
|
|
44
|
+
* Get all storage values (it uses `localStorage.get()`).
|
|
45
|
+
*
|
|
46
|
+
* `undefined` and `null` values are not returned.
|
|
47
|
+
*/ getAll (defaultValues) {
|
|
48
|
+
if (!_isBrowser.default) {
|
|
40
49
|
if (process.env["NODE_ENV"] !== "production") {
|
|
41
|
-
console.log(
|
|
50
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.`);
|
|
42
51
|
}
|
|
43
52
|
return {};
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
for
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!(0,
|
|
54
|
+
const all = {};
|
|
55
|
+
for(const key in keys){
|
|
56
|
+
const value = this.get(key);
|
|
57
|
+
const defaultValue = defaultValues?.[key];
|
|
58
|
+
if (!(0, _isNullOrUndefined.default)(value)) {
|
|
50
59
|
all[key] = value;
|
|
51
|
-
}
|
|
52
|
-
|
|
60
|
+
} else if (defaultValue) {
|
|
61
|
+
// NOTE: without the assertion typedoc does not compile
|
|
53
62
|
all[key] = defaultValue;
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
65
|
return all;
|
|
57
66
|
},
|
|
58
67
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
client.set(keys[key], value, encode_1.default);
|
|
68
|
+
* Set a storage value (it uses `localStorage.set()`).
|
|
69
|
+
*
|
|
70
|
+
* Non-string values are stringified with `JSON.stringify()`
|
|
71
|
+
*/ set (key, value) {
|
|
72
|
+
client.set(keys[key], value, _encode.default);
|
|
65
73
|
},
|
|
66
74
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
setMany: function (newValues) {
|
|
75
|
+
* Set all given storage values (it uses `localStorage.set()`).
|
|
76
|
+
*
|
|
77
|
+
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
78
|
+
* and `null` values are removed from the storage
|
|
79
|
+
*/ setMany (newValues) {
|
|
73
80
|
if (process.env["NODE_ENV"] !== "production") {
|
|
74
|
-
if (!
|
|
75
|
-
console.log(
|
|
81
|
+
if (!_isBrowser.default) {
|
|
82
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.`);
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
|
-
if (
|
|
79
|
-
for
|
|
80
|
-
|
|
81
|
-
if (!(0,
|
|
85
|
+
if (_isBrowser.default) {
|
|
86
|
+
for(const key in newValues){
|
|
87
|
+
const value = newValues[key];
|
|
88
|
+
if (!(0, _isNullOrUndefined.default)(value)) {
|
|
82
89
|
this.set(key, value);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
90
|
+
} else {
|
|
85
91
|
this.remove(key);
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
95
|
},
|
|
90
96
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
has: function (key) {
|
|
97
|
+
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
98
|
+
*/ has (key) {
|
|
94
99
|
return client.has(keys[key]);
|
|
95
100
|
},
|
|
96
101
|
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
remove: function (key) {
|
|
102
|
+
* Remove a storage value (it uses `localStorage.remove()`).
|
|
103
|
+
*/ remove (key) {
|
|
100
104
|
client.remove(keys[key]);
|
|
101
105
|
},
|
|
102
106
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
clear: function () {
|
|
107
|
+
* Clear all storage values (it uses `localStorage.remove()`).
|
|
108
|
+
*/ clear () {
|
|
106
109
|
if (process.env["NODE_ENV"] !== "production") {
|
|
107
|
-
if (!
|
|
108
|
-
console.log(
|
|
110
|
+
if (!_isBrowser.default) {
|
|
111
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
if (
|
|
112
|
-
for
|
|
114
|
+
if (_isBrowser.default) {
|
|
115
|
+
for(const key in keys){
|
|
113
116
|
client.remove(keys[key]);
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
},
|
|
117
120
|
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (!isBrowser_1.default) {
|
|
121
|
+
* Watch a storage value changes, this needs to be executed only in browser
|
|
122
|
+
* context (it uses `window.addEventListener("storage")`).
|
|
123
|
+
*
|
|
124
|
+
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
125
|
+
*/ watch: (keyToWatch, onRemoved, onAdded)=>{
|
|
126
|
+
if (!_isBrowser.default) {
|
|
125
127
|
if (process.env["NODE_ENV"] !== "production") {
|
|
126
|
-
console.log(
|
|
128
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
|
|
127
129
|
}
|
|
128
|
-
return
|
|
130
|
+
return _noop.default;
|
|
129
131
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
const handler = (event)=>{
|
|
133
|
+
const { key, oldValue, newValue } = event;
|
|
132
134
|
if (key === keys[keyToWatch]) {
|
|
133
135
|
if (oldValue && !newValue) {
|
|
134
|
-
onRemoved
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
onAdded === null || onAdded === void 0 ? void 0 : onAdded();
|
|
136
|
+
onRemoved?.();
|
|
137
|
+
} else if (!oldValue && newValue) {
|
|
138
|
+
onAdded?.();
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
};
|
|
141
|
-
|
|
142
|
+
const listener = (0, _on.default)(window, "storage", handler);
|
|
142
143
|
return listener;
|
|
143
|
-
}
|
|
144
|
+
}
|
|
144
145
|
};
|
|
145
146
|
};
|
|
146
|
-
|
|
147
|
-
exports.default = exports.createStorage;
|
|
147
|
+
const _default = createStorage;
|
package/createStorage.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import decode from "@koine/utils/decode";
|
|
3
2
|
import encode from "@koine/utils/encode";
|
|
4
3
|
import isBrowser from "@koine/utils/isBrowser";
|
|
@@ -9,135 +8,126 @@ import storage from "./storage";
|
|
|
9
8
|
/**
|
|
10
9
|
* Utility to create a storage instance to interact with `localStorage` using
|
|
11
10
|
* encrypted (encoded) key/values.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
*
|
|
12
|
+
* @category storage
|
|
13
|
+
*/ export const createStorage = (config, useSessionStorage)=>{
|
|
14
|
+
const client = useSessionStorage ? storage.s : storage.l;
|
|
15
|
+
const keys = Object.keys(config).reduce((map, key)=>({
|
|
16
|
+
...map,
|
|
17
|
+
[key]: encode(key)
|
|
18
|
+
}), {});
|
|
19
19
|
return {
|
|
20
20
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
get: function (key, defaultValue) {
|
|
21
|
+
* Get all storage value (it uses `localStorage.get()`).
|
|
22
|
+
*
|
|
23
|
+
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
24
|
+
* On ssr or if the given `key` argument is not found `defaultValue` is
|
|
25
|
+
* returned, otherwise `null`.
|
|
26
|
+
*/ get (key, defaultValue) {
|
|
28
27
|
return client.get(keys[key], decode, defaultValue);
|
|
29
28
|
},
|
|
30
29
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
getAll: function (defaultValues) {
|
|
30
|
+
* Get all storage values (it uses `localStorage.get()`).
|
|
31
|
+
*
|
|
32
|
+
* `undefined` and `null` values are not returned.
|
|
33
|
+
*/ getAll (defaultValues) {
|
|
36
34
|
if (!isBrowser) {
|
|
37
35
|
if (process.env["NODE_ENV"] !== "production") {
|
|
38
|
-
console.log(
|
|
36
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.`);
|
|
39
37
|
}
|
|
40
38
|
return {};
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
for
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
const all = {};
|
|
41
|
+
for(const key in keys){
|
|
42
|
+
const value = this.get(key);
|
|
43
|
+
const defaultValue = defaultValues?.[key];
|
|
46
44
|
if (!isNullOrUndefined(value)) {
|
|
47
45
|
all[key] = value;
|
|
48
|
-
}
|
|
49
|
-
|
|
46
|
+
} else if (defaultValue) {
|
|
47
|
+
// NOTE: without the assertion typedoc does not compile
|
|
50
48
|
all[key] = defaultValue;
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
return all;
|
|
54
52
|
},
|
|
55
53
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
set: function (key, value) {
|
|
54
|
+
* Set a storage value (it uses `localStorage.set()`).
|
|
55
|
+
*
|
|
56
|
+
* Non-string values are stringified with `JSON.stringify()`
|
|
57
|
+
*/ set (key, value) {
|
|
61
58
|
client.set(keys[key], value, encode);
|
|
62
59
|
},
|
|
63
60
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
setMany: function (newValues) {
|
|
61
|
+
* Set all given storage values (it uses `localStorage.set()`).
|
|
62
|
+
*
|
|
63
|
+
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
64
|
+
* and `null` values are removed from the storage
|
|
65
|
+
*/ setMany (newValues) {
|
|
70
66
|
if (process.env["NODE_ENV"] !== "production") {
|
|
71
67
|
if (!isBrowser) {
|
|
72
|
-
console.log(
|
|
68
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.`);
|
|
73
69
|
}
|
|
74
70
|
}
|
|
75
71
|
if (isBrowser) {
|
|
76
|
-
for
|
|
77
|
-
|
|
72
|
+
for(const key in newValues){
|
|
73
|
+
const value = newValues[key];
|
|
78
74
|
if (!isNullOrUndefined(value)) {
|
|
79
75
|
this.set(key, value);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
76
|
+
} else {
|
|
82
77
|
this.remove(key);
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
81
|
},
|
|
87
82
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
has: function (key) {
|
|
83
|
+
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
84
|
+
*/ has (key) {
|
|
91
85
|
return client.has(keys[key]);
|
|
92
86
|
},
|
|
93
87
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
remove: function (key) {
|
|
88
|
+
* Remove a storage value (it uses `localStorage.remove()`).
|
|
89
|
+
*/ remove (key) {
|
|
97
90
|
client.remove(keys[key]);
|
|
98
91
|
},
|
|
99
92
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
clear: function () {
|
|
93
|
+
* Clear all storage values (it uses `localStorage.remove()`).
|
|
94
|
+
*/ clear () {
|
|
103
95
|
if (process.env["NODE_ENV"] !== "production") {
|
|
104
96
|
if (!isBrowser) {
|
|
105
|
-
console.log(
|
|
97
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
|
|
106
98
|
}
|
|
107
99
|
}
|
|
108
100
|
if (isBrowser) {
|
|
109
|
-
for
|
|
101
|
+
for(const key in keys){
|
|
110
102
|
client.remove(keys[key]);
|
|
111
103
|
}
|
|
112
104
|
}
|
|
113
105
|
},
|
|
114
106
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
watch: function (keyToWatch, onRemoved, onAdded) {
|
|
107
|
+
* Watch a storage value changes, this needs to be executed only in browser
|
|
108
|
+
* context (it uses `window.addEventListener("storage")`).
|
|
109
|
+
*
|
|
110
|
+
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
111
|
+
*/ watch: (keyToWatch, onRemoved, onAdded)=>{
|
|
121
112
|
if (!isBrowser) {
|
|
122
113
|
if (process.env["NODE_ENV"] !== "production") {
|
|
123
|
-
console.log(
|
|
114
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
|
|
124
115
|
}
|
|
125
116
|
return noop;
|
|
126
117
|
}
|
|
127
|
-
|
|
128
|
-
|
|
118
|
+
const handler = (event)=>{
|
|
119
|
+
const { key, oldValue, newValue } = event;
|
|
129
120
|
if (key === keys[keyToWatch]) {
|
|
130
121
|
if (oldValue && !newValue) {
|
|
131
|
-
onRemoved
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
onAdded === null || onAdded === void 0 ? void 0 : onAdded();
|
|
122
|
+
onRemoved?.();
|
|
123
|
+
} else if (!oldValue && newValue) {
|
|
124
|
+
onAdded?.();
|
|
135
125
|
}
|
|
136
126
|
}
|
|
137
127
|
};
|
|
138
|
-
|
|
128
|
+
const listener = on(window, "storage", handler);
|
|
139
129
|
return listener;
|
|
140
|
-
}
|
|
130
|
+
}
|
|
141
131
|
};
|
|
142
132
|
};
|
|
143
133
|
export default createStorage;
|
package/getZonedDate.js
CHANGED
|
@@ -1,42 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!dateString.endsWith("Z"))
|
|
24
|
-
|
|
25
|
-
if (!timeZone && isBrowser_1.default) {
|
|
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
|
+
getZonedDate: function() {
|
|
13
|
+
return getZonedDate;
|
|
14
|
+
},
|
|
15
|
+
default: function() {
|
|
16
|
+
return _default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
+
const _utcToZonedTime = /*#__PURE__*/ _interop_require_default._(require("date-fns-tz/utcToZonedTime"));
|
|
21
|
+
const _isBrowser = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isBrowser"));
|
|
22
|
+
function getZonedDate(dateString = "", timeZone) {
|
|
23
|
+
if (!dateString.endsWith("Z")) dateString += "Z";
|
|
24
|
+
if (!timeZone && _isBrowser.default) {
|
|
26
25
|
try {
|
|
27
26
|
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
27
|
+
} catch (e) {
|
|
30
28
|
if (process.env["NODE_ENV"] !== "production") {
|
|
31
29
|
console.warn("[@koine/utils:getZonedDate] failed reading timeZone, error", e);
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
// no need to do anything here, it just means `Intl` failed, probably
|
|
32
|
+
// because the browser does not support it
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
return timeZone
|
|
38
|
-
? (0, utcToZonedTime_1.default)(new Date(dateString), timeZone)
|
|
39
|
-
: new Date(dateString);
|
|
35
|
+
return timeZone ? (0, _utcToZonedTime.default)(new Date(dateString), timeZone) : new Date(dateString);
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
exports.default = getZonedDate;
|
|
37
|
+
const _default = getZonedDate;
|
package/getZonedDate.mjs
CHANGED
|
@@ -13,25 +13,19 @@ import isBrowser from "@koine/utils/isBrowser";
|
|
|
13
13
|
*
|
|
14
14
|
* @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.
|
|
15
15
|
* @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.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
if (dateString === void 0) { dateString = ""; }
|
|
19
|
-
if (!dateString.endsWith("Z"))
|
|
20
|
-
dateString += "Z";
|
|
16
|
+
*/ export function getZonedDate(dateString = "", timeZone) {
|
|
17
|
+
if (!dateString.endsWith("Z")) dateString += "Z";
|
|
21
18
|
if (!timeZone && isBrowser) {
|
|
22
19
|
try {
|
|
23
20
|
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
21
|
+
} catch (e) {
|
|
26
22
|
if (process.env["NODE_ENV"] !== "production") {
|
|
27
23
|
console.warn("[@koine/utils:getZonedDate] failed reading timeZone, error", e);
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
// no need to do anything here, it just means `Intl` failed, probably
|
|
26
|
+
// because the browser does not support it
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
|
-
return timeZone
|
|
34
|
-
? utcToZonedTime(new Date(dateString), timeZone)
|
|
35
|
-
: new Date(dateString);
|
|
29
|
+
return timeZone ? utcToZonedTime(new Date(dateString), timeZone) : new Date(dateString);
|
|
36
30
|
}
|
|
37
31
|
export default getZonedDate;
|
package/gtagPageview.js
CHANGED
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
gtagPageview: function() {
|
|
13
|
+
return gtagPageview;
|
|
14
|
+
},
|
|
15
|
+
default: function() {
|
|
16
|
+
return _default // export type GtmEventArgs = [
|
|
17
|
+
// eventCategory?: string,
|
|
18
|
+
// eventAction?: string,
|
|
19
|
+
// eventLabel?: string,
|
|
20
|
+
// eventValue?: string
|
|
21
|
+
// ];
|
|
22
|
+
// export const event = (...args: GtmEventArgs) => {
|
|
23
|
+
// if (!isUndefined(window) && !isUndefined(window.gtag)) {
|
|
24
|
+
// window.gtag("send", "event", ...args);
|
|
25
|
+
// }
|
|
26
|
+
// };
|
|
27
|
+
;
|
|
13
28
|
}
|
|
14
|
-
|
|
29
|
+
});
|
|
30
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
31
|
+
const _isUndefined = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isUndefined"));
|
|
32
|
+
const gtagPageview = (...args)=>{
|
|
33
|
+
if (!(0, _isUndefined.default)(window) && !(0, _isUndefined.default)(window.gtag)) {
|
|
15
34
|
window.gtag("event", "page_view", {
|
|
16
35
|
page_path: args[0] || location.pathname,
|
|
17
36
|
page_title: args[1] || document.title,
|
|
18
|
-
page_location: args[2] || location.href
|
|
19
|
-
// send_to: '<GA_MEASUREMENT_ID>'
|
|
37
|
+
page_location: args[2] || location.href
|
|
20
38
|
});
|
|
21
39
|
}
|
|
22
40
|
};
|
|
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
|
-
// };
|
|
41
|
+
const _default = gtagPageview;
|