@hylid/env 0.0.90011183064-dev.22 → 0.0.90011267721-dev.2
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,5 +1,6 @@
|
|
|
1
1
|
import { mpWebChecker } from "../checker";
|
|
2
2
|
import { getMatchName } from "../utils";
|
|
3
3
|
export function getName4MpWeb() {
|
|
4
|
-
|
|
4
|
+
var _a;
|
|
5
|
+
return getMatchName(mpWebChecker, ((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) || '');
|
|
5
6
|
}
|
|
@@ -2,5 +2,6 @@ import { webChecker } from "../checker";
|
|
|
2
2
|
import { CLIENT } from "../constants";
|
|
3
3
|
import { getMatchName } from "../utils";
|
|
4
4
|
export function getName4Web() {
|
|
5
|
-
|
|
5
|
+
var _a;
|
|
6
|
+
return getMatchName(webChecker, ((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) || '') || CLIENT.H5;
|
|
6
7
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Checker } from './types';
|
|
2
|
+
export declare const isClient: boolean;
|
|
2
3
|
export declare function isMP(): boolean;
|
|
3
4
|
export declare function getMatchName(checks: Checker[], pattern: string): string | undefined;
|
|
4
5
|
export declare function createCommonEnv<T>(source: Record<string, string>, current?: string): T;
|
package/lib/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
1
2
|
var __assign = this && this.__assign || function () {
|
|
2
3
|
__assign = Object.assign || function (t) {
|
|
3
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -8,6 +9,7 @@ var __assign = this && this.__assign || function () {
|
|
|
8
9
|
};
|
|
9
10
|
return __assign.apply(this, arguments);
|
|
10
11
|
};
|
|
12
|
+
export var isClient = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object';
|
|
11
13
|
export function isMP() {
|
|
12
14
|
// 小程序一定有 my
|
|
13
15
|
if (typeof my === 'undefined') return false;
|
|
@@ -41,13 +43,13 @@ export function notice(text) {
|
|
|
41
43
|
console.info("[hylid-env]: ".concat(text));
|
|
42
44
|
}
|
|
43
45
|
export function getSettingName() {
|
|
44
|
-
var _a;
|
|
46
|
+
var _a, _b;
|
|
45
47
|
var ENV_KEY = '__hy_env__';
|
|
46
|
-
var clientMatch = ((_a = window.location.search) === null || _a === void 0 ? void 0 : _a.match(/__app__=([^&]*)/)) || [];
|
|
48
|
+
var clientMatch = isClient ? ((_a = window.location.search) === null || _a === void 0 ? void 0 : _a.match(/__app__=([^&]*)/)) || [] : [];
|
|
47
49
|
var client = clientMatch[1];
|
|
48
|
-
var platformMatch = window.location.search.match(/__platform__=([^&]*)/) || [];
|
|
50
|
+
var platformMatch = isClient ? ((_b = window.location.search) === null || _b === void 0 ? void 0 : _b.match(/__platform__=([^&]*)/)) || [] : [];
|
|
49
51
|
var platform = platformMatch[1];
|
|
50
|
-
var env = JSON.parse(localStorage.getItem(ENV_KEY) || '{}') || {};
|
|
52
|
+
var env = isClient ? JSON.parse(localStorage.getItem(ENV_KEY) || '{}') || {} : {};
|
|
51
53
|
if (client) {
|
|
52
54
|
env.client = client;
|
|
53
55
|
}
|
|
@@ -65,8 +67,8 @@ export function getSettingName() {
|
|
|
65
67
|
var newUrl = "".concat(window.location.pathname).concat(search).concat(hash);
|
|
66
68
|
history.replaceState(null, '', newUrl);
|
|
67
69
|
}
|
|
68
|
-
var cached = JSON.parse(localStorage.getItem(ENV_KEY) || '{}');
|
|
69
|
-
var crossBridgeStorage = localStorage.getItem('_CB__app__');
|
|
70
|
+
var cached = isClient ? JSON.parse(localStorage.getItem(ENV_KEY) || '{}') : {};
|
|
71
|
+
var crossBridgeStorage = isClient ? localStorage.getItem('_CB__app__') : undefined;
|
|
70
72
|
return crossBridgeStorage ? __assign(__assign({}, cached), {
|
|
71
73
|
client: crossBridgeStorage
|
|
72
74
|
}) : cached;
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.0.
|
|
1
|
+
export default '0.0.90011267721-dev.2';
|