@yqg/beetle
Advanced tools
| type EnvStage = 'prod' | 'test' | 'dev' | 'indo' | 'mex' | 'phi' | 'eu' | 'cn'; | ||
| interface OperateEnvOptions { | ||
| useUrlParam?: boolean; | ||
| urlParamKey?: string; | ||
| envAlias?: string; | ||
| } | ||
| /** | ||
| * 操作环境的工具函数 | ||
| * 通过 env 方法设置当前环境 | ||
| * @param {string} stage - 当前的stage | ||
| * @param {object} options - 配置项,包含额外判定条件 | ||
| * @returns {object} - 返回可以获取当前环境的 isXXX 方法 | ||
| */ | ||
| declare const operateEnv: { | ||
| env: (stage: EnvStage) => void; | ||
| isProd: (options?: OperateEnvOptions) => boolean; | ||
| isDev: (options?: OperateEnvOptions) => boolean; | ||
| isTest: (options?: OperateEnvOptions) => boolean; | ||
| isCn: (options?: OperateEnvOptions) => boolean; | ||
| isIndo: (options?: OperateEnvOptions) => boolean; | ||
| isMex: (options?: OperateEnvOptions) => boolean; | ||
| isPhi: (options?: OperateEnvOptions) => boolean; | ||
| isEu: (options?: OperateEnvOptions) => boolean; | ||
| }; | ||
| export default operateEnv; |
| const l = /* @__PURE__ */ function() { | ||
| let t = null; | ||
| const c = (e) => { | ||
| t = e; | ||
| }, r = (e, n) => { | ||
| const a = (n == null ? void 0 : n.envAlias) || e; | ||
| if (n != null && n.useUrlParam && new URLSearchParams(window.location.search).get(n.urlParamKey || "env") === a) | ||
| return !0; | ||
| if (a === "cn") | ||
| return (t == null ? void 0 : t.indexOf("-")) === -1; | ||
| const u = location.hostname, s = new RegExp(a); | ||
| return ["dev", "test", "prod"].includes(e) ? s.test(t || "") : s.test(t || "") || s.test(u); | ||
| }; | ||
| return { | ||
| env: c, | ||
| // 用于设置当前的环境 | ||
| isProd: (e) => r("prod", e), | ||
| // 判断是否是生产环境 | ||
| isDev: (e) => r("dev", e), | ||
| // 判断是否是开发环境 | ||
| isTest: (e) => r("test", e), | ||
| // 判断是否是测试环境 | ||
| isCn: (e) => r("cn", e), | ||
| // 判断是否是中国环境 | ||
| isIndo: (e) => r("indo", e), | ||
| // 判断是否是印尼环境 | ||
| isMex: (e) => r("mex", e), | ||
| // 判断是否是墨西哥环境 | ||
| isPhi: (e) => r("phi", e), | ||
| // 判断是否是菲律宾环境 | ||
| isEu: (e) => r("eu", e) | ||
| // 判断是否是波兰环境 | ||
| }; | ||
| }(); | ||
| export { | ||
| l as default | ||
| }; |
+28
-26
| import r from "./data/arrayToTree/index.mjs"; | ||
| import o from "./data/treeToArray/index.mjs"; | ||
| import m from "./data/traverseDeep/index.mjs"; | ||
| import i from "./data/mergeDeep/index.mjs"; | ||
| import t from "./data/parseJSON/index.mjs"; | ||
| import t from "./data/mergeDeep/index.mjs"; | ||
| import i from "./data/parseJSON/index.mjs"; | ||
| import e from "./data/stringifyJSON/index.mjs"; | ||
@@ -13,4 +13,4 @@ import f from "./data/formatStrToArray/index.mjs"; | ||
| import g from "./url/removeQueryParam/index.mjs"; | ||
| import y from "./validate/isValidMobile/index.mjs"; | ||
| import n from "./validate/isValidPhone/index.mjs"; | ||
| import n from "./validate/isValidMobile/index.mjs"; | ||
| import y from "./validate/isValidPhone/index.mjs"; | ||
| import d from "./format/formatFileSize/index.mjs"; | ||
@@ -28,9 +28,9 @@ import T from "./format/maskNumber/index.mjs"; | ||
| import N from "./date/isValidDate/index.mjs"; | ||
| import A from "./cookie/setCookie/index.mjs"; | ||
| import C from "./cookie/getCookie/index.mjs"; | ||
| import O from "./date/getTimeAgo/index.mjs"; | ||
| import R from "./date/getDaysDiff/index.mjs"; | ||
| import v from "./date/getWeekDay/index.mjs"; | ||
| import x from "./date/getDaysInMonth/index.mjs"; | ||
| import E from "./date/isLeapYear/index.mjs"; | ||
| import v from "./cookie/setCookie/index.mjs"; | ||
| import A from "./cookie/getCookie/index.mjs"; | ||
| import C from "./date/getTimeAgo/index.mjs"; | ||
| import E from "./date/getDaysDiff/index.mjs"; | ||
| import O from "./date/getWeekDay/index.mjs"; | ||
| import R from "./date/getDaysInMonth/index.mjs"; | ||
| import x from "./date/isLeapYear/index.mjs"; | ||
| import F from "./date/formatSeconds/index.mjs"; | ||
@@ -43,4 +43,5 @@ import I from "./validate/isValidURL/index.mjs"; | ||
| import z from "./file/getFileType/index.mjs"; | ||
| import B from "./package.json.mjs"; | ||
| import * as J from "lodash-es"; | ||
| import B from "./util/operateEnv/index.mjs"; | ||
| import J from "./package.json.mjs"; | ||
| import * as M from "lodash-es"; | ||
| const Rr = { | ||
@@ -50,4 +51,4 @@ arrayToTree: r, | ||
| traverseDeep: m, | ||
| mergeDeep: i, | ||
| parseJSON: t, | ||
| mergeDeep: t, | ||
| parseJSON: i, | ||
| stringifyJSON: e, | ||
@@ -59,4 +60,4 @@ formatStrToArray: f, | ||
| removeQueryParam: g, | ||
| isValidMobile: y, | ||
| isValidPhone: n, | ||
| isValidMobile: n, | ||
| isValidPhone: y, | ||
| formatFileSize: d, | ||
@@ -74,9 +75,9 @@ maskNumber: T, | ||
| isValidDate: N, | ||
| setCookie: A, | ||
| getCookie: C, | ||
| getTimeAgo: O, | ||
| getDaysDiff: R, | ||
| getWeekDay: v, | ||
| getDaysInMonth: x, | ||
| isLeapYear: E, | ||
| setCookie: v, | ||
| getCookie: A, | ||
| getTimeAgo: C, | ||
| getDaysDiff: E, | ||
| getWeekDay: O, | ||
| getDaysInMonth: R, | ||
| isLeapYear: x, | ||
| formatSeconds: F, | ||
@@ -90,4 +91,5 @@ isValidURL: I, | ||
| isDeepEqual: p, | ||
| ...J, | ||
| VERSION: B.version | ||
| operateEnv: B, | ||
| ...M, | ||
| VERSION: J.version | ||
| }; | ||
@@ -94,0 +96,0 @@ export { |
+18
-16
@@ -5,3 +5,3 @@ export * from "lodash-es"; | ||
| import { default as s } from "./data/traverseDeep/index.mjs"; | ||
| import { default as d } from "./data/mergeDeep/index.mjs"; | ||
| import { default as p } from "./data/mergeDeep/index.mjs"; | ||
| import { default as u } from "./data/parseJSON/index.mjs"; | ||
@@ -16,8 +16,8 @@ import { default as i } from "./data/stringifyJSON/index.mjs"; | ||
| import { default as C } from "./validate/isValidMobile/index.mjs"; | ||
| import { default as F } from "./validate/isValidPhone/index.mjs"; | ||
| import { default as O } from "./format/formatFileSize/index.mjs"; | ||
| import { default as R } from "./format/maskNumber/index.mjs"; | ||
| import { default as v } from "./format/formatPercentage/index.mjs"; | ||
| import { default as z } from "./format/formatNumber/index.mjs"; | ||
| import { default as E } from "./format/formatCurrency/index.mjs"; | ||
| import { default as v } from "./validate/isValidPhone/index.mjs"; | ||
| import { default as F } from "./format/formatFileSize/index.mjs"; | ||
| import { default as O } from "./format/maskNumber/index.mjs"; | ||
| import { default as R } from "./format/formatPercentage/index.mjs"; | ||
| import { default as w } from "./format/formatNumber/index.mjs"; | ||
| import { default as B } from "./format/formatCurrency/index.mjs"; | ||
| import { default as J } from "./util/copyToClipboard/index.mjs"; | ||
@@ -34,3 +34,3 @@ import { default as j } from "./util/hexToRGB/index.mjs"; | ||
| import { default as se } from "./date/formatSeconds/index.mjs"; | ||
| import { default as de } from "./date/getDaysDiff/index.mjs"; | ||
| import { default as pe } from "./date/getDaysDiff/index.mjs"; | ||
| import { default as ue } from "./date/getWeekDay/index.mjs"; | ||
@@ -45,2 +45,3 @@ import { default as ie } from "./date/getDaysInMonth/index.mjs"; | ||
| import { default as Ce } from "./file/getFileType/index.mjs"; | ||
| import { default as ve } from "./util/operateEnv/index.mjs"; | ||
| import { default as Fe } from "./beetle.mjs"; | ||
@@ -52,10 +53,10 @@ export { | ||
| he as downloadFile, | ||
| E as formatCurrency, | ||
| O as formatFileSize, | ||
| z as formatNumber, | ||
| v as formatPercentage, | ||
| B as formatCurrency, | ||
| F as formatFileSize, | ||
| w as formatNumber, | ||
| R as formatPercentage, | ||
| se as formatSeconds, | ||
| y as formatStrToArray, | ||
| oe as getCookie, | ||
| de as getDaysDiff, | ||
| pe as getDaysDiff, | ||
| ie as getDaysInMonth, | ||
@@ -75,6 +76,7 @@ Ce as getFileType, | ||
| C as isValidMobile, | ||
| F as isValidPhone, | ||
| v as isValidPhone, | ||
| Te as isValidURL, | ||
| R as maskNumber, | ||
| d as mergeDeep, | ||
| O as maskNumber, | ||
| p as mergeDeep, | ||
| ve as operateEnv, | ||
| u as parseJSON, | ||
@@ -81,0 +83,0 @@ h as removeQueryParam, |
@@ -49,2 +49,3 @@ /** | ||
| export { default as getFileType } from './file/getFileType/index'; | ||
| export { default as operateEnv } from './util/operateEnv/index'; | ||
| export { default } from './beetle'; |
@@ -1,20 +0,20 @@ | ||
| function i(c, a = {}) { | ||
| const { onSuccess: t, onError: o } = a; | ||
| if (typeof c != "string") | ||
| function r(a, i = {}) { | ||
| const { onSuccess: o, onError: e } = i; | ||
| if (typeof a != "string") | ||
| throw new Error("Invalid content value"); | ||
| if (navigator.clipboard) | ||
| navigator.clipboard.writeText(c).then(() => { | ||
| t && t(); | ||
| }).catch((e) => { | ||
| o && o(e); | ||
| navigator.clipboard.writeText(a).then(() => { | ||
| o && o(); | ||
| }).catch((t) => { | ||
| e && e(t); | ||
| }); | ||
| else { | ||
| const e = document.createElement("textarea"); | ||
| e.value = c, e.style.position = "fixed", document.body.appendChild(e), e.select(); | ||
| const t = document.createElement("textarea"); | ||
| t.value = a, t.style.position = "fixed", document.body.appendChild(t), t.select(); | ||
| try { | ||
| document.execCommand("copy") && t ? t() : o && o(new Error("Failed to copy content")); | ||
| } catch (r) { | ||
| o && o(r); | ||
| document.execCommand("copy") ? o == null || o() : e == null || e(new Error("Failed to copy content")); | ||
| } catch (c) { | ||
| e && e(c); | ||
| } finally { | ||
| document.body.removeChild(e); | ||
| document.body.removeChild(t); | ||
| } | ||
@@ -24,3 +24,3 @@ } | ||
| export { | ||
| i as default | ||
| r as default | ||
| }; |
+2
-2
| { | ||
| "name": "@yqg/beetle", | ||
| "version": "1.0.6", | ||
| "version": "1.0.7", | ||
| "type": "module", | ||
@@ -86,2 +86,2 @@ "types": "./dist-utils/types/index.d.ts", | ||
| } | ||
| } | ||
| } |
65222
3.73%89
2.3%1749
3.98%