@koine/browser 2.0.0-beta.1 → 2.0.0-beta.11

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.
@@ -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.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
- 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
+ *
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
- * 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) {
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
- * Get all storage values (it uses `localStorage.get()`).
32
- *
33
- * `undefined` and `null` values are not returned.
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("[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.");
36
+ console.log(`[@koine/utils:createStorage] attempt to use 'getAll' outside of browser.`);
39
37
  }
40
38
  return {};
41
39
  }
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];
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
- else if (defaultValue) {
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
- * Set a storage value (it uses `localStorage.set()`).
57
- *
58
- * Non-string values are stringified with `JSON.stringify()`
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
- * 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) {
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("[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.");
68
+ console.log(`[@koine/utils:createStorage] attempt to use 'setMany' outside of browser.`);
73
69
  }
74
70
  }
75
71
  if (isBrowser) {
76
- for (var key in newValues) {
77
- var value = newValues[key];
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
- * Check if a storage value is _truthy_ (it uses `localStorage.get()`).
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
- * Remove a storage value (it uses `localStorage.remove()`).
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
- * Clear all storage values (it uses `localStorage.remove()`).
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("[@koine/utils:createStorage] attempt to use 'clear' outside of browser.");
97
+ console.log(`[@koine/utils:createStorage] attempt to use 'clear' outside of browser.`);
106
98
  }
107
99
  }
108
100
  if (isBrowser) {
109
- for (var key in keys) {
101
+ for(const key in keys){
110
102
  client.remove(keys[key]);
111
103
  }
112
104
  }
113
105
  },
114
106
  /**
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) {
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("[@koine/utils:createStorage] attempt to use 'watch' outside of browser.");
114
+ console.log(`[@koine/utils:createStorage] attempt to use 'watch' outside of browser.`);
124
115
  }
125
116
  return noop;
126
117
  }
127
- var handler = function (event) {
128
- var key = event.key, oldValue = event.oldValue, newValue = event.newValue;
118
+ const handler = (event)=>{
119
+ const { key, oldValue, newValue } = event;
129
120
  if (key === keys[keyToWatch]) {
130
121
  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();
122
+ onRemoved?.();
123
+ } else if (!oldValue && newValue) {
124
+ onAdded?.();
135
125
  }
136
126
  }
137
127
  };
138
- var listener = on(window, "storage", handler);
128
+ const listener = on(window, "storage", handler);
139
129
  return listener;
140
- },
130
+ }
141
131
  };
142
132
  };
143
133
  export default createStorage;
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.mjs CHANGED
@@ -1,30 +1,23 @@
1
1
  import isUndefined from "@koine/utils/isUndefined";
2
2
  /**
3
3
  * @category analytics-google
4
- */
5
- export var gtagPageview = function () {
6
- var args = [];
7
- for (var _i = 0; _i < arguments.length; _i++) {
8
- args[_i] = arguments[_i];
9
- }
4
+ */ export const gtagPageview = (...args)=>{
10
5
  if (!isUndefined(window) && !isUndefined(window.gtag)) {
11
6
  window.gtag("event", "page_view", {
12
7
  page_path: args[0] || location.pathname,
13
8
  page_title: args[1] || document.title,
14
- page_location: args[2] || location.href,
15
- // send_to: '<GA_MEASUREMENT_ID>'
9
+ page_location: args[2] || location.href
16
10
  });
17
11
  }
18
12
  };
19
- export default gtagPageview;
20
- // export type GtmEventArgs = [
21
- // eventCategory?: string,
22
- // eventAction?: string,
23
- // eventLabel?: string,
24
- // eventValue?: string
25
- // ];
26
- // export const event = (...args: GtmEventArgs) => {
27
- // if (!isUndefined(window) && !isUndefined(window.gtag)) {
28
- // window.gtag("send", "event", ...args);
29
- // }
30
- // };
13
+ export default gtagPageview; // export type GtmEventArgs = [
14
+ // eventCategory?: string,
15
+ // eventAction?: string,
16
+ // eventLabel?: string,
17
+ // eventValue?: string
18
+ // ];
19
+ // export const event = (...args: GtmEventArgs) => {
20
+ // if (!isUndefined(window) && !isUndefined(window.gtag)) {
21
+ // window.gtag("send", "event", ...args);
22
+ // }
23
+ // };
package/isIE.mjs CHANGED
@@ -3,13 +3,11 @@ import isServer from "@koine/utils/isServer";
3
3
  * @category detect
4
4
  * @category is
5
5
  * @see https://stackoverflow.com/a/21712356/12285349
6
- */
7
- export function isIE(ssrValue) {
8
- if (ssrValue === void 0) { ssrValue = true; }
6
+ */ export function isIE(ssrValue = true) {
9
7
  if (isServer) {
10
8
  return ssrValue;
11
9
  }
12
- var ua = window.navigator.userAgent;
10
+ const ua = window.navigator.userAgent;
13
11
  if (ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0) {
14
12
  return true;
15
13
  }
package/isMobile.mjs CHANGED
@@ -3,14 +3,12 @@ import isServer from "@koine/utils/isServer";
3
3
  * @category detect
4
4
  * @category is
5
5
  * @see https://stackoverflow.com/a/3540295
6
- */
7
- export function isMobile(ssrValue) {
8
- if (ssrValue === void 0) { ssrValue = true; }
6
+ */ export function isMobile(ssrValue = true) {
9
7
  if (isServer) {
10
8
  return ssrValue;
11
9
  }
12
10
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(window.navigator.userAgent);
13
- // return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
14
- // || /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)
11
+ // return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
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)
15
13
  }
16
14
  export default isMobile;
@@ -4,10 +4,8 @@ import navigateToUrl from "./navigateToUrl";
4
4
  * The non-silent standard way would simply be `location.hash = "#new-hash"`
5
5
  *
6
6
  * @category location
7
- */
8
- export function navigateToHash(hash) {
9
- if (hash === void 0) { hash = ""; }
10
- var pathname = location.pathname, search = location.search;
7
+ */ export function navigateToHash(hash = "") {
8
+ const { pathname, search } = location;
11
9
  navigateToUrl(pathname + (search ? "?" + search : "") + (hash ? "#" + hash : ""), true);
12
10
  }
13
11
  export default navigateToHash;
@@ -5,15 +5,12 @@ import getUrlHashPathname from "@koine/utils/getUrlHashPathname";
5
5
  * if a second argument `hash` is not provded
6
6
  *
7
7
  * @category location
8
- */
9
- export function navigateToHashParams(params, hash) {
10
- if (params === void 0) { params = {}; }
11
- if (hash === void 0) { hash = ""; }
12
- var useLocation = !hash;
8
+ */ export function navigateToHashParams(params = {}, hash = "") {
9
+ const useLocation = !hash;
13
10
  hash = hash || location.hash;
14
- var hashQueryLess = getUrlHashPathname(hash);
15
- var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
16
- var newHash = "#/" + hashQueryLess + queryString;
11
+ const hashQueryLess = getUrlHashPathname(hash);
12
+ const queryString = typeof params === "string" ? params : buildUrlQueryString(params);
13
+ const newHash = "#/" + hashQueryLess + queryString;
17
14
  if (useLocation) {
18
15
  location.hash = newHash;
19
16
  }
@@ -1,14 +1,11 @@
1
- import mergeUrlQueryParams from "@koine/utils/mergeUrlQueryParams";
2
1
  import getUrlHashParams from "@koine/utils/getUrlHashParams";
2
+ import mergeUrlQueryParams from "@koine/utils/mergeUrlQueryParams";
3
3
  import { navigateToHashParams } from "./navigateToHashParams";
4
4
  /**
5
5
  * It updates the "query params" within the `location.hash`, it uses `location`
6
6
  *
7
7
  * @category location
8
- */
9
- export function navigateToMergedHashParams(params, hash) {
10
- if (params === void 0) { params = {}; }
11
- if (hash === void 0) { hash = ""; }
8
+ */ export function navigateToMergedHashParams(params = {}, hash = "") {
12
9
  return navigateToHashParams(mergeUrlQueryParams(getUrlHashParams(hash), params), hash);
13
10
  }
14
11
  export default navigateToMergedHashParams;
@@ -1,14 +1,12 @@
1
- import mergeUrlQueryParams from "@koine/utils/mergeUrlQueryParams";
2
1
  import getUrlQueryParams from "@koine/utils/getUrlQueryParams";
2
+ import mergeUrlQueryParams from "@koine/utils/mergeUrlQueryParams";
3
3
  import { navigateToParams } from "./navigateToParams";
4
4
  /**
5
5
  * Merge current URL query parameters with the given ones, it uses `history`.
6
6
  *
7
7
  * @category location
8
8
  * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
9
- */
10
- export function navigateToMergedParams(params, replace) {
11
- if (params === void 0) { params = {}; }
9
+ */ export function navigateToMergedParams(params = {}, replace) {
12
10
  return navigateToParams(mergeUrlQueryParams(getUrlQueryParams(), params), replace);
13
11
  }
14
12
  export default navigateToMergedParams;
@@ -1,5 +1,5 @@
1
- import isBrowser from "@koine/utils/isBrowser";
2
1
  import buildUrlQueryString from "@koine/utils/buildUrlQueryString";
2
+ import isBrowser from "@koine/utils/isBrowser";
3
3
  import navigateToUrl from "./navigateToUrl";
4
4
  /**
5
5
  * Change current URL query parameters, it uses `history`.
@@ -7,10 +7,8 @@ import navigateToUrl from "./navigateToUrl";
7
7
  * @category location
8
8
  * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
9
9
  * @returns The query string with initial `?`
10
- */
11
- export function navigateToParams(params, replace) {
12
- if (params === void 0) { params = {}; }
13
- var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
10
+ */ export function navigateToParams(params = {}, replace) {
11
+ const queryString = typeof params === "string" ? params : buildUrlQueryString(params);
14
12
  if (isBrowser) {
15
13
  navigateToUrl(location.pathname + queryString, replace);
16
14
  }
package/navigateToUrl.mjs CHANGED
@@ -2,9 +2,7 @@
2
2
  * It updates the browser's location URL with global `history` object
3
3
  *
4
4
  * @category location
5
- */
6
- export function navigateToUrl(url, replace) {
7
- if (url === void 0) { url = ""; }
5
+ */ export function navigateToUrl(url = "", replace) {
8
6
  if (url) {
9
7
  history[replace ? "replaceState" : "pushState"](history.state, "", url);
10
8
  }
@@ -5,11 +5,10 @@ import navigateToParams from "./navigateToParams";
5
5
  *
6
6
  * @category location
7
7
  * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
8
- */
9
- export function navigateWithoutUrlParam(paramName, replace) {
10
- var params = {};
11
- var currentParams = getUrlQueryParams();
12
- for (var key in currentParams) {
8
+ */ export function navigateWithoutUrlParam(paramName, replace) {
9
+ const params = {};
10
+ const currentParams = getUrlQueryParams();
11
+ for(const key in currentParams){
13
12
  if (key !== paramName) {
14
13
  params[key] = currentParams[key];
15
14
  }
package/package.json CHANGED
@@ -2,13 +2,15 @@
2
2
  "name": "@koine/browser",
3
3
  "sideEffects": false,
4
4
  "dependencies": {
5
- "date-fns-tz": "^2.0.0"
6
- },
7
- "peerDependencies": {
8
- "tslib": "2.5.3"
5
+ "@koine/dom": "2.0.0-beta.11",
6
+ "@koine/utils": "2.0.0-beta.11"
9
7
  },
8
+ "module": "./index.mjs",
10
9
  "main": "./index.js",
11
10
  "types": "./index.d.ts",
12
- "version": "2.0.0-beta.1",
13
- "module": "./index.mjs"
14
- }
11
+ "peerDependencies": {
12
+ "date-fns-tz": "^2.0.0",
13
+ "type-fest": "^4.1.0"
14
+ },
15
+ "version": "2.0.0-beta.11"
16
+ }
package/redirectTo.mjs CHANGED
@@ -1,14 +1,13 @@
1
- import isBrowser from "@koine/utils/isBrowser";
2
1
  import buildUrlQueryString from "@koine/utils/buildUrlQueryString";
2
+ import isBrowser from "@koine/utils/isBrowser";
3
3
  /**
4
4
  * Redirect to url with params {optionally}, removes eventual trailing question
5
5
  * marks from the given URL, it uses `location`
6
6
  *
7
7
  * @category location
8
- */
9
- export function redirectTo(url, params) {
8
+ */ export function redirectTo(url, params) {
10
9
  if (isBrowser) {
11
- var queryString = buildUrlQueryString(params);
10
+ const queryString = buildUrlQueryString(params);
12
11
  location.href = url.replace(/\?+$/g, "") + queryString;
13
12
  }
14
13
  }
package/storage.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Storage, for `localStorage` and `sessionStorage`
3
+ *
4
+ * @category storage
3
5
  */
4
6
  export declare const storage: {
5
7
  l: {
package/storage.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import storageClient from "./storageClient";
2
2
  /**
3
3
  * Storage, for `localStorage` and `sessionStorage`
4
- */
5
- export var storage = {
4
+ *
5
+ * @category storage
6
+ */ export const storage = {
6
7
  l: storageClient(),
7
- s: storageClient(true),
8
+ s: storageClient(true)
8
9
  };
9
10
  export default storage;
@@ -1,6 +1,11 @@
1
+ /**
2
+ * @category storage
3
+ */
1
4
  export type StorageClientConfig = Record<string, any>;
2
5
  /**
3
6
  * Super minifiable `local/session Storage` client creator with SSR safety
7
+ *
8
+ * @category storage
4
9
  */
5
10
  export declare const storageClient: <TConfig extends StorageClientConfig = StorageClientConfig>(useSessionStorage?: boolean) => {
6
11
  get: <TKey extends Extract<keyof TConfig, string>, TValue = TConfig[TKey]>(key: TKey, transform?: ((value: string) => TValue) | undefined, defaultValue?: TValue | null | undefined) => NonNullable<TValue> | null;