@koine/browser 2.0.0-beta.2 → 2.0.0-beta.4

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 CHANGED
@@ -1,147 +1,146 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createStorage = void 0;
4
- var tslib_1 = require("tslib");
5
- var decode_1 = tslib_1.__importDefault(require("@koine/utils/decode"));
6
- var encode_1 = tslib_1.__importDefault(require("@koine/utils/encode"));
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;
18
- var keys = Object.keys(config).reduce(function (map, key) {
19
- var _a;
20
- return (tslib_1.__assign(tslib_1.__assign({}, map), (_a = {}, _a[key] = (0, encode_1.default)(key), _a)));
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
- * 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
- get: function (key, defaultValue) {
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
- * Get all storage values (it uses `localStorage.get()`).
35
- *
36
- * `undefined` and `null` values are not returned.
37
- */
38
- getAll: function (defaultValues) {
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("[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.");
50
+ console.log(`[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.`);
42
51
  }
43
52
  return {};
44
53
  }
45
- var all = {};
46
- for (var key in keys) {
47
- var value = this.get(key);
48
- var defaultValue = defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues[key];
49
- if (!(0, isNullOrUndefined_1.default)(value)) {
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
- * Set a storage value (it uses `localStorage.set()`).
60
- *
61
- * Non-string values are stringified with `JSON.stringify()`
62
- */
63
- set: function (key, value) {
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
- * 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
- 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 (!isBrowser_1.default) {
75
- console.log("[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.");
80
+ if (!_isBrowser.default) {
81
+ console.log(`[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.`);
76
82
  }
77
83
  }
78
- if (isBrowser_1.default) {
79
- for (var key in newValues) {
80
- var value = newValues[key];
81
- if (!(0, isNullOrUndefined_1.default)(value)) {
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
- * Check if a storage value is _truthy_ (it uses `localStorage.get()`).
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
- * Remove a storage value (it uses `localStorage.remove()`).
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
- * Clear all storage values (it uses `localStorage.remove()`).
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 (!isBrowser_1.default) {
108
- console.log("[@koine/utils:createStorage] attempt to use 'clear' outside of browser.");
109
+ if (!_isBrowser.default) {
110
+ console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
109
111
  }
110
112
  }
111
- if (isBrowser_1.default) {
112
- for (var key in keys) {
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
- * 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
- watch: function (keyToWatch, onRemoved, onAdded) {
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("[@koine/utils:createStorage] attempt to use 'watch' outside of browser.");
127
+ console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
127
128
  }
128
- return noop_1.default;
129
+ return _noop.default;
129
130
  }
130
- var handler = function (event) {
131
- var key = event.key, oldValue = event.oldValue, newValue = event.newValue;
131
+ const handler = (event)=>{
132
+ const { key, oldValue, newValue } = event;
132
133
  if (key === keys[keyToWatch]) {
133
134
  if (oldValue && !newValue) {
134
- onRemoved === null || onRemoved === void 0 ? void 0 : onRemoved();
135
- }
136
- else if (!oldValue && newValue) {
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
- var listener = (0, on_1.default)(window, "storage", handler);
141
+ const listener = (0, _on.default)(window, "storage", handler);
142
142
  return listener;
143
- },
143
+ }
144
144
  };
145
145
  };
146
- exports.createStorage = createStorage;
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
- export var createStorage = function (config, useSessionStorage) {
14
- var client = useSessionStorage ? storage.s : storage.l;
15
- var keys = Object.keys(config).reduce(function (map, key) {
16
- var _a;
17
- return (__assign(__assign({}, map), (_a = {}, _a[key] = encode(key), _a)));
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
- * 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
- */
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
- * Get all storage values (it uses `localStorage.get()`).
32
- *
33
- * `undefined` and `null` values are not returned.
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("[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.");
34
+ console.log(`[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.`);
39
35
  }
40
36
  return {};
41
37
  }
42
- var all = {};
43
- for (var key in keys) {
44
- var value = this.get(key);
45
- var defaultValue = defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues[key];
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
- * Set a storage value (it uses `localStorage.set()`).
57
- *
58
- * Non-string values are stringified with `JSON.stringify()`
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
- * Set all given storage values (it uses `localStorage.set()`).
65
- *
66
- * Non-string values are stringified with `JSON.stringify()`, `undefined`
67
- * and `null` values are removed from the storage
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("[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.");
65
+ console.log(`[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.`);
73
66
  }
74
67
  }
75
68
  if (isBrowser) {
76
- for (var key in newValues) {
77
- var value = newValues[key];
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
- * Check if a storage value is _truthy_ (it uses `localStorage.get()`).
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
- * Remove a storage value (it uses `localStorage.remove()`).
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
- * Clear all storage values (it uses `localStorage.remove()`).
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("[@koine/utils:createStorage] attempt to use 'clear' outside of browser.");
94
+ console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
106
95
  }
107
96
  }
108
97
  if (isBrowser) {
109
- for (var key in keys) {
98
+ for(const key in keys){
110
99
  client.remove(keys[key]);
111
100
  }
112
101
  }
113
102
  },
114
103
  /**
115
- * Watch a storage value changes, this needs to be executed only in browser
116
- * context (it uses `window.addEventListener("storage")`).
117
- *
118
- * Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
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("[@koine/utils:createStorage] attempt to use 'watch' outside of browser.");
111
+ console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
124
112
  }
125
113
  return noop;
126
114
  }
127
- var handler = function (event) {
128
- var key = event.key, oldValue = event.oldValue, newValue = event.newValue;
115
+ const handler = (event)=>{
116
+ const { key, oldValue, newValue } = event;
129
117
  if (key === keys[keyToWatch]) {
130
118
  if (oldValue && !newValue) {
131
- onRemoved === null || onRemoved === void 0 ? void 0 : onRemoved();
132
- }
133
- else if (!oldValue && newValue) {
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
- var listener = on(window, "storage", handler);
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", { value: true });
3
- exports.getZonedDate = void 0;
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) {
22
- if (dateString === void 0) { dateString = ""; }
23
- if (!dateString.endsWith("Z"))
24
- dateString += "Z";
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
- // no need to do anything here, it just means `Intl` failed, probably
34
- // because the browser does not support it
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
- exports.getZonedDate = getZonedDate;
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
- export function getZonedDate(dateString, timeZone) {
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
- // no need to do anything here, it just means `Intl` failed, probably
30
- // because the browser does not support it
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", { value: true });
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 () {
10
- var args = [];
11
- for (var _i = 0; _i < arguments.length; _i++) {
12
- args[_i] = arguments[_i];
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
- if (!(0, isUndefined_1.default)(window) && !(0, isUndefined_1.default)(window.gtag)) {
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
- exports.gtagPageview = gtagPageview;
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;