@koine/browser 2.0.0-beta.80 → 2.0.0-beta.83
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.cjs.js +39 -89
- package/createStorage.d.ts +2 -2
- package/createStorage.esm.js +39 -89
- package/getZonedDate.cjs.js +18 -20
- package/getZonedDate.esm.js +18 -20
- package/gtag.cjs.js +13 -6
- package/gtag.esm.js +13 -6
- package/gtagPageview.cjs.js +3 -5
- package/gtagPageview.esm.js +3 -5
- package/isIE.cjs.js +5 -10
- package/isIE.esm.js +5 -10
- package/isMobile.cjs.js +7 -4
- package/isMobile.esm.js +7 -4
- package/listenUrlSearch.cjs.js +22 -36
- package/listenUrlSearch.esm.js +22 -36
- package/listenUrlSearchParams.cjs.js +5 -8
- package/listenUrlSearchParams.esm.js +5 -8
- package/navigateToHash.cjs.js +6 -4
- package/navigateToHash.esm.js +6 -4
- package/navigateToHashParams.cjs.js +6 -11
- package/navigateToHashParams.esm.js +6 -11
- package/navigateToMergedHashParams.cjs.js +5 -1
- package/navigateToMergedHashParams.esm.js +5 -1
- package/navigateToMergedParams.cjs.js +6 -1
- package/navigateToMergedParams.esm.js +6 -1
- package/navigateToParams.cjs.js +7 -7
- package/navigateToParams.esm.js +7 -7
- package/navigateToUrl.cjs.js +5 -5
- package/navigateToUrl.esm.js +5 -5
- package/navigateWithoutUrlParam.cjs.js +6 -10
- package/navigateWithoutUrlParam.esm.js +6 -10
- package/package.json +3 -3
- package/redirectTo.cjs.js +6 -6
- package/redirectTo.esm.js +6 -6
- package/storage.cjs.js +5 -4
- package/storage.esm.js +5 -4
- package/storageClient.cjs.js +12 -89
- package/storageClient.d.ts +1 -1
- package/storageClient.esm.js +12 -89
package/createStorage.cjs.js
CHANGED
|
@@ -7,95 +7,45 @@ var dom = require('@koine/dom');
|
|
|
7
7
|
var storage = require('./storage.cjs.js');
|
|
8
8
|
require('./storageClient.cjs.js');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!utils.isNullOrUndefined(value)) {
|
|
50
|
-
this.set(key, value);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
this.remove(key);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
has(key) {
|
|
59
|
-
return client.has(keys[key]);
|
|
60
|
-
},
|
|
61
|
-
remove(key) {
|
|
62
|
-
client.remove(keys[key]);
|
|
63
|
-
},
|
|
64
|
-
clear() {
|
|
65
|
-
if (process.env["NODE_ENV"] === "development") {
|
|
66
|
-
if (!utils.isBrowser) {
|
|
67
|
-
console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (utils.isBrowser) {
|
|
71
|
-
for (const key in keys) {
|
|
72
|
-
client.remove(keys[key]);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
watch: (keyToWatch, onRemoved, onAdded) => {
|
|
77
|
-
if (!utils.isBrowser) {
|
|
78
|
-
if (process.env["NODE_ENV"] === "development") {
|
|
79
|
-
console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
|
|
80
|
-
}
|
|
81
|
-
return utils.noop;
|
|
82
|
-
}
|
|
83
|
-
const handler = (event) => {
|
|
84
|
-
const { key, oldValue, newValue } = event;
|
|
85
|
-
if (key === keys[keyToWatch]) {
|
|
86
|
-
if (oldValue && !newValue) {
|
|
87
|
-
onRemoved?.();
|
|
88
|
-
}
|
|
89
|
-
else if (!oldValue && newValue) {
|
|
90
|
-
onAdded?.();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const listener = dom.on(window, "storage", handler);
|
|
95
|
-
return listener;
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
};
|
|
10
|
+
/**
|
|
11
|
+
* @category storage
|
|
12
|
+
*//**
|
|
13
|
+
* Utility to create a storage instance to interact with `localStorage` using
|
|
14
|
+
* encrypted (encoded) key/values.
|
|
15
|
+
*
|
|
16
|
+
* @category storage
|
|
17
|
+
*/let createStorage=(a,n)=>{let c=n?storage.storage.s:storage.storage.l,m=Object.keys(a).reduce((e,o)=>({...e,[o]:utils.encode(o)}),{});return {/**
|
|
18
|
+
* Get all storage value (it uses `localStorage.get()`).
|
|
19
|
+
*
|
|
20
|
+
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
21
|
+
* On ssr or if the given `key` argument is not found `defaultValue` is
|
|
22
|
+
* returned, otherwise `null`.
|
|
23
|
+
*/get:(t,o)=>c.get(m[t],utils.decode,o),/**
|
|
24
|
+
* Get all storage values (it uses `localStorage.get()`).
|
|
25
|
+
*
|
|
26
|
+
* `undefined` and `null` values are not returned.
|
|
27
|
+
*/getAll(e){if(!utils.isBrowser)return "development"===process.env.NODE_ENV&&console.log("[@koine/utils:createStorage] attempt to use 'getAll' outside of browser."),{};let t={};for(let o in m){let s=this.get(o),l=e?.[o];utils.isNullOrUndefined(s)?l&&// NOTE: without the assertion typedoc does not compile
|
|
28
|
+
(t[o]=l):t[o]=s;}return t},/**
|
|
29
|
+
* Set a storage value (it uses `localStorage.set()`).
|
|
30
|
+
*
|
|
31
|
+
* Non-string values are stringified with `JSON.stringify()`
|
|
32
|
+
*/set(e,o){c.set(m[e],o,utils.encode);},/**
|
|
33
|
+
* Set all given storage values (it uses `localStorage.set()`).
|
|
34
|
+
*
|
|
35
|
+
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
36
|
+
* and `null` values are removed from the storage
|
|
37
|
+
*/setMany(e){if("development"!==process.env.NODE_ENV||utils.isBrowser||console.log("[@koine/utils:createStorage] attempt to use 'setMany' outside of browser."),utils.isBrowser)for(let t in e){let o=e[t];utils.isNullOrUndefined(o)?this.remove(t):this.set(t,o);}},/**
|
|
38
|
+
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
39
|
+
*/has:e=>c.has(m[e]),/**
|
|
40
|
+
* Remove a storage value (it uses `localStorage.remove()`).
|
|
41
|
+
*/remove(e){c.remove(m[e]);},/**
|
|
42
|
+
* Clear all storage values (it uses `localStorage.remove()`).
|
|
43
|
+
*/clear(){if("development"!==process.env.NODE_ENV||utils.isBrowser||console.log("[@koine/utils:createStorage] attempt to use 'clear' outside of browser."),utils.isBrowser)for(let e in m)c.remove(m[e]);},/**
|
|
44
|
+
* Watch a storage value changes, this needs to be executed only in browser
|
|
45
|
+
* context (it uses `window.addEventListener("storage")`).
|
|
46
|
+
*
|
|
47
|
+
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
48
|
+
*/watch:(e,t,r)=>utils.isBrowser?dom.on(window,"storage",o=>{let{key:s,oldValue:l,newValue:i}=o;s===m[e]&&(l&&!i?t?.():!l&&i&&r?.());}):("development"===process.env.NODE_ENV&&console.log("[@koine/utils:createStorage] attempt to use 'watch' outside of browser."),utils.noop)}};
|
|
99
49
|
|
|
100
50
|
exports.createStorage = createStorage;
|
|
101
51
|
exports["default"] = createStorage;
|
package/createStorage.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type CreateStorageConfig = Record<string, any>;
|
|
2
2
|
export declare let createStorage: <T extends CreateStorageConfig>(config: Partial<T>, useSessionStorage?: boolean) => {
|
|
3
|
-
get<TKey extends Extract<keyof T, string>>(key: TKey, defaultValue?: T[TKey]
|
|
4
|
-
getAll(defaultValues?: Partial<T>
|
|
3
|
+
get<TKey extends Extract<keyof T, string>>(key: TKey, defaultValue?: null | T[TKey]): T[TKey] | null;
|
|
4
|
+
getAll(defaultValues?: Partial<T>): T;
|
|
5
5
|
set<TKey_1 extends Extract<keyof T, string>>(key: TKey_1, value?: T[TKey_1] | undefined): void;
|
|
6
6
|
setMany(newValues: Partial<T>): void;
|
|
7
7
|
has<TKey_2 extends Extract<keyof T, string>>(key: TKey_2): any;
|
package/createStorage.esm.js
CHANGED
|
@@ -3,94 +3,44 @@ import { on } from '@koine/dom';
|
|
|
3
3
|
import { storage } from './storage.esm.js';
|
|
4
4
|
import './storageClient.esm.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!isNullOrUndefined(value)) {
|
|
46
|
-
this.set(key, value);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
this.remove(key);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
has(key) {
|
|
55
|
-
return client.has(keys[key]);
|
|
56
|
-
},
|
|
57
|
-
remove(key) {
|
|
58
|
-
client.remove(keys[key]);
|
|
59
|
-
},
|
|
60
|
-
clear() {
|
|
61
|
-
if (process.env["NODE_ENV"] === "development") {
|
|
62
|
-
if (!isBrowser) {
|
|
63
|
-
console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (isBrowser) {
|
|
67
|
-
for (const key in keys) {
|
|
68
|
-
client.remove(keys[key]);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
watch: (keyToWatch, onRemoved, onAdded) => {
|
|
73
|
-
if (!isBrowser) {
|
|
74
|
-
if (process.env["NODE_ENV"] === "development") {
|
|
75
|
-
console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
|
|
76
|
-
}
|
|
77
|
-
return noop;
|
|
78
|
-
}
|
|
79
|
-
const handler = (event) => {
|
|
80
|
-
const { key, oldValue, newValue } = event;
|
|
81
|
-
if (key === keys[keyToWatch]) {
|
|
82
|
-
if (oldValue && !newValue) {
|
|
83
|
-
onRemoved?.();
|
|
84
|
-
}
|
|
85
|
-
else if (!oldValue && newValue) {
|
|
86
|
-
onAdded?.();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
const listener = on(window, "storage", handler);
|
|
91
|
-
return listener;
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
};
|
|
6
|
+
/**
|
|
7
|
+
* @category storage
|
|
8
|
+
*//**
|
|
9
|
+
* Utility to create a storage instance to interact with `localStorage` using
|
|
10
|
+
* encrypted (encoded) key/values.
|
|
11
|
+
*
|
|
12
|
+
* @category storage
|
|
13
|
+
*/let createStorage=(a,n)=>{let c=n?storage.s:storage.l,m=Object.keys(a).reduce((e,o)=>({...e,[o]:encode(o)}),{});return {/**
|
|
14
|
+
* Get all storage value (it uses `localStorage.get()`).
|
|
15
|
+
*
|
|
16
|
+
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
17
|
+
* On ssr or if the given `key` argument is not found `defaultValue` is
|
|
18
|
+
* returned, otherwise `null`.
|
|
19
|
+
*/get:(t,o)=>c.get(m[t],decode,o),/**
|
|
20
|
+
* Get all storage values (it uses `localStorage.get()`).
|
|
21
|
+
*
|
|
22
|
+
* `undefined` and `null` values are not returned.
|
|
23
|
+
*/getAll(e){if(!isBrowser)return "development"===process.env.NODE_ENV&&console.log("[@koine/utils:createStorage] attempt to use 'getAll' outside of browser."),{};let t={};for(let o in m){let s=this.get(o),l=e?.[o];isNullOrUndefined(s)?l&&// NOTE: without the assertion typedoc does not compile
|
|
24
|
+
(t[o]=l):t[o]=s;}return t},/**
|
|
25
|
+
* Set a storage value (it uses `localStorage.set()`).
|
|
26
|
+
*
|
|
27
|
+
* Non-string values are stringified with `JSON.stringify()`
|
|
28
|
+
*/set(e,o){c.set(m[e],o,encode);},/**
|
|
29
|
+
* Set all given storage values (it uses `localStorage.set()`).
|
|
30
|
+
*
|
|
31
|
+
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
32
|
+
* and `null` values are removed from the storage
|
|
33
|
+
*/setMany(e){if("development"!==process.env.NODE_ENV||isBrowser||console.log("[@koine/utils:createStorage] attempt to use 'setMany' outside of browser."),isBrowser)for(let t in e){let o=e[t];isNullOrUndefined(o)?this.remove(t):this.set(t,o);}},/**
|
|
34
|
+
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
35
|
+
*/has:e=>c.has(m[e]),/**
|
|
36
|
+
* Remove a storage value (it uses `localStorage.remove()`).
|
|
37
|
+
*/remove(e){c.remove(m[e]);},/**
|
|
38
|
+
* Clear all storage values (it uses `localStorage.remove()`).
|
|
39
|
+
*/clear(){if("development"!==process.env.NODE_ENV||isBrowser||console.log("[@koine/utils:createStorage] attempt to use 'clear' outside of browser."),isBrowser)for(let e in m)c.remove(m[e]);},/**
|
|
40
|
+
* Watch a storage value changes, this needs to be executed only in browser
|
|
41
|
+
* context (it uses `window.addEventListener("storage")`).
|
|
42
|
+
*
|
|
43
|
+
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
44
|
+
*/watch:(e,t,r)=>isBrowser?on(window,"storage",o=>{let{key:s,oldValue:l,newValue:i}=o;s===m[e]&&(l&&!i?t?.():!l&&i&&r?.());}):("development"===process.env.NODE_ENV&&console.log("[@koine/utils:createStorage] attempt to use 'watch' outside of browser."),noop)}};
|
|
95
45
|
|
|
96
46
|
export { createStorage, createStorage as default };
|
package/getZonedDate.cjs.js
CHANGED
|
@@ -4,26 +4,24 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
: new Date(dateString);
|
|
26
|
-
};
|
|
7
|
+
// import utcToZonedTime from "date-fns-tz/utcToZonedTime";
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
let t=(e,t)=>e;/**
|
|
10
|
+
* It returns a `Date` object from a date `string` adjusted on the user timeZone,
|
|
11
|
+
* if a timeZone is not provided we try getting it from the `Intl` browwser native
|
|
12
|
+
* API. It gracefully falls back returning a _non-timezone-based_ `Date`.
|
|
13
|
+
*
|
|
14
|
+
* @category date
|
|
15
|
+
*
|
|
16
|
+
* @resources
|
|
17
|
+
* - to get the timeZone client side see [this article](https://attacomsian.com/blog/javascript-current-timezone)
|
|
18
|
+
* - 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)
|
|
19
|
+
*
|
|
20
|
+
* @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.
|
|
21
|
+
* @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.
|
|
22
|
+
*/let getZonedDate=(o="",n)=>{if(o.endsWith("Z")||(o+="Z"),!n&&utils.isBrowser)try{n=Intl.DateTimeFormat().resolvedOptions().timeZone;}catch(e){"development"===process.env.NODE_ENV&&console.warn("[@koine/browser:getZonedDate] failed reading timeZone, error",e);}// no need to do anything here, it just means `Intl` failed, probably
|
|
23
|
+
// because the browser does not support it
|
|
24
|
+
return n?t(new Date(o)):new Date(o)};
|
|
27
25
|
|
|
28
26
|
exports["default"] = getZonedDate;
|
|
29
27
|
exports.getZonedDate = getZonedDate;
|
package/getZonedDate.esm.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { isBrowser } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
: new Date(dateString);
|
|
22
|
-
};
|
|
3
|
+
// import utcToZonedTime from "date-fns-tz/utcToZonedTime";
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
let t=(e,t)=>e;/**
|
|
6
|
+
* It returns a `Date` object from a date `string` adjusted on the user timeZone,
|
|
7
|
+
* if a timeZone is not provided we try getting it from the `Intl` browwser native
|
|
8
|
+
* API. It gracefully falls back returning a _non-timezone-based_ `Date`.
|
|
9
|
+
*
|
|
10
|
+
* @category date
|
|
11
|
+
*
|
|
12
|
+
* @resources
|
|
13
|
+
* - to get the timeZone client side see [this article](https://attacomsian.com/blog/javascript-current-timezone)
|
|
14
|
+
* - 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)
|
|
15
|
+
*
|
|
16
|
+
* @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.
|
|
17
|
+
* @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.
|
|
18
|
+
*/let getZonedDate=(o="",n)=>{if(o.endsWith("Z")||(o+="Z"),!n&&isBrowser)try{n=Intl.DateTimeFormat().resolvedOptions().timeZone;}catch(e){"development"===process.env.NODE_ENV&&console.warn("[@koine/browser:getZonedDate] failed reading timeZone, error",e);}// no need to do anything here, it just means `Intl` failed, probably
|
|
19
|
+
// because the browser does not support it
|
|
20
|
+
return n?t(new Date(o)):new Date(o)};
|
|
23
21
|
|
|
24
22
|
export { getZonedDate as default, getZonedDate };
|
package/gtag.cjs.js
CHANGED
|
@@ -4,12 +4,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @category analytics-google
|
|
9
|
+
*
|
|
10
|
+
* If you like you could add to your globals `.d.ts` types:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* declare interface Window {
|
|
14
|
+
* gtag: <T extends unknown[]>(...args: T) => void;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/let gtag=(...o)=>{// @ts-expect-error nevermind
|
|
18
|
+
utils.isUndefined(window)||utils.isUndefined(window.gtag)?utils.noop():// @ts-expect-error nevermind
|
|
19
|
+
window.gtag(...o);};// export type GtmEventArgs = [
|
|
13
20
|
|
|
14
21
|
exports["default"] = gtag;
|
|
15
22
|
exports.gtag = gtag;
|
package/gtag.esm.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { isUndefined, noop } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @category analytics-google
|
|
5
|
+
*
|
|
6
|
+
* If you like you could add to your globals `.d.ts` types:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* declare interface Window {
|
|
10
|
+
* gtag: <T extends unknown[]>(...args: T) => void;
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*/let gtag=(...o)=>{// @ts-expect-error nevermind
|
|
14
|
+
isUndefined(window)||isUndefined(window.gtag)?noop():// @ts-expect-error nevermind
|
|
15
|
+
window.gtag(...o);};// export type GtmEventArgs = [
|
|
9
16
|
|
|
10
17
|
export { gtag as default, gtag };
|
package/gtagPageview.cjs.js
CHANGED
|
@@ -5,11 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var gtag = require('./gtag.cjs.js');
|
|
6
6
|
require('@koine/utils');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
page_location: args[2] || location.href,
|
|
12
|
-
});
|
|
8
|
+
/**
|
|
9
|
+
* @category analytics-google
|
|
10
|
+
*/let gtagPageview=(...t)=>gtag.gtag("event","page_view",{page_path:t[0]||location.pathname,page_title:t[1]||document.title,page_location:t[2]||location.href});// send_to: '<GA_MEASUREMENT_ID>'
|
|
13
11
|
|
|
14
12
|
exports["default"] = gtagPageview;
|
|
15
13
|
exports.gtagPageview = gtagPageview;
|
package/gtagPageview.esm.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { gtag } from './gtag.esm.js';
|
|
2
2
|
import '@koine/utils';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
page_location: args[2] || location.href,
|
|
8
|
-
});
|
|
4
|
+
/**
|
|
5
|
+
* @category analytics-google
|
|
6
|
+
*/let gtagPageview=(...t)=>gtag("event","page_view",{page_path:t[0]||location.pathname,page_title:t[1]||document.title,page_location:t[2]||location.href});// send_to: '<GA_MEASUREMENT_ID>'
|
|
9
7
|
|
|
10
8
|
export { gtagPageview as default, gtagPageview };
|
package/isIE.cjs.js
CHANGED
|
@@ -4,16 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
};
|
|
7
|
+
/**
|
|
8
|
+
* @category detect
|
|
9
|
+
* @category is
|
|
10
|
+
* @see https://stackoverflow.com/a/21712356/12285349
|
|
11
|
+
*/let isIE=(t=!0)=>{if(utils.isServer)return t;let i=window.navigator.userAgent;return !!(i.indexOf("MSIE ")>0||i.indexOf("Trident/")>0)};
|
|
17
12
|
|
|
18
13
|
exports["default"] = isIE;
|
|
19
14
|
exports.isIE = isIE;
|
package/isIE.esm.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { isServer } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
return false;
|
|
12
|
-
};
|
|
3
|
+
/**
|
|
4
|
+
* @category detect
|
|
5
|
+
* @category is
|
|
6
|
+
* @see https://stackoverflow.com/a/21712356/12285349
|
|
7
|
+
*/let isIE=(t=!0)=>{if(isServer)return t;let i=window.navigator.userAgent;return !!(i.indexOf("MSIE ")>0||i.indexOf("Trident/")>0)};
|
|
13
8
|
|
|
14
9
|
export { isIE as default, isIE };
|
package/isMobile.cjs.js
CHANGED
|
@@ -4,10 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @category detect
|
|
9
|
+
* @category is
|
|
10
|
+
* @see https://stackoverflow.com/a/3540295
|
|
11
|
+
*/let isMobile=(e=!0)=>utils.isServer?e:// /(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)
|
|
12
|
+
// || /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)
|
|
13
|
+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(window.navigator.userAgent);
|
|
11
14
|
|
|
12
15
|
exports["default"] = isMobile;
|
|
13
16
|
exports.isMobile = isMobile;
|
package/isMobile.esm.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { isServer } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @category detect
|
|
5
|
+
* @category is
|
|
6
|
+
* @see https://stackoverflow.com/a/3540295
|
|
7
|
+
*/let isMobile=(e=!0)=>isServer?e:// /(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)
|
|
8
|
+
// || /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)
|
|
9
|
+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(window.navigator.userAgent);
|
|
7
10
|
|
|
8
11
|
export { isMobile as default, isMobile };
|
package/listenUrlSearch.cjs.js
CHANGED
|
@@ -5,42 +5,28 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
var dom = require('@koine/dom');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
let listenUrlSearch = (handler) => {
|
|
31
|
-
if (!history.__) {
|
|
32
|
-
history.pushState = extendHistoryMethod(history.pushState, runHandlers);
|
|
33
|
-
history.replaceState = extendHistoryMethod(history.replaceState, runHandlers);
|
|
34
|
-
dom.on(window, "popstate", runHandlers);
|
|
35
|
-
history.__ = { h: new Set() };
|
|
36
|
-
}
|
|
37
|
-
if (!history.__.h.has(handler)) {
|
|
38
|
-
history.__.h.add(handler);
|
|
39
|
-
}
|
|
40
|
-
return () => {
|
|
41
|
-
history.__.h.delete(handler);
|
|
42
|
-
};
|
|
43
|
-
};
|
|
8
|
+
/**
|
|
9
|
+
* Flag that tells if `history` methods have been replaced
|
|
10
|
+
*//**
|
|
11
|
+
* @param prevLocationSearch The previous URL search query e.g. `?myparam=mvalue`
|
|
12
|
+
* @param newLocationSearch The previous URL search query e.g. `?myparam=mvalue`
|
|
13
|
+
*/let r=(t,e,r)=>function(...o){if(r)return e(),t.apply(this,o);let i=t.apply(this,o);return e(),i},o=utils.isBrowser?location.search:"",i=()=>{let t=location.search;// console.log(`listenUrlSearch: "${prevSearch}" vs "${newSearch}`);
|
|
14
|
+
if(t!==o)for(let e of history.__.h.values())e(o,t);o=t;};/**
|
|
15
|
+
* Here we extend and mutate the native `window.history` object so that multiple
|
|
16
|
+
* scripts can add url change handlers without interfering each other and using
|
|
17
|
+
* the same single listener.
|
|
18
|
+
*
|
|
19
|
+
* @borrows [SO answer](https://stackoverflow.com/a/42727249/1938970)
|
|
20
|
+
*
|
|
21
|
+
* @category location
|
|
22
|
+
* @category navigation
|
|
23
|
+
* @category events
|
|
24
|
+
*
|
|
25
|
+
* @returns A de-register function to remove the handler
|
|
26
|
+
*/let listenUrlSearch=t=>(history.__||(// replace browser's history global methods
|
|
27
|
+
history.pushState=r(history.pushState,i),history.replaceState=r(history.replaceState,i),// listen native history events
|
|
28
|
+
dom.on(window,"popstate",i),// extend history object
|
|
29
|
+
history.__={h:new Set}),history.__.h.has(t)||history.__.h.add(t),()=>{history.__.h.delete(t);});
|
|
44
30
|
|
|
45
31
|
exports["default"] = listenUrlSearch;
|
|
46
32
|
exports.listenUrlSearch = listenUrlSearch;
|