@koine/browser 2.0.0-beta.2 → 2.0.0-beta.21
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.d.ts +0 -42
- package/createStorage.js +24 -74
- package/getZonedDate.d.ts +0 -14
- package/getZonedDate.js +7 -28
- package/gtagPageview.d.ts +0 -3
- package/gtagPageview.js +4 -24
- package/index.d.ts +17 -15
- package/index.js +17 -33
- package/isIE.d.ts +0 -5
- package/isIE.js +4 -14
- package/isMobile.d.ts +0 -5
- package/isMobile.js +4 -16
- package/listenUrlSearch.d.ts +3 -0
- package/listenUrlSearch.js +55 -0
- package/listenUrlSearchParams.d.ts +2 -0
- package/listenUrlSearchParams.js +12 -0
- package/navigateToHash.d.ts +0 -6
- package/navigateToHash.js +4 -15
- package/navigateToHashParams.d.ts +1 -7
- package/navigateToHashParams.js +5 -17
- package/navigateToMergedHashParams.d.ts +1 -6
- package/navigateToMergedHashParams.js +5 -16
- package/navigateToMergedParams.d.ts +1 -7
- package/navigateToMergedParams.js +5 -17
- package/navigateToParams.d.ts +1 -8
- package/navigateToParams.js +7 -20
- package/navigateToUrl.d.ts +0 -5
- package/navigateToUrl.js +2 -11
- package/navigateWithoutUrlParam.d.ts +0 -6
- package/navigateWithoutUrlParam.js +6 -17
- package/package.json +62 -12
- package/redirectTo.d.ts +1 -7
- package/redirectTo.js +5 -17
- package/storage.d.ts +0 -3
- package/storage.js +5 -12
- package/storageClient.d.ts +0 -3
- package/storageClient.js +20 -34
- package/README.md +0 -1
- package/createStorage.mjs +0 -143
- package/getZonedDate.mjs +0 -37
- package/gtagPageview.mjs +0 -30
- package/index.mjs +0 -15
- package/isIE.mjs +0 -18
- package/isMobile.mjs +0 -16
- package/navigateToHash.mjs +0 -13
- package/navigateToHashParams.mjs +0 -22
- package/navigateToMergedHashParams.mjs +0 -14
- package/navigateToMergedParams.mjs +0 -14
- package/navigateToParams.mjs +0 -19
- package/navigateToUrl.mjs +0 -12
- package/navigateWithoutUrlParam.mjs +0 -19
- package/redirectTo.mjs +0 -15
- package/storage.mjs +0 -9
- package/storageClient.mjs +0 -103
package/getZonedDate.mjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import utcToZonedTime from "date-fns-tz/utcToZonedTime";
|
|
2
|
-
import isBrowser from "@koine/utils/isBrowser";
|
|
3
|
-
/**
|
|
4
|
-
* It returns a `Date` object from a date `string` adjusted on the user timeZone,
|
|
5
|
-
* if a timeZone is not provided we try getting it from the `Intl` browwser native
|
|
6
|
-
* API. It gracefully falls back returning a _non-timezone-based_ `Date`.
|
|
7
|
-
*
|
|
8
|
-
* @category date
|
|
9
|
-
*
|
|
10
|
-
* @resources
|
|
11
|
-
* - to get the timeZone client side see [this article](https://attacomsian.com/blog/javascript-current-timezone)
|
|
12
|
-
* - 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)
|
|
13
|
-
*
|
|
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
|
-
* @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";
|
|
21
|
-
if (!timeZone && isBrowser) {
|
|
22
|
-
try {
|
|
23
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
27
|
-
console.warn("[@koine/utils:getZonedDate] failed reading timeZone, error", e);
|
|
28
|
-
}
|
|
29
|
-
// no need to do anything here, it just means `Intl` failed, probably
|
|
30
|
-
// because the browser does not support it
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return timeZone
|
|
34
|
-
? utcToZonedTime(new Date(dateString), timeZone)
|
|
35
|
-
: new Date(dateString);
|
|
36
|
-
}
|
|
37
|
-
export default getZonedDate;
|
package/gtagPageview.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import isUndefined from "@koine/utils/isUndefined";
|
|
2
|
-
/**
|
|
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
|
-
}
|
|
10
|
-
if (!isUndefined(window) && !isUndefined(window.gtag)) {
|
|
11
|
-
window.gtag("event", "page_view", {
|
|
12
|
-
page_path: args[0] || location.pathname,
|
|
13
|
-
page_title: args[1] || document.title,
|
|
14
|
-
page_location: args[2] || location.href,
|
|
15
|
-
// send_to: '<GA_MEASUREMENT_ID>'
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
};
|
|
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
|
-
// };
|
package/index.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export { createStorage } from "./createStorage";
|
|
2
|
-
export { getZonedDate } from "./getZonedDate";
|
|
3
|
-
export { gtagPageview } from "./gtagPageview";
|
|
4
|
-
export { isIE } from "./isIE";
|
|
5
|
-
export { isMobile } from "./isMobile";
|
|
6
|
-
export { navigateToHash } from "./navigateToHash";
|
|
7
|
-
export { navigateToHashParams } from "./navigateToHashParams";
|
|
8
|
-
export { navigateToMergedHashParams } from "./navigateToMergedHashParams";
|
|
9
|
-
export { navigateToMergedParams } from "./navigateToMergedParams";
|
|
10
|
-
export { navigateToParams } from "./navigateToParams";
|
|
11
|
-
export { navigateToUrl } from "./navigateToUrl";
|
|
12
|
-
export { navigateWithoutUrlParam } from "./navigateWithoutUrlParam";
|
|
13
|
-
export { redirectTo } from "./redirectTo";
|
|
14
|
-
export { storage } from "./storage";
|
|
15
|
-
export { storageClient } from "./storageClient";
|
package/isIE.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import isServer from "@koine/utils/isServer";
|
|
2
|
-
/**
|
|
3
|
-
* @category detect
|
|
4
|
-
* @category is
|
|
5
|
-
* @see https://stackoverflow.com/a/21712356/12285349
|
|
6
|
-
*/
|
|
7
|
-
export function isIE(ssrValue) {
|
|
8
|
-
if (ssrValue === void 0) { ssrValue = true; }
|
|
9
|
-
if (isServer) {
|
|
10
|
-
return ssrValue;
|
|
11
|
-
}
|
|
12
|
-
var ua = window.navigator.userAgent;
|
|
13
|
-
if (ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
export default isIE;
|
package/isMobile.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import isServer from "@koine/utils/isServer";
|
|
2
|
-
/**
|
|
3
|
-
* @category detect
|
|
4
|
-
* @category is
|
|
5
|
-
* @see https://stackoverflow.com/a/3540295
|
|
6
|
-
*/
|
|
7
|
-
export function isMobile(ssrValue) {
|
|
8
|
-
if (ssrValue === void 0) { ssrValue = true; }
|
|
9
|
-
if (isServer) {
|
|
10
|
-
return ssrValue;
|
|
11
|
-
}
|
|
12
|
-
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)
|
|
15
|
-
}
|
|
16
|
-
export default isMobile;
|
package/navigateToHash.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import navigateToUrl from "./navigateToUrl";
|
|
2
|
-
/**
|
|
3
|
-
* It updates the browser's location hash by replacing the history state.
|
|
4
|
-
* The non-silent standard way would simply be `location.hash = "#new-hash"`
|
|
5
|
-
*
|
|
6
|
-
* @category location
|
|
7
|
-
*/
|
|
8
|
-
export function navigateToHash(hash) {
|
|
9
|
-
if (hash === void 0) { hash = ""; }
|
|
10
|
-
var pathname = location.pathname, search = location.search;
|
|
11
|
-
navigateToUrl(pathname + (search ? "?" + search : "") + (hash ? "#" + hash : ""), true);
|
|
12
|
-
}
|
|
13
|
-
export default navigateToHash;
|
package/navigateToHashParams.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import buildUrlQueryString from "@koine/utils/buildUrlQueryString";
|
|
2
|
-
import getUrlHashPathname from "@koine/utils/getUrlHashPathname";
|
|
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
|
-
*/
|
|
9
|
-
export function navigateToHashParams(params, hash) {
|
|
10
|
-
if (params === void 0) { params = {}; }
|
|
11
|
-
if (hash === void 0) { hash = ""; }
|
|
12
|
-
var useLocation = !hash;
|
|
13
|
-
hash = hash || location.hash;
|
|
14
|
-
var hashQueryLess = getUrlHashPathname(hash);
|
|
15
|
-
var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
|
|
16
|
-
var newHash = "#/" + hashQueryLess + queryString;
|
|
17
|
-
if (useLocation) {
|
|
18
|
-
location.hash = newHash;
|
|
19
|
-
}
|
|
20
|
-
return newHash;
|
|
21
|
-
}
|
|
22
|
-
export default navigateToHashParams;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import mergeUrlQueryParams from "@koine/utils/mergeUrlQueryParams";
|
|
2
|
-
import getUrlHashParams from "@koine/utils/getUrlHashParams";
|
|
3
|
-
import { navigateToHashParams } from "./navigateToHashParams";
|
|
4
|
-
/**
|
|
5
|
-
* It updates the "query params" within the `location.hash`, it uses `location`
|
|
6
|
-
*
|
|
7
|
-
* @category location
|
|
8
|
-
*/
|
|
9
|
-
export function navigateToMergedHashParams(params, hash) {
|
|
10
|
-
if (params === void 0) { params = {}; }
|
|
11
|
-
if (hash === void 0) { hash = ""; }
|
|
12
|
-
return navigateToHashParams(mergeUrlQueryParams(getUrlHashParams(hash), params), hash);
|
|
13
|
-
}
|
|
14
|
-
export default navigateToMergedHashParams;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import mergeUrlQueryParams from "@koine/utils/mergeUrlQueryParams";
|
|
2
|
-
import getUrlQueryParams from "@koine/utils/getUrlQueryParams";
|
|
3
|
-
import { navigateToParams } from "./navigateToParams";
|
|
4
|
-
/**
|
|
5
|
-
* Merge current URL query parameters with the given ones, 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
|
-
*/
|
|
10
|
-
export function navigateToMergedParams(params, replace) {
|
|
11
|
-
if (params === void 0) { params = {}; }
|
|
12
|
-
return navigateToParams(mergeUrlQueryParams(getUrlQueryParams(), params), replace);
|
|
13
|
-
}
|
|
14
|
-
export default navigateToMergedParams;
|
package/navigateToParams.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import isBrowser from "@koine/utils/isBrowser";
|
|
2
|
-
import buildUrlQueryString from "@koine/utils/buildUrlQueryString";
|
|
3
|
-
import navigateToUrl from "./navigateToUrl";
|
|
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
|
-
*/
|
|
11
|
-
export function navigateToParams(params, replace) {
|
|
12
|
-
if (params === void 0) { params = {}; }
|
|
13
|
-
var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
|
|
14
|
-
if (isBrowser) {
|
|
15
|
-
navigateToUrl(location.pathname + queryString, replace);
|
|
16
|
-
}
|
|
17
|
-
return queryString;
|
|
18
|
-
}
|
|
19
|
-
export default navigateToParams;
|
package/navigateToUrl.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It updates the browser's location URL with global `history` object
|
|
3
|
-
*
|
|
4
|
-
* @category location
|
|
5
|
-
*/
|
|
6
|
-
export function navigateToUrl(url, replace) {
|
|
7
|
-
if (url === void 0) { url = ""; }
|
|
8
|
-
if (url) {
|
|
9
|
-
history[replace ? "replaceState" : "pushState"](history.state, "", url);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export default navigateToUrl;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import getUrlQueryParams from "@koine/utils/getUrlQueryParams";
|
|
2
|
-
import navigateToParams from "./navigateToParams";
|
|
3
|
-
/**
|
|
4
|
-
* Remove URL query parameter, it uses `history`
|
|
5
|
-
*
|
|
6
|
-
* @category location
|
|
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) {
|
|
13
|
-
if (key !== paramName) {
|
|
14
|
-
params[key] = currentParams[key];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return navigateToParams(params, replace);
|
|
18
|
-
}
|
|
19
|
-
export default navigateWithoutUrlParam;
|
package/redirectTo.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import isBrowser from "@koine/utils/isBrowser";
|
|
2
|
-
import buildUrlQueryString from "@koine/utils/buildUrlQueryString";
|
|
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
|
-
*/
|
|
9
|
-
export function redirectTo(url, params) {
|
|
10
|
-
if (isBrowser) {
|
|
11
|
-
var queryString = buildUrlQueryString(params);
|
|
12
|
-
location.href = url.replace(/\?+$/g, "") + queryString;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export default redirectTo;
|
package/storage.mjs
DELETED
package/storageClient.mjs
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import isBrowser from "@koine/utils/isBrowser";
|
|
2
|
-
import isString from "@koine/utils/isString";
|
|
3
|
-
var methodsMap = { g: "getItem", s: "setItem", r: "removeItem" };
|
|
4
|
-
/**
|
|
5
|
-
* Super minifiable `local/session Storage` client creator with SSR safety
|
|
6
|
-
*/
|
|
7
|
-
export var storageClient = function (useSessionStorage) {
|
|
8
|
-
var nativeMethod = function (method, key, value) {
|
|
9
|
-
return isBrowser
|
|
10
|
-
? window[useSessionStorage ? "sessionStorage" : "localStorage"][methodsMap[method]](key, value)
|
|
11
|
-
: function () {
|
|
12
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
13
|
-
console.warn("[@koine/utils:storageClient]: ".concat(useSessionStorage ? "sessionStorage" : "localStorage", " does not exists outside of browser."));
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
var get = function (key, transform, defaultValue) {
|
|
18
|
-
var value = defaultValue !== null && defaultValue !== void 0 ? defaultValue : null;
|
|
19
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
20
|
-
if (!isBrowser) {
|
|
21
|
-
console.log("[@koine/utils:storage] called 'get' outside of browser with default value '".concat(JSON.stringify(defaultValue), "'."));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (isBrowser) {
|
|
25
|
-
var stored = nativeMethod("g", key);
|
|
26
|
-
if (stored) {
|
|
27
|
-
stored = transform ? transform(stored) : stored;
|
|
28
|
-
try {
|
|
29
|
-
var parsed = JSON.parse(stored);
|
|
30
|
-
if (parsed)
|
|
31
|
-
value = parsed;
|
|
32
|
-
}
|
|
33
|
-
catch (_e) {
|
|
34
|
-
value = stored;
|
|
35
|
-
// if (process.env["NODE_ENV"] !== "production") {
|
|
36
|
-
// console.warn(
|
|
37
|
-
// `[@koine/utils:storage]: 'get' failed to parse stored value as JSON. Plain '${stored}' value is returned.`
|
|
38
|
-
// );
|
|
39
|
-
// }
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
};
|
|
45
|
-
var set = function (key, value, transform) {
|
|
46
|
-
if (transform === void 0) { transform = function (value) { return value; }; }
|
|
47
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
48
|
-
if (!isBrowser) {
|
|
49
|
-
console.log("[@koine/utils:storage] called 'set' outside of browser does not work.");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (isBrowser) {
|
|
53
|
-
try {
|
|
54
|
-
var transformedValue = isString(value)
|
|
55
|
-
? transform(value)
|
|
56
|
-
: transform(JSON.stringify(value));
|
|
57
|
-
nativeMethod("s", key, transformedValue);
|
|
58
|
-
}
|
|
59
|
-
catch (_e) {
|
|
60
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
61
|
-
console.warn("[@koine/utils:createStorage]: 'set' error.", _e);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
var remove = function (key) {
|
|
67
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
68
|
-
if (!isBrowser) {
|
|
69
|
-
console.log("[@koine/utils:storage] called 'remove' outside of browser does not work.");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (isBrowser) {
|
|
73
|
-
try {
|
|
74
|
-
nativeMethod("r", key);
|
|
75
|
-
}
|
|
76
|
-
catch (_e) {
|
|
77
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
78
|
-
console.warn("[@koine/utils:createStorage]: 'remove' error.", _e);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var has = function (key, defaultValue) {
|
|
84
|
-
var value = defaultValue !== null && defaultValue !== void 0 ? defaultValue : false;
|
|
85
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
86
|
-
if (!isBrowser) {
|
|
87
|
-
console.log("[@koine/utils:storage] called 'has' outside of browser with default value '".concat(JSON.stringify(defaultValue), "'."));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (isBrowser) {
|
|
91
|
-
var stored = nativeMethod("g", key);
|
|
92
|
-
value = stored !== null && stored !== void 0 ? stored : false;
|
|
93
|
-
}
|
|
94
|
-
return value;
|
|
95
|
-
};
|
|
96
|
-
return {
|
|
97
|
-
get: get,
|
|
98
|
-
set: set,
|
|
99
|
-
remove: remove,
|
|
100
|
-
has: has,
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
export default storageClient;
|