Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hylid/env

Package Overview
Dependencies
Maintainers
0
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hylid/env - npm Package Compare versions

Comparing version 3.0.0-alpha.2 to 3.0.0-alpha.4

4

lib/getClientName/getName4Mp.js
import { mpChecker } from "../checker";
import { CLIENT } from "../constants";
import { getMatchName, isNotMP } from "../utils";
import { getMatchName } from "../utils";
export function getName4MP() {

@@ -8,5 +8,3 @@ // 微信小程序

if (typeof wx !== 'undefined') return CLIENT.WECHAT;
// 支付宝系小程序
if (isNotMP()) return;
return getMatchName(mpChecker, my.getSystemInfoSync().app);
}

@@ -1,6 +0,1 @@

/**
* 1. 优先从 URL 解析 __app__
* 2. 其次从 Storage 解析 __app__
* 3. 再之解析 userAgent
*/
export declare function getName4MpWeb(): string | undefined;

@@ -1,20 +0,5 @@

import { mpChecker, mpWebChecker } from "../checker";
import { CLIENT } from "../constants";
import { getMatchName, getUrlClientName, getStorageClientName } from "../utils";
/**
* 1. 优先从 URL 解析 __app__
* 2. 其次从 Storage 解析 __app__
* 3. 再之解析 userAgent
*/
import { mpWebChecker } from "../checker";
import { getMatchName } from "../utils";
export function getName4MpWeb() {
var appName = getUrlClientName() || getStorageClientName();
if (appName) {
// 如果 hylid-bridge 的 client 枚举值找到了 app,则优先用 hylid-bridge 的
if (Object.keys(CLIENT).find(function (i) {
return CLIENT[i] === appName;
})) return appName;
// 套壳的 __app__ 参数,一般是壳子拼的,值从 getSystemInfoSync 取的,所以使用 mpChecker
return getMatchName(mpChecker, appName);
}
return getMatchName(mpWebChecker, window.navigator.userAgent);
}

@@ -1,1 +0,1 @@

export declare function getName4Web(): string | undefined;
export declare function getName4Web(): string;

@@ -1,16 +0,6 @@

import { webChecker, mpChecker } from "../checker";
import { webChecker } from "../checker";
import { CLIENT } from "../constants";
import { getMatchName, getUrlClientName, getStorageClientName } from "../utils";
import { getMatchName } from "../utils";
export function getName4Web() {
var appName = getUrlClientName() || getStorageClientName();
// 无法识别的,可以手动指定 __app__ 参数
if (appName) {
// 如果 hylid-bridge 的 client 枚举值找到了 app,则优先用 hylid-bridge 的
if (Object.keys(CLIENT).find(function (i) {
return CLIENT[i] === appName;
})) return appName;
// 指定的 __app__ 和小程序返回值对齐
return getMatchName(mpChecker, appName);
}
return getMatchName(webChecker, window.navigator.userAgent) || CLIENT.H5;
}

@@ -1,2 +0,2 @@

import { createCommonEnv, notice } from "./utils";
import { createCommonEnv, getSettingName, isMP, notice } from "./utils";
import { getName4MP, getName4MpWeb, getName4Web } from "./getClientName";

@@ -6,21 +6,17 @@ import { CLIENT, PLATFORM } from "./constants";

var platform;
/**
* 优先判断小程序,根据 my.SDKVersion 是否存在进行判断
* 其次判断套壳 H5,根据 UA 是否存在 miniprogram 字段进行判断
* 再者判断端内 H5,UA 不存在 miniprogram 且含有钱包特征值进行判断
* 不满足上面的条件时,判断为端外 H5
*/
// 小程序
client = getName4MP();
if (client) {
if (isMP()) {
client = getName4MP();
platform = PLATFORM.MP;
} else {
// 套壳 H5
client = getName4MpWeb();
if (client) {
platform = PLATFORM.MPWEB;
var setting = getSettingName();
if (setting.platform) {
platform = setting.platform;
client = setting.client || (platform === 'mpweb' ? getName4MpWeb() : getName4Web());
} else {
// 端内/端外 H5
client = getName4Web();
// 如果只设置了 client,默认是套壳场景
client = setting.client || getName4MpWeb();
if (client) {
platform = PLATFORM.MPWEB;
} else {
client = getName4Web();
platform = PLATFORM.WEB;

@@ -30,3 +26,3 @@ }

}
if (!platform) {
if (!platform || !client) {
notice('Cannot identify your client.');

@@ -33,0 +29,0 @@ }

import { Checker } from './types';
export declare function isNotMP(): boolean;
export declare function isMP(): boolean;
export declare function getMatchName(checks: Checker[], pattern: string): string | undefined;
export declare function createCommonEnv<T>(source: Record<string, string>, current?: string): T;
export declare function notice(text: string): void;
export declare function getUrlClientName(): string;
export declare function getStorageClientName(): string | null;
export declare function getSettingName(): any;

@@ -1,6 +0,8 @@

export function isNotMP() {
export function isMP() {
// @ts-ignore
if (typeof wx !== 'undefined') return true;
// 小程序一定有 my
if (typeof my == 'undefined') return true;
if (typeof my === 'undefined') return false;
// SDKVersion 只在小程序有
if (typeof my.SDKVersion !== 'string') return true;
if (typeof my.SDKVersion === 'string') return true;
return false;

@@ -33,8 +35,13 @@ }

}
export function getUrlClientName() {
return (window.location.search.match(/[?&]__app__=([^?&=]+)/) || [])[1];
}
export function getStorageClientName() {
// __app__ 值和 getSystemInfo 里的 app 保持对齐
return localStorage.getItem('__app__');
export function getSettingName() {
var client = (window.location.search.match(/[?&]__app__=([^?&=]+)/) || [])[1];
var platform = (window.location.search.match(/[?&]__platform__=([^?&=]+)/) || [])[1];
if (client || platform) {
localStorage.setItem('__hy_env__', JSON.stringify({
client: client,
platform: platform
}));
}
var cached = localStorage.getItem('__hy_env__');
return cached ? JSON.parse(cached) : {};
}
{
"name": "@hylid/env",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "files": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc