@koine/browser 2.0.0-beta.82 → 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 -1
- package/createStorage.esm.js +39 -1
- package/getZonedDate.cjs.js +18 -1
- package/getZonedDate.esm.js +18 -1
- package/gtag.cjs.js +13 -1
- package/gtag.esm.js +13 -1
- package/gtagPageview.cjs.js +3 -1
- package/gtagPageview.esm.js +3 -1
- package/isIE.cjs.js +5 -1
- package/isIE.esm.js +5 -1
- package/isMobile.cjs.js +7 -1
- package/isMobile.esm.js +7 -1
- package/listenUrlSearch.cjs.js +22 -1
- package/listenUrlSearch.esm.js +22 -1
- package/listenUrlSearchParams.cjs.js +5 -1
- package/listenUrlSearchParams.esm.js +5 -1
- package/navigateToHash.cjs.js +6 -1
- package/navigateToHash.esm.js +6 -1
- package/navigateToHashParams.cjs.js +6 -1
- package/navigateToHashParams.esm.js +6 -1
- 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 -1
- package/navigateToParams.esm.js +7 -1
- package/navigateToUrl.cjs.js +5 -1
- package/navigateToUrl.esm.js +5 -1
- package/navigateWithoutUrlParam.cjs.js +6 -1
- package/navigateWithoutUrlParam.esm.js +6 -1
- package/package.json +3 -3
- package/redirectTo.cjs.js +6 -1
- package/redirectTo.esm.js +6 -1
- package/storage.cjs.js +5 -1
- package/storage.esm.js +5 -1
- package/storageClient.cjs.js +12 -1
- package/storageClient.esm.js +12 -1
package/createStorage.cjs.js
CHANGED
|
@@ -7,7 +7,45 @@ var dom = require('@koine/dom');
|
|
|
7
7
|
var storage = require('./storage.cjs.js');
|
|
8
8
|
require('./storageClient.cjs.js');
|
|
9
9
|
|
|
10
|
-
|
|
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)}};
|
|
11
49
|
|
|
12
50
|
exports.createStorage = createStorage;
|
|
13
51
|
exports["default"] = createStorage;
|
package/createStorage.esm.js
CHANGED
|
@@ -3,6 +3,44 @@ import { on } from '@koine/dom';
|
|
|
3
3
|
import { storage } from './storage.esm.js';
|
|
4
4
|
import './storageClient.esm.js';
|
|
5
5
|
|
|
6
|
-
|
|
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)}};
|
|
7
45
|
|
|
8
46
|
export { createStorage, createStorage as default };
|
package/getZonedDate.cjs.js
CHANGED
|
@@ -4,7 +4,24 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
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)};
|
|
8
25
|
|
|
9
26
|
exports["default"] = getZonedDate;
|
|
10
27
|
exports.getZonedDate = getZonedDate;
|
package/getZonedDate.esm.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { isBrowser } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
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)};
|
|
4
21
|
|
|
5
22
|
export { getZonedDate as default, getZonedDate };
|
package/gtag.cjs.js
CHANGED
|
@@ -4,7 +4,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
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 = [
|
|
8
20
|
|
|
9
21
|
exports["default"] = gtag;
|
|
10
22
|
exports.gtag = gtag;
|
package/gtag.esm.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { isUndefined, noop } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
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 = [
|
|
4
16
|
|
|
5
17
|
export { gtag as default, gtag };
|
package/gtagPageview.cjs.js
CHANGED
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var gtag = require('./gtag.cjs.js');
|
|
6
6
|
require('@koine/utils');
|
|
7
7
|
|
|
8
|
-
|
|
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>'
|
|
9
11
|
|
|
10
12
|
exports["default"] = gtagPageview;
|
|
11
13
|
exports.gtagPageview = gtagPageview;
|
package/gtagPageview.esm.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { gtag } from './gtag.esm.js';
|
|
2
2
|
import '@koine/utils';
|
|
3
3
|
|
|
4
|
-
|
|
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>'
|
|
5
7
|
|
|
6
8
|
export { gtagPageview as default, gtagPageview };
|
package/isIE.cjs.js
CHANGED
|
@@ -4,7 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
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)};
|
|
8
12
|
|
|
9
13
|
exports["default"] = isIE;
|
|
10
14
|
exports.isIE = isIE;
|
package/isIE.esm.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { isServer } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
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)};
|
|
4
8
|
|
|
5
9
|
export { isIE as default, isIE };
|
package/isMobile.cjs.js
CHANGED
|
@@ -4,7 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
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);
|
|
8
14
|
|
|
9
15
|
exports["default"] = isMobile;
|
|
10
16
|
exports.isMobile = isMobile;
|
package/isMobile.esm.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { isServer } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
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);
|
|
4
10
|
|
|
5
11
|
export { isMobile as default, isMobile };
|
package/listenUrlSearch.cjs.js
CHANGED
|
@@ -5,7 +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
|
-
|
|
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);});
|
|
9
30
|
|
|
10
31
|
exports["default"] = listenUrlSearch;
|
|
11
32
|
exports.listenUrlSearch = listenUrlSearch;
|
package/listenUrlSearch.esm.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { isBrowser } from '@koine/utils';
|
|
2
2
|
import { on } from '@koine/dom';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Flag that tells if `history` methods have been replaced
|
|
6
|
+
*//**
|
|
7
|
+
* @param prevLocationSearch The previous URL search query e.g. `?myparam=mvalue`
|
|
8
|
+
* @param newLocationSearch The previous URL search query e.g. `?myparam=mvalue`
|
|
9
|
+
*/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=isBrowser?location.search:"",i=()=>{let t=location.search;// console.log(`listenUrlSearch: "${prevSearch}" vs "${newSearch}`);
|
|
10
|
+
if(t!==o)for(let e of history.__.h.values())e(o,t);o=t;};/**
|
|
11
|
+
* Here we extend and mutate the native `window.history` object so that multiple
|
|
12
|
+
* scripts can add url change handlers without interfering each other and using
|
|
13
|
+
* the same single listener.
|
|
14
|
+
*
|
|
15
|
+
* @borrows [SO answer](https://stackoverflow.com/a/42727249/1938970)
|
|
16
|
+
*
|
|
17
|
+
* @category location
|
|
18
|
+
* @category navigation
|
|
19
|
+
* @category events
|
|
20
|
+
*
|
|
21
|
+
* @returns A de-register function to remove the handler
|
|
22
|
+
*/let listenUrlSearch=t=>(history.__||(// replace browser's history global methods
|
|
23
|
+
history.pushState=r(history.pushState,i),history.replaceState=r(history.replaceState,i),// listen native history events
|
|
24
|
+
on(window,"popstate",i),// extend history object
|
|
25
|
+
history.__={h:new Set}),history.__.h.has(t)||history.__.h.add(t),()=>{history.__.h.delete(t);});
|
|
5
26
|
|
|
6
27
|
export { listenUrlSearch as default, listenUrlSearch };
|
|
@@ -6,7 +6,11 @@ var listenUrlSearch = require('./listenUrlSearch.cjs.js');
|
|
|
6
6
|
require('@koine/utils');
|
|
7
7
|
require('@koine/dom');
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @category events
|
|
11
|
+
* @category navigation
|
|
12
|
+
* @category events
|
|
13
|
+
*/let listenUrlSearchParams=(r,a)=>listenUrlSearch.listenUrlSearch((e,t)=>{let l=new URLSearchParams(e),s=new URLSearchParams(t).get(r);l.get(r)!==s&&a(s);});
|
|
10
14
|
|
|
11
15
|
exports["default"] = listenUrlSearchParams;
|
|
12
16
|
exports.listenUrlSearchParams = listenUrlSearchParams;
|
|
@@ -2,6 +2,10 @@ import { listenUrlSearch } from './listenUrlSearch.esm.js';
|
|
|
2
2
|
import '@koine/utils';
|
|
3
3
|
import '@koine/dom';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @category events
|
|
7
|
+
* @category navigation
|
|
8
|
+
* @category events
|
|
9
|
+
*/let listenUrlSearchParams=(r,a)=>listenUrlSearch((e,t)=>{let l=new URLSearchParams(e),s=new URLSearchParams(t).get(r);l.get(r)!==s&&a(s);});
|
|
6
10
|
|
|
7
11
|
export { listenUrlSearchParams as default, listenUrlSearchParams };
|
package/navigateToHash.cjs.js
CHANGED
|
@@ -4,7 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var navigateToUrl = require('./navigateToUrl.cjs.js');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* It updates the browser's location hash by replacing the history state.
|
|
9
|
+
* The non-silent standard way would simply be `location.hash = "#new-hash"`
|
|
10
|
+
*
|
|
11
|
+
* @category location
|
|
12
|
+
*/let navigateToHash=(t="")=>{let{pathname:o,search:e}=location;navigateToUrl.navigateToUrl(o+(e?"?"+e:"")+(t?"#"+t:""),!0);};
|
|
8
13
|
|
|
9
14
|
exports["default"] = navigateToHash;
|
|
10
15
|
exports.navigateToHash = navigateToHash;
|
package/navigateToHash.esm.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { navigateToUrl } from './navigateToUrl.esm.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* It updates the browser's location hash by replacing the history state.
|
|
5
|
+
* The non-silent standard way would simply be `location.hash = "#new-hash"`
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
*/let navigateToHash=(t="")=>{let{pathname:o,search:e}=location;navigateToUrl(o+(e?"?"+e:"")+(t?"#"+t:""),!0);};
|
|
4
9
|
|
|
5
10
|
export { navigateToHash as default, navigateToHash };
|
|
@@ -4,7 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* It updates the `location.hash` with the given query params, it uses `location.hash`
|
|
9
|
+
* if a second argument `hash` is not provded
|
|
10
|
+
*
|
|
11
|
+
* @category location
|
|
12
|
+
*/let navigateToHashParams=(o={},e="")=>{let r=!e,i="#/"+utils.getUrlHashPathname(e=e||location.hash)+("string"==typeof o?o:utils.buildUrlQueryString(o));return r&&(location.hash=i),i};
|
|
8
13
|
|
|
9
14
|
exports["default"] = navigateToHashParams;
|
|
10
15
|
exports.navigateToHashParams = navigateToHashParams;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { getUrlHashPathname, buildUrlQueryString } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* It updates the `location.hash` with the given query params, it uses `location.hash`
|
|
5
|
+
* if a second argument `hash` is not provded
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
*/let navigateToHashParams=(o={},e="")=>{let r=!e,i="#/"+getUrlHashPathname(e=e||location.hash)+("string"==typeof o?o:buildUrlQueryString(o));return r&&(location.hash=i),i};
|
|
4
9
|
|
|
5
10
|
export { navigateToHashParams as default, navigateToHashParams };
|
|
@@ -5,7 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
var navigateToHashParams = require('./navigateToHashParams.cjs.js');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* It updates the "query params" within the `location.hash`, it uses `location`
|
|
10
|
+
*
|
|
11
|
+
* @category location
|
|
12
|
+
*/let navigateToMergedHashParams=(o={},t="")=>navigateToHashParams.navigateToHashParams(utils.mergeUrlQueryParams(utils.getUrlHashParams(t),o),t);
|
|
9
13
|
|
|
10
14
|
exports["default"] = navigateToMergedHashParams;
|
|
11
15
|
exports.navigateToMergedHashParams = navigateToMergedHashParams;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { mergeUrlQueryParams, getUrlHashParams } from '@koine/utils';
|
|
2
2
|
import { navigateToHashParams } from './navigateToHashParams.esm.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* It updates the "query params" within the `location.hash`, it uses `location`
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
*/let navigateToMergedHashParams=(o={},t="")=>navigateToHashParams(mergeUrlQueryParams(getUrlHashParams(t),o),t);
|
|
5
9
|
|
|
6
10
|
export { navigateToMergedHashParams as default, navigateToMergedHashParams };
|
|
@@ -6,7 +6,12 @@ var utils = require('@koine/utils');
|
|
|
6
6
|
var navigateToParams = require('./navigateToParams.cjs.js');
|
|
7
7
|
require('./navigateToUrl.cjs.js');
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Merge current URL query parameters with the given ones, it uses `history`.
|
|
11
|
+
*
|
|
12
|
+
* @category location
|
|
13
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
14
|
+
*/let navigateToMergedParams=(o={},t)=>navigateToParams.navigateToParams(utils.mergeUrlQueryParams(utils.getUrlQueryParams(),o),t);
|
|
10
15
|
|
|
11
16
|
exports["default"] = navigateToMergedParams;
|
|
12
17
|
exports.navigateToMergedParams = navigateToMergedParams;
|
|
@@ -2,6 +2,11 @@ import { mergeUrlQueryParams, getUrlQueryParams } from '@koine/utils';
|
|
|
2
2
|
import { navigateToParams } from './navigateToParams.esm.js';
|
|
3
3
|
import './navigateToUrl.esm.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Merge current URL query parameters with the given ones, it uses `history`.
|
|
7
|
+
*
|
|
8
|
+
* @category location
|
|
9
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
10
|
+
*/let navigateToMergedParams=(o={},t)=>navigateToParams(mergeUrlQueryParams(getUrlQueryParams(),o),t);
|
|
6
11
|
|
|
7
12
|
export { navigateToMergedParams as default, navigateToMergedParams };
|
package/navigateToParams.cjs.js
CHANGED
|
@@ -5,7 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
var navigateToUrl = require('./navigateToUrl.cjs.js');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Change current URL query parameters, it uses `history`.
|
|
10
|
+
*
|
|
11
|
+
* @category location
|
|
12
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
13
|
+
* @returns The query string with initial `?`
|
|
14
|
+
*/let navigateToParams=(e={},r)=>{let i="string"==typeof e?e:utils.buildUrlQueryString(e);return utils.isBrowser&&navigateToUrl.navigateToUrl(location.pathname+i,r),i};
|
|
9
15
|
|
|
10
16
|
exports["default"] = navigateToParams;
|
|
11
17
|
exports.navigateToParams = navigateToParams;
|
package/navigateToParams.esm.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { buildUrlQueryString, isBrowser } from '@koine/utils';
|
|
2
2
|
import { navigateToUrl } from './navigateToUrl.esm.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Change current URL query parameters, it uses `history`.
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
9
|
+
* @returns The query string with initial `?`
|
|
10
|
+
*/let navigateToParams=(e={},r)=>{let i="string"==typeof e?e:buildUrlQueryString(e);return isBrowser&&navigateToUrl(location.pathname+i,r),i};
|
|
5
11
|
|
|
6
12
|
export { navigateToParams as default, navigateToParams };
|
package/navigateToUrl.cjs.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* It updates the browser's location URL with global `history` object
|
|
7
|
+
*
|
|
8
|
+
* @category location
|
|
9
|
+
*/let navigateToUrl=(t="",e)=>{t&&history[e?"replaceState":"pushState"](history.state,"",t);};
|
|
6
10
|
|
|
7
11
|
exports["default"] = navigateToUrl;
|
|
8
12
|
exports.navigateToUrl = navigateToUrl;
|
package/navigateToUrl.esm.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* It updates the browser's location URL with global `history` object
|
|
3
|
+
*
|
|
4
|
+
* @category location
|
|
5
|
+
*/let navigateToUrl=(t="",e)=>{t&&history[e?"replaceState":"pushState"](history.state,"",t);};
|
|
2
6
|
|
|
3
7
|
export { navigateToUrl as default, navigateToUrl };
|
|
@@ -6,7 +6,12 @@ var utils = require('@koine/utils');
|
|
|
6
6
|
var navigateToParams = require('./navigateToParams.cjs.js');
|
|
7
7
|
require('./navigateToUrl.cjs.js');
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Remove URL query parameter, it uses `history`
|
|
11
|
+
*
|
|
12
|
+
* @category location
|
|
13
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
14
|
+
*/let navigateWithoutUrlParam=(a,e)=>{let o={},i=utils.getUrlQueryParams();for(let t in i)t!==a&&(o[t]=i[t]);return navigateToParams.navigateToParams(o,e)};
|
|
10
15
|
|
|
11
16
|
exports["default"] = navigateWithoutUrlParam;
|
|
12
17
|
exports.navigateWithoutUrlParam = navigateWithoutUrlParam;
|
|
@@ -2,6 +2,11 @@ import { getUrlQueryParams } from '@koine/utils';
|
|
|
2
2
|
import { navigateToParams } from './navigateToParams.esm.js';
|
|
3
3
|
import './navigateToUrl.esm.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Remove URL query parameter, it uses `history`
|
|
7
|
+
*
|
|
8
|
+
* @category location
|
|
9
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
10
|
+
*/let navigateWithoutUrlParam=(a,e)=>{let o={},i=getUrlQueryParams();for(let t in i)t!==a&&(o[t]=i[t]);return navigateToParams(o,e)};
|
|
6
11
|
|
|
7
12
|
export { navigateWithoutUrlParam as default, navigateWithoutUrlParam };
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@koine/browser",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@koine/dom": "2.0.0-beta.
|
|
6
|
-
"@koine/utils": "2.0.0-beta.
|
|
5
|
+
"@koine/dom": "2.0.0-beta.83",
|
|
6
|
+
"@koine/utils": "2.0.0-beta.83"
|
|
7
7
|
},
|
|
8
8
|
"peerDependenciesMeta": {
|
|
9
9
|
"date-fns-tz": {
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
},
|
|
111
111
|
"module": "./index.esm.js",
|
|
112
112
|
"main": "./index.cjs.js",
|
|
113
|
-
"version": "2.0.0-beta.
|
|
113
|
+
"version": "2.0.0-beta.83"
|
|
114
114
|
}
|
package/redirectTo.cjs.js
CHANGED
|
@@ -4,7 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
9
|
+
* marks from the given URL, it uses `location`
|
|
10
|
+
*
|
|
11
|
+
* @category location
|
|
12
|
+
*/let redirectTo=(t,o)=>{if(utils.isBrowser){let r=utils.buildUrlQueryString(o);location.href=t.replace(/\?+$/g,"")+r;}};
|
|
8
13
|
|
|
9
14
|
exports["default"] = redirectTo;
|
|
10
15
|
exports.redirectTo = redirectTo;
|
package/redirectTo.esm.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { isBrowser, buildUrlQueryString } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
5
|
+
* marks from the given URL, it uses `location`
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
*/let redirectTo=(t,o)=>{if(isBrowser){let r=buildUrlQueryString(o);location.href=t.replace(/\?+$/g,"")+r;}};
|
|
4
9
|
|
|
5
10
|
export { redirectTo as default, redirectTo };
|
package/storage.cjs.js
CHANGED
|
@@ -5,7 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var storageClient = require('./storageClient.cjs.js');
|
|
6
6
|
require('@koine/utils');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Storage, for `localStorage` and `sessionStorage`
|
|
10
|
+
*
|
|
11
|
+
* @category storage
|
|
12
|
+
*/let storage={l:storageClient.storageClient(),s:storageClient.storageClient(!0)};
|
|
9
13
|
|
|
10
14
|
exports["default"] = storage;
|
|
11
15
|
exports.storage = storage;
|
package/storage.esm.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { storageClient } from './storageClient.esm.js';
|
|
2
2
|
import '@koine/utils';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Storage, for `localStorage` and `sessionStorage`
|
|
6
|
+
*
|
|
7
|
+
* @category storage
|
|
8
|
+
*/let storage={l:storageClient(),s:storageClient(!0)};
|
|
5
9
|
|
|
6
10
|
export { storage as default, storage };
|
package/storageClient.cjs.js
CHANGED
|
@@ -4,7 +4,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('@koine/utils');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @category storage
|
|
9
|
+
*/let t={g:"getItem",s:"setItem",r:"removeItem"};/**
|
|
10
|
+
* Super minifiable `local/session Storage` client creator with SSR safety
|
|
11
|
+
*
|
|
12
|
+
* @category storage
|
|
13
|
+
*/let storageClient=s=>{let r=(o,r,l)=>utils.isBrowser?window[s?"sessionStorage":"localStorage"][t[o]](r,l):()=>{"development"===process.env.NODE_ENV&&console.warn(`[@koine/utils:storageClient]: ${s?"sessionStorage":"localStorage"} does not exists outside of browser.`);};return {get:(o,t,s)=>{let l=s??null;if("development"!==process.env.NODE_ENV||utils.isBrowser||console.log(`[@koine/utils:storage] called 'get' outside of browser with default value '${JSON.stringify(s)}'.`),utils.isBrowser){let e=r("g",o);if(e){e=t?t(e):e;try{let o=JSON.parse(e);o&&(l=o);}catch(o){l=e;}}}// if (process.env["NODE_ENV"] === "development") {
|
|
14
|
+
// console.warn(
|
|
15
|
+
// `[@koine/utils:storage]: 'get' failed to parse stored value as JSON. Plain '${stored}' value is returned.`
|
|
16
|
+
// );
|
|
17
|
+
// }
|
|
18
|
+
return l},set:(t,s,l=e=>e)=>{if("development"!==process.env.NODE_ENV||utils.isBrowser||console.log("[@koine/utils:storage] called 'set' outside of browser does not work."),utils.isBrowser)try{let e=l(utils.isString(s)?s:JSON.stringify(s));r("s",t,e);}catch(e){"development"===process.env.NODE_ENV&&console.warn("[@koine/utils:createStorage]: 'set' error.",e);}},remove:o=>{if("development"!==process.env.NODE_ENV||utils.isBrowser||console.log("[@koine/utils:storage] called 'remove' outside of browser does not work."),utils.isBrowser)try{r("r",o);}catch(e){"development"===process.env.NODE_ENV&&console.warn("[@koine/utils:createStorage]: 'remove' error.",e);}},has:(o,t)=>{let s=t??!1;return "development"!==process.env.NODE_ENV||utils.isBrowser||console.log(`[@koine/utils:storage] called 'has' outside of browser with default value '${JSON.stringify(t)}'.`),utils.isBrowser&&(s=r("g",o)??!1),s}}};
|
|
8
19
|
|
|
9
20
|
exports["default"] = storageClient;
|
|
10
21
|
exports.storageClient = storageClient;
|
package/storageClient.esm.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { isBrowser, isString } from '@koine/utils';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @category storage
|
|
5
|
+
*/let t={g:"getItem",s:"setItem",r:"removeItem"};/**
|
|
6
|
+
* Super minifiable `local/session Storage` client creator with SSR safety
|
|
7
|
+
*
|
|
8
|
+
* @category storage
|
|
9
|
+
*/let storageClient=s=>{let r=(o,r,l)=>isBrowser?window[s?"sessionStorage":"localStorage"][t[o]](r,l):()=>{"development"===process.env.NODE_ENV&&console.warn(`[@koine/utils:storageClient]: ${s?"sessionStorage":"localStorage"} does not exists outside of browser.`);};return {get:(o,t,s)=>{let l=s??null;if("development"!==process.env.NODE_ENV||isBrowser||console.log(`[@koine/utils:storage] called 'get' outside of browser with default value '${JSON.stringify(s)}'.`),isBrowser){let e=r("g",o);if(e){e=t?t(e):e;try{let o=JSON.parse(e);o&&(l=o);}catch(o){l=e;}}}// if (process.env["NODE_ENV"] === "development") {
|
|
10
|
+
// console.warn(
|
|
11
|
+
// `[@koine/utils:storage]: 'get' failed to parse stored value as JSON. Plain '${stored}' value is returned.`
|
|
12
|
+
// );
|
|
13
|
+
// }
|
|
14
|
+
return l},set:(t,s,l=e=>e)=>{if("development"!==process.env.NODE_ENV||isBrowser||console.log("[@koine/utils:storage] called 'set' outside of browser does not work."),isBrowser)try{let e=l(isString(s)?s:JSON.stringify(s));r("s",t,e);}catch(e){"development"===process.env.NODE_ENV&&console.warn("[@koine/utils:createStorage]: 'set' error.",e);}},remove:o=>{if("development"!==process.env.NODE_ENV||isBrowser||console.log("[@koine/utils:storage] called 'remove' outside of browser does not work."),isBrowser)try{r("r",o);}catch(e){"development"===process.env.NODE_ENV&&console.warn("[@koine/utils:createStorage]: 'remove' error.",e);}},has:(o,t)=>{let s=t??!1;return "development"!==process.env.NODE_ENV||isBrowser||console.log(`[@koine/utils:storage] called 'has' outside of browser with default value '${JSON.stringify(t)}'.`),isBrowser&&(s=r("g",o)??!1),s}}};
|
|
4
15
|
|
|
5
16
|
export { storageClient as default, storageClient };
|