@koine/browser 2.0.0-beta.2 → 2.0.0-beta.5
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.js +93 -94
- package/createStorage.mjs +56 -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 +12 -10
- package/redirectTo.js +23 -15
- package/redirectTo.mjs +3 -4
- package/storage.js +23 -11
- package/storage.mjs +2 -3
- package/storageClient.js +70 -66
- package/storageClient.mjs +41 -49
package/createStorage.js
CHANGED
|
@@ -1,147 +1,146 @@
|
|
|
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
|
-
else if (defaultValue) {
|
|
60
|
+
} else if (defaultValue) {
|
|
53
61
|
all[key] = defaultValue;
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
return all;
|
|
57
65
|
},
|
|
58
66
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
client.set(keys[key], value, encode_1.default);
|
|
67
|
+
* Set a storage value (it uses `localStorage.set()`).
|
|
68
|
+
*
|
|
69
|
+
* Non-string values are stringified with `JSON.stringify()`
|
|
70
|
+
*/ set (key, value) {
|
|
71
|
+
client.set(keys[key], value, _encode.default);
|
|
65
72
|
},
|
|
66
73
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
setMany: function (newValues) {
|
|
74
|
+
* Set all given storage values (it uses `localStorage.set()`).
|
|
75
|
+
*
|
|
76
|
+
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
77
|
+
* and `null` values are removed from the storage
|
|
78
|
+
*/ setMany (newValues) {
|
|
73
79
|
if (process.env["NODE_ENV"] !== "production") {
|
|
74
|
-
if (!
|
|
75
|
-
console.log(
|
|
80
|
+
if (!_isBrowser.default) {
|
|
81
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.`);
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
|
-
if (
|
|
79
|
-
for
|
|
80
|
-
|
|
81
|
-
if (!(0,
|
|
84
|
+
if (_isBrowser.default) {
|
|
85
|
+
for(const key in newValues){
|
|
86
|
+
const value = newValues[key];
|
|
87
|
+
if (!(0, _isNullOrUndefined.default)(value)) {
|
|
82
88
|
this.set(key, value);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
89
|
+
} else {
|
|
85
90
|
this.remove(key);
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
94
|
},
|
|
90
95
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
has: function (key) {
|
|
96
|
+
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
97
|
+
*/ has (key) {
|
|
94
98
|
return client.has(keys[key]);
|
|
95
99
|
},
|
|
96
100
|
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
remove: function (key) {
|
|
101
|
+
* Remove a storage value (it uses `localStorage.remove()`).
|
|
102
|
+
*/ remove (key) {
|
|
100
103
|
client.remove(keys[key]);
|
|
101
104
|
},
|
|
102
105
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
clear: function () {
|
|
106
|
+
* Clear all storage values (it uses `localStorage.remove()`).
|
|
107
|
+
*/ clear () {
|
|
106
108
|
if (process.env["NODE_ENV"] !== "production") {
|
|
107
|
-
if (!
|
|
108
|
-
console.log(
|
|
109
|
+
if (!_isBrowser.default) {
|
|
110
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
|
-
if (
|
|
112
|
-
for
|
|
113
|
+
if (_isBrowser.default) {
|
|
114
|
+
for(const key in keys){
|
|
113
115
|
client.remove(keys[key]);
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
},
|
|
117
119
|
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (!isBrowser_1.default) {
|
|
120
|
+
* Watch a storage value changes, this needs to be executed only in browser
|
|
121
|
+
* context (it uses `window.addEventListener("storage")`).
|
|
122
|
+
*
|
|
123
|
+
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
124
|
+
*/ watch: (keyToWatch, onRemoved, onAdded)=>{
|
|
125
|
+
if (!_isBrowser.default) {
|
|
125
126
|
if (process.env["NODE_ENV"] !== "production") {
|
|
126
|
-
console.log(
|
|
127
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
|
|
127
128
|
}
|
|
128
|
-
return
|
|
129
|
+
return _noop.default;
|
|
129
130
|
}
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
const handler = (event)=>{
|
|
132
|
+
const { key, oldValue, newValue } = event;
|
|
132
133
|
if (key === keys[keyToWatch]) {
|
|
133
134
|
if (oldValue && !newValue) {
|
|
134
|
-
onRemoved
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
onAdded === null || onAdded === void 0 ? void 0 : onAdded();
|
|
135
|
+
onRemoved?.();
|
|
136
|
+
} else if (!oldValue && newValue) {
|
|
137
|
+
onAdded?.();
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
|
-
|
|
141
|
+
const listener = (0, _on.default)(window, "storage", handler);
|
|
142
142
|
return listener;
|
|
143
|
-
}
|
|
143
|
+
}
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
|
-
|
|
147
|
-
exports.default = exports.createStorage;
|
|
146
|
+
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,123 @@ 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
|
+
*/ export const createStorage = (config, useSessionStorage)=>{
|
|
12
|
+
const client = useSessionStorage ? storage.s : storage.l;
|
|
13
|
+
const keys = Object.keys(config).reduce((map, key)=>({
|
|
14
|
+
...map,
|
|
15
|
+
[key]: encode(key)
|
|
16
|
+
}), {});
|
|
19
17
|
return {
|
|
20
18
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
get: function (key, defaultValue) {
|
|
19
|
+
* Get all storage value (it uses `localStorage.get()`).
|
|
20
|
+
*
|
|
21
|
+
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
22
|
+
* On ssr or if the given `key` argument is not found `defaultValue` is
|
|
23
|
+
* returned, otherwise `null`.
|
|
24
|
+
*/ get (key, defaultValue) {
|
|
28
25
|
return client.get(keys[key], decode, defaultValue);
|
|
29
26
|
},
|
|
30
27
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
getAll: function (defaultValues) {
|
|
28
|
+
* Get all storage values (it uses `localStorage.get()`).
|
|
29
|
+
*
|
|
30
|
+
* `undefined` and `null` values are not returned.
|
|
31
|
+
*/ getAll (defaultValues) {
|
|
36
32
|
if (!isBrowser) {
|
|
37
33
|
if (process.env["NODE_ENV"] !== "production") {
|
|
38
|
-
console.log(
|
|
34
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.`);
|
|
39
35
|
}
|
|
40
36
|
return {};
|
|
41
37
|
}
|
|
42
|
-
|
|
43
|
-
for
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
const all = {};
|
|
39
|
+
for(const key in keys){
|
|
40
|
+
const value = this.get(key);
|
|
41
|
+
const defaultValue = defaultValues?.[key];
|
|
46
42
|
if (!isNullOrUndefined(value)) {
|
|
47
43
|
all[key] = value;
|
|
48
|
-
}
|
|
49
|
-
else if (defaultValue) {
|
|
44
|
+
} else if (defaultValue) {
|
|
50
45
|
all[key] = defaultValue;
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
48
|
return all;
|
|
54
49
|
},
|
|
55
50
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
set: function (key, value) {
|
|
51
|
+
* Set a storage value (it uses `localStorage.set()`).
|
|
52
|
+
*
|
|
53
|
+
* Non-string values are stringified with `JSON.stringify()`
|
|
54
|
+
*/ set (key, value) {
|
|
61
55
|
client.set(keys[key], value, encode);
|
|
62
56
|
},
|
|
63
57
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
setMany: function (newValues) {
|
|
58
|
+
* Set all given storage values (it uses `localStorage.set()`).
|
|
59
|
+
*
|
|
60
|
+
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
61
|
+
* and `null` values are removed from the storage
|
|
62
|
+
*/ setMany (newValues) {
|
|
70
63
|
if (process.env["NODE_ENV"] !== "production") {
|
|
71
64
|
if (!isBrowser) {
|
|
72
|
-
console.log(
|
|
65
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.`);
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
68
|
if (isBrowser) {
|
|
76
|
-
for
|
|
77
|
-
|
|
69
|
+
for(const key in newValues){
|
|
70
|
+
const value = newValues[key];
|
|
78
71
|
if (!isNullOrUndefined(value)) {
|
|
79
72
|
this.set(key, value);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
73
|
+
} else {
|
|
82
74
|
this.remove(key);
|
|
83
75
|
}
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
78
|
},
|
|
87
79
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
has: function (key) {
|
|
80
|
+
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
81
|
+
*/ has (key) {
|
|
91
82
|
return client.has(keys[key]);
|
|
92
83
|
},
|
|
93
84
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
remove: function (key) {
|
|
85
|
+
* Remove a storage value (it uses `localStorage.remove()`).
|
|
86
|
+
*/ remove (key) {
|
|
97
87
|
client.remove(keys[key]);
|
|
98
88
|
},
|
|
99
89
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
clear: function () {
|
|
90
|
+
* Clear all storage values (it uses `localStorage.remove()`).
|
|
91
|
+
*/ clear () {
|
|
103
92
|
if (process.env["NODE_ENV"] !== "production") {
|
|
104
93
|
if (!isBrowser) {
|
|
105
|
-
console.log(
|
|
94
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
|
|
106
95
|
}
|
|
107
96
|
}
|
|
108
97
|
if (isBrowser) {
|
|
109
|
-
for
|
|
98
|
+
for(const key in keys){
|
|
110
99
|
client.remove(keys[key]);
|
|
111
100
|
}
|
|
112
101
|
}
|
|
113
102
|
},
|
|
114
103
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
watch: function (keyToWatch, onRemoved, onAdded) {
|
|
104
|
+
* Watch a storage value changes, this needs to be executed only in browser
|
|
105
|
+
* context (it uses `window.addEventListener("storage")`).
|
|
106
|
+
*
|
|
107
|
+
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
108
|
+
*/ watch: (keyToWatch, onRemoved, onAdded)=>{
|
|
121
109
|
if (!isBrowser) {
|
|
122
110
|
if (process.env["NODE_ENV"] !== "production") {
|
|
123
|
-
console.log(
|
|
111
|
+
console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
|
|
124
112
|
}
|
|
125
113
|
return noop;
|
|
126
114
|
}
|
|
127
|
-
|
|
128
|
-
|
|
115
|
+
const handler = (event)=>{
|
|
116
|
+
const { key, oldValue, newValue } = event;
|
|
129
117
|
if (key === keys[keyToWatch]) {
|
|
130
118
|
if (oldValue && !newValue) {
|
|
131
|
-
onRemoved
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
onAdded === null || onAdded === void 0 ? void 0 : onAdded();
|
|
119
|
+
onRemoved?.();
|
|
120
|
+
} else if (!oldValue && newValue) {
|
|
121
|
+
onAdded?.();
|
|
135
122
|
}
|
|
136
123
|
}
|
|
137
124
|
};
|
|
138
|
-
|
|
125
|
+
const listener = on(window, "storage", handler);
|
|
139
126
|
return listener;
|
|
140
|
-
}
|
|
127
|
+
}
|
|
141
128
|
};
|
|
142
129
|
};
|
|
143
130
|
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;
|