@wzyjs/utils 0.3.32 → 0.3.36

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.
@@ -4,6 +4,7 @@ export declare const replaceByRules: (str: string, rules: [string, string][]) =>
4
4
  export declare const replaceByVariables: (prompt: string, variables?: {
5
5
  [key: string]: string;
6
6
  }) => string;
7
+ export declare const getSafeCallbackPath: (value: string | null, fallback: string) => string;
7
8
  export declare const getType: (value: any) => any;
8
9
  export declare const safeJsonParse: <T = any>(value: unknown, fallback: T) => T;
9
10
  export declare const isJsonObject: (str: string) => boolean;
@@ -0,0 +1,14 @@
1
+ export type CorsOptions = {
2
+ allowHeaders?: string[];
3
+ allowMethods?: string[];
4
+ maxAge?: string;
5
+ };
6
+ export declare const createCorsHeaders: (request: Request, options?: CorsOptions) => {
7
+ 'Access-Control-Allow-Headers': string;
8
+ 'Access-Control-Allow-Methods': string;
9
+ 'Access-Control-Allow-Origin': string;
10
+ 'Access-Control-Max-Age': string;
11
+ Vary: string;
12
+ };
13
+ export declare const applyCorsHeaders: (request: Request, response: Response, options?: CorsOptions) => Response;
14
+ export declare const createCorsPreflightResponse: (request: Request, options?: CorsOptions) => Response;
@@ -1,8 +1,21 @@
1
+ export declare const getExtFromFileName: (fileName?: string) => string;
2
+ export declare const getExtFromMimeType: (mimeType?: string) => string;
1
3
  export declare const getMimeType: (fileName: string) => string;
4
+ export declare const normalizeDataUrlBase64: (value: string) => {
5
+ base64: string;
6
+ mimeType?: string;
7
+ };
8
+ export declare const parseBase64File: (input: {
9
+ fileBase64: string;
10
+ mimeType?: string;
11
+ }) => {
12
+ buffer: Buffer;
13
+ mimeType?: string;
14
+ };
2
15
  export declare const replaceContentInFile: (filePath: string, targetContent: string, replacement: string) => Promise<void>;
3
16
  export declare const downloadFile: (httpUrl: string, outputPath?: string) => Promise<string>;
4
17
  /**
5
- * 上传文件参数
18
+ * 描述 processFile 支持的文件来源和对应输入内容。
6
19
  */
7
20
  export interface UploadFileParams {
8
21
  /**
@@ -23,7 +36,7 @@ export interface UploadFileParams {
23
36
  file: string | Buffer | File;
24
37
  }
25
38
  /**
26
- * 文件处理结果
39
+ * 描述 processFile 归一化后的文件元信息和内容。
27
40
  */
28
41
  export interface UploadFileResult {
29
42
  /** 文件内容 Buffer */
@@ -42,7 +55,7 @@ export interface UploadFileResult {
42
55
  ext: string;
43
56
  }
44
57
  /**
45
- * 处理各种类型的文件输入,将其统一转换为标准的文件信息对象
58
+ * 处理各种类型的文件输入,将其统一转换为标准的文件信息对象。
46
59
  *
47
60
  * @description
48
61
  * 该函数用于处理不同来源的文件(URL、本地路径、Buffer、File对象),
package/dist/node.cjs.js CHANGED
@@ -5539,6 +5539,7 @@ __export(exports_node, {
5539
5539
  getType: () => getType,
5540
5540
  getStrLength: () => getStrLength,
5541
5541
  getSliceStr: () => getSliceStr,
5542
+ getSafeCallbackPath: () => getSafeCallbackPath,
5542
5543
  getRandomString: () => getRandomString,
5543
5544
  getRandomColor: () => getRandomColor,
5544
5545
  getPublicUrl: () => getPublicUrl,
@@ -5564,6 +5565,7 @@ __export(exports_node, {
5564
5565
  custom: () => custom,
5565
5566
  cron: () => exports_cron,
5566
5567
  crawl: () => exports_crawl,
5568
+ cors: () => exports_cors,
5567
5569
  consola: () => import_consola.default,
5568
5570
  coerce: () => coerce,
5569
5571
  cheerio: () => cheerio,
@@ -10413,6 +10415,12 @@ var replaceByVariables = (prompt, variables) => {
10413
10415
  return variables[p1] ?? match;
10414
10416
  });
10415
10417
  };
10418
+ var getSafeCallbackPath = (value, fallback) => {
10419
+ if (!value || !value.startsWith("/") || value.startsWith("//")) {
10420
+ return fallback;
10421
+ }
10422
+ return value;
10423
+ };
10416
10424
  var getType = (value) => {
10417
10425
  return Object.prototype.toString.call(value).slice(8, -1);
10418
10426
  };
@@ -10726,6 +10734,36 @@ var Timezone;
10726
10734
  Timezone2["EuropeBerlin"] = "Europe/Berlin";
10727
10735
  })(Timezone ||= {});
10728
10736
  var dayjs_default = import_dayjs.default;
10737
+ // src/node/cors.ts
10738
+ var exports_cors = {};
10739
+ __export(exports_cors, {
10740
+ createCorsPreflightResponse: () => createCorsPreflightResponse,
10741
+ createCorsHeaders: () => createCorsHeaders,
10742
+ applyCorsHeaders: () => applyCorsHeaders
10743
+ });
10744
+ var DEFAULT_ALLOW_HEADERS = ["Authorization", "Content-Type", "X-TRPC-Source"];
10745
+ var DEFAULT_ALLOW_METHODS = ["GET", "POST", "OPTIONS"];
10746
+ var DEFAULT_MAX_AGE = "86400";
10747
+ var createCorsHeaders = (request, options = {}) => {
10748
+ const origin = request.headers.get("origin") ?? "*";
10749
+ return {
10750
+ "Access-Control-Allow-Headers": (options.allowHeaders ?? DEFAULT_ALLOW_HEADERS).join(", "),
10751
+ "Access-Control-Allow-Methods": (options.allowMethods ?? DEFAULT_ALLOW_METHODS).join(", "),
10752
+ "Access-Control-Allow-Origin": origin,
10753
+ "Access-Control-Max-Age": options.maxAge ?? DEFAULT_MAX_AGE,
10754
+ Vary: "Origin"
10755
+ };
10756
+ };
10757
+ var applyCorsHeaders = (request, response, options) => {
10758
+ Object.entries(createCorsHeaders(request, options)).forEach(([key2, value]) => {
10759
+ response.headers.set(key2, value);
10760
+ });
10761
+ return response;
10762
+ };
10763
+ var createCorsPreflightResponse = (request, options) => new Response(null, {
10764
+ headers: createCorsHeaders(request, options),
10765
+ status: 204
10766
+ });
10729
10767
  // src/node/oss/index.ts
10730
10768
  var exports_oss = {};
10731
10769
  __export(exports_oss, {
@@ -10894,7 +10932,11 @@ var exports_file = {};
10894
10932
  __export(exports_file, {
10895
10933
  replaceContentInFile: () => replaceContentInFile,
10896
10934
  processFile: () => processFile,
10935
+ parseBase64File: () => parseBase64File,
10936
+ normalizeDataUrlBase64: () => normalizeDataUrlBase64,
10897
10937
  getMimeType: () => getMimeType,
10938
+ getExtFromMimeType: () => getExtFromMimeType,
10939
+ getExtFromFileName: () => getExtFromFileName,
10898
10940
  downloadFile: () => downloadFile
10899
10941
  });
10900
10942
  var import_fs_extra = __toESM(require("fs-extra"));
@@ -10902,53 +10944,62 @@ var import_axios9 = __toESM(require("axios"));
10902
10944
  var import_url = __toESM(require("url"));
10903
10945
  var path2 = __toESM(require("path"));
10904
10946
  var import_crypto = __toESM(require("crypto"));
10947
+ var mimeExtMap = {
10948
+ "image/png": ["png"],
10949
+ "image/jpeg": ["jpg", "jpeg"],
10950
+ "image/gif": ["gif"],
10951
+ "image/webp": ["webp"],
10952
+ "image/svg+xml": ["svg"],
10953
+ "video/mp4": ["mp4"],
10954
+ "audio/mpeg": ["mp3"],
10955
+ "application/pdf": ["pdf"],
10956
+ "application/msword": ["doc"],
10957
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ["docx"],
10958
+ "application/vnd.ms-excel": ["xls"],
10959
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ["xlsx"],
10960
+ "application/vnd.ms-powerpoint": ["ppt"],
10961
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": ["pptx"],
10962
+ "text/plain": ["txt"],
10963
+ "text/html": ["html"],
10964
+ "text/css": ["css"],
10965
+ "application/javascript": ["js"],
10966
+ "application/json": ["json"],
10967
+ "application/xml": ["xml"]
10968
+ };
10969
+ var getExtFromFileName = (fileName) => {
10970
+ return fileName ? path2.extname(fileName).toLowerCase() : "";
10971
+ };
10972
+ var getExtFromMimeType = (mimeType) => {
10973
+ const ext = mimeType ? mimeExtMap[mimeType]?.[0] : "";
10974
+ return ext ? `.${ext}` : "";
10975
+ };
10905
10976
  var getMimeType = (fileName) => {
10906
- const ext = fileName.split(".").pop()?.toLowerCase();
10907
- switch (ext) {
10908
- case "png":
10909
- return "image/png";
10910
- case "jpg":
10911
- case "jpeg":
10912
- return "image/jpeg";
10913
- case "gif":
10914
- return "image/gif";
10915
- case "webp":
10916
- return "image/webp";
10917
- case "svg":
10918
- return "image/svg+xml";
10919
- case "mp4":
10920
- return "video/mp4";
10921
- case "mp3":
10922
- return "audio/mpeg";
10923
- case "pdf":
10924
- return "application/pdf";
10925
- case "doc":
10926
- return "application/msword";
10927
- case "docx":
10928
- return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
10929
- case "xls":
10930
- return "application/vnd.ms-excel";
10931
- case "xlsx":
10932
- return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
10933
- case "ppt":
10934
- return "application/vnd.ms-powerpoint";
10935
- case "pptx":
10936
- return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
10937
- case "txt":
10938
- return "text/plain";
10939
- case "html":
10940
- return "text/html";
10941
- case "css":
10942
- return "text/css";
10943
- case "js":
10944
- return "application/javascript";
10945
- case "json":
10946
- return "application/json";
10947
- case "xml":
10948
- return "application/xml";
10949
- default:
10950
- return "application/octet-stream";
10951
- }
10977
+ const ext = getExtFromFileName(fileName).replace(/^\./, "");
10978
+ const matched = Object.entries(mimeExtMap).find(([, extensions]) => extensions.includes(ext));
10979
+ return matched?.[0] || "application/octet-stream";
10980
+ };
10981
+ var generateUniqueFileName = (originalName = "") => {
10982
+ const ext = path2.extname(originalName);
10983
+ const nameWithoutExt = path2.basename(originalName, ext);
10984
+ const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
10985
+ return {
10986
+ finalFileName,
10987
+ ext: ext.toLowerCase()
10988
+ };
10989
+ };
10990
+ var normalizeDataUrlBase64 = (value) => {
10991
+ const matched = value.match(/^data:([^;]+);base64,(.*)$/);
10992
+ return {
10993
+ base64: matched?.[2] || value,
10994
+ mimeType: matched?.[1]
10995
+ };
10996
+ };
10997
+ var parseBase64File = (input) => {
10998
+ const parsed = normalizeDataUrlBase64(input.fileBase64);
10999
+ return {
11000
+ buffer: Buffer.from(parsed.base64, "base64"),
11001
+ mimeType: input.mimeType || parsed.mimeType
11002
+ };
10952
11003
  };
10953
11004
  var replaceContentInFile = async (filePath, targetContent, replacement) => {
10954
11005
  const data = await import_fs_extra.default.readFile(filePath, "utf8");
@@ -10962,8 +11013,8 @@ var replaceContentInFile = async (filePath, targetContent, replacement) => {
10962
11013
  };
10963
11014
  var downloadFile = async (httpUrl, outputPath) => {
10964
11015
  try {
10965
- let parsedUrl = import_url.default.parse(httpUrl);
10966
- let fileName = path2.basename(parsedUrl.pathname);
11016
+ const parsedUrl = import_url.default.parse(httpUrl);
11017
+ const fileName = path2.basename(parsedUrl.pathname);
10967
11018
  if (!outputPath) {
10968
11019
  if (!import_fs_extra.default.existsSync(".tmp")) {
10969
11020
  import_fs_extra.default.mkdirSync(".tmp", { recursive: true });
@@ -10987,15 +11038,6 @@ var downloadFile = async (httpUrl, outputPath) => {
10987
11038
  throw error;
10988
11039
  }
10989
11040
  };
10990
- var generateUniqueFileName = (originalName = "") => {
10991
- const ext = path2.extname(originalName);
10992
- const nameWithoutExt = path2.basename(originalName, ext);
10993
- const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
10994
- return {
10995
- finalFileName,
10996
- ext: ext.toLowerCase()
10997
- };
10998
- };
10999
11041
  var processFile = async (params) => {
11000
11042
  const { file, type } = params;
11001
11043
  let buffer;
package/dist/node.d.ts CHANGED
@@ -7,6 +7,7 @@ export { default as fs } from 'fs-extra';
7
7
  import lodash from 'lodash';
8
8
  export declare const _: lodash.LoDashStatic;
9
9
  export * from './common';
10
+ export * as cors from './node/cors';
10
11
  export * as oss from './node/oss';
11
12
  export * as cron from './node/cron';
12
13
  export * as mail from './node/mail';
package/dist/node.esm.js CHANGED
@@ -10240,6 +10240,12 @@ var replaceByVariables = (prompt, variables) => {
10240
10240
  return variables[p1] ?? match;
10241
10241
  });
10242
10242
  };
10243
+ var getSafeCallbackPath = (value, fallback) => {
10244
+ if (!value || !value.startsWith("/") || value.startsWith("//")) {
10245
+ return fallback;
10246
+ }
10247
+ return value;
10248
+ };
10243
10249
  var getType = (value) => {
10244
10250
  return Object.prototype.toString.call(value).slice(8, -1);
10245
10251
  };
@@ -10553,6 +10559,36 @@ var Timezone;
10553
10559
  Timezone2["EuropeBerlin"] = "Europe/Berlin";
10554
10560
  })(Timezone ||= {});
10555
10561
  var dayjs_default = dayjs;
10562
+ // src/node/cors.ts
10563
+ var exports_cors = {};
10564
+ __export(exports_cors, {
10565
+ createCorsPreflightResponse: () => createCorsPreflightResponse,
10566
+ createCorsHeaders: () => createCorsHeaders,
10567
+ applyCorsHeaders: () => applyCorsHeaders
10568
+ });
10569
+ var DEFAULT_ALLOW_HEADERS = ["Authorization", "Content-Type", "X-TRPC-Source"];
10570
+ var DEFAULT_ALLOW_METHODS = ["GET", "POST", "OPTIONS"];
10571
+ var DEFAULT_MAX_AGE = "86400";
10572
+ var createCorsHeaders = (request, options = {}) => {
10573
+ const origin = request.headers.get("origin") ?? "*";
10574
+ return {
10575
+ "Access-Control-Allow-Headers": (options.allowHeaders ?? DEFAULT_ALLOW_HEADERS).join(", "),
10576
+ "Access-Control-Allow-Methods": (options.allowMethods ?? DEFAULT_ALLOW_METHODS).join(", "),
10577
+ "Access-Control-Allow-Origin": origin,
10578
+ "Access-Control-Max-Age": options.maxAge ?? DEFAULT_MAX_AGE,
10579
+ Vary: "Origin"
10580
+ };
10581
+ };
10582
+ var applyCorsHeaders = (request, response, options) => {
10583
+ Object.entries(createCorsHeaders(request, options)).forEach(([key2, value]) => {
10584
+ response.headers.set(key2, value);
10585
+ });
10586
+ return response;
10587
+ };
10588
+ var createCorsPreflightResponse = (request, options) => new Response(null, {
10589
+ headers: createCorsHeaders(request, options),
10590
+ status: 204
10591
+ });
10556
10592
  // src/node/oss/index.ts
10557
10593
  var exports_oss = {};
10558
10594
  __export(exports_oss, {
@@ -10721,7 +10757,11 @@ var exports_file = {};
10721
10757
  __export(exports_file, {
10722
10758
  replaceContentInFile: () => replaceContentInFile,
10723
10759
  processFile: () => processFile,
10760
+ parseBase64File: () => parseBase64File,
10761
+ normalizeDataUrlBase64: () => normalizeDataUrlBase64,
10724
10762
  getMimeType: () => getMimeType,
10763
+ getExtFromMimeType: () => getExtFromMimeType,
10764
+ getExtFromFileName: () => getExtFromFileName,
10725
10765
  downloadFile: () => downloadFile
10726
10766
  });
10727
10767
  import fs from "fs-extra";
@@ -10729,53 +10769,62 @@ import axios6 from "axios";
10729
10769
  import url2 from "url";
10730
10770
  import * as path2 from "path";
10731
10771
  import crypto2 from "crypto";
10772
+ var mimeExtMap = {
10773
+ "image/png": ["png"],
10774
+ "image/jpeg": ["jpg", "jpeg"],
10775
+ "image/gif": ["gif"],
10776
+ "image/webp": ["webp"],
10777
+ "image/svg+xml": ["svg"],
10778
+ "video/mp4": ["mp4"],
10779
+ "audio/mpeg": ["mp3"],
10780
+ "application/pdf": ["pdf"],
10781
+ "application/msword": ["doc"],
10782
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ["docx"],
10783
+ "application/vnd.ms-excel": ["xls"],
10784
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ["xlsx"],
10785
+ "application/vnd.ms-powerpoint": ["ppt"],
10786
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": ["pptx"],
10787
+ "text/plain": ["txt"],
10788
+ "text/html": ["html"],
10789
+ "text/css": ["css"],
10790
+ "application/javascript": ["js"],
10791
+ "application/json": ["json"],
10792
+ "application/xml": ["xml"]
10793
+ };
10794
+ var getExtFromFileName = (fileName) => {
10795
+ return fileName ? path2.extname(fileName).toLowerCase() : "";
10796
+ };
10797
+ var getExtFromMimeType = (mimeType) => {
10798
+ const ext = mimeType ? mimeExtMap[mimeType]?.[0] : "";
10799
+ return ext ? `.${ext}` : "";
10800
+ };
10732
10801
  var getMimeType = (fileName) => {
10733
- const ext = fileName.split(".").pop()?.toLowerCase();
10734
- switch (ext) {
10735
- case "png":
10736
- return "image/png";
10737
- case "jpg":
10738
- case "jpeg":
10739
- return "image/jpeg";
10740
- case "gif":
10741
- return "image/gif";
10742
- case "webp":
10743
- return "image/webp";
10744
- case "svg":
10745
- return "image/svg+xml";
10746
- case "mp4":
10747
- return "video/mp4";
10748
- case "mp3":
10749
- return "audio/mpeg";
10750
- case "pdf":
10751
- return "application/pdf";
10752
- case "doc":
10753
- return "application/msword";
10754
- case "docx":
10755
- return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
10756
- case "xls":
10757
- return "application/vnd.ms-excel";
10758
- case "xlsx":
10759
- return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
10760
- case "ppt":
10761
- return "application/vnd.ms-powerpoint";
10762
- case "pptx":
10763
- return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
10764
- case "txt":
10765
- return "text/plain";
10766
- case "html":
10767
- return "text/html";
10768
- case "css":
10769
- return "text/css";
10770
- case "js":
10771
- return "application/javascript";
10772
- case "json":
10773
- return "application/json";
10774
- case "xml":
10775
- return "application/xml";
10776
- default:
10777
- return "application/octet-stream";
10778
- }
10802
+ const ext = getExtFromFileName(fileName).replace(/^\./, "");
10803
+ const matched = Object.entries(mimeExtMap).find(([, extensions]) => extensions.includes(ext));
10804
+ return matched?.[0] || "application/octet-stream";
10805
+ };
10806
+ var generateUniqueFileName = (originalName = "") => {
10807
+ const ext = path2.extname(originalName);
10808
+ const nameWithoutExt = path2.basename(originalName, ext);
10809
+ const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
10810
+ return {
10811
+ finalFileName,
10812
+ ext: ext.toLowerCase()
10813
+ };
10814
+ };
10815
+ var normalizeDataUrlBase64 = (value) => {
10816
+ const matched = value.match(/^data:([^;]+);base64,(.*)$/);
10817
+ return {
10818
+ base64: matched?.[2] || value,
10819
+ mimeType: matched?.[1]
10820
+ };
10821
+ };
10822
+ var parseBase64File = (input) => {
10823
+ const parsed = normalizeDataUrlBase64(input.fileBase64);
10824
+ return {
10825
+ buffer: Buffer.from(parsed.base64, "base64"),
10826
+ mimeType: input.mimeType || parsed.mimeType
10827
+ };
10779
10828
  };
10780
10829
  var replaceContentInFile = async (filePath, targetContent, replacement) => {
10781
10830
  const data = await fs.readFile(filePath, "utf8");
@@ -10789,8 +10838,8 @@ var replaceContentInFile = async (filePath, targetContent, replacement) => {
10789
10838
  };
10790
10839
  var downloadFile = async (httpUrl, outputPath) => {
10791
10840
  try {
10792
- let parsedUrl = url2.parse(httpUrl);
10793
- let fileName = path2.basename(parsedUrl.pathname);
10841
+ const parsedUrl = url2.parse(httpUrl);
10842
+ const fileName = path2.basename(parsedUrl.pathname);
10794
10843
  if (!outputPath) {
10795
10844
  if (!fs.existsSync(".tmp")) {
10796
10845
  fs.mkdirSync(".tmp", { recursive: true });
@@ -10814,15 +10863,6 @@ var downloadFile = async (httpUrl, outputPath) => {
10814
10863
  throw error;
10815
10864
  }
10816
10865
  };
10817
- var generateUniqueFileName = (originalName = "") => {
10818
- const ext = path2.extname(originalName);
10819
- const nameWithoutExt = path2.basename(originalName, ext);
10820
- const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
10821
- return {
10822
- finalFileName,
10823
- ext: ext.toLowerCase()
10824
- };
10825
- };
10826
10866
  var processFile = async (params) => {
10827
10867
  const { file, type } = params;
10828
10868
  let buffer;
@@ -11974,6 +12014,7 @@ export {
11974
12014
  getType,
11975
12015
  getStrLength,
11976
12016
  getSliceStr,
12017
+ getSafeCallbackPath,
11977
12018
  getRandomString,
11978
12019
  getRandomColor,
11979
12020
  getPublicUrl,
@@ -11999,6 +12040,7 @@ export {
11999
12040
  custom,
12000
12041
  exports_cron as cron,
12001
12042
  exports_crawl as crawl,
12043
+ exports_cors as cors,
12002
12044
  default4 as consola,
12003
12045
  coerce,
12004
12046
  cheerio,
package/dist/web.cjs.js CHANGED
@@ -10861,6 +10861,7 @@ __export(exports_web, {
10861
10861
  getType: () => getType,
10862
10862
  getStrLength: () => getStrLength,
10863
10863
  getSliceStr: () => getSliceStr,
10864
+ getSafeCallbackPath: () => getSafeCallbackPath,
10864
10865
  getRandomString: () => getRandomString,
10865
10866
  getRandomColor: () => getRandomColor,
10866
10867
  getPublicUrl: () => getPublicUrl,
@@ -20350,6 +20351,12 @@ var replaceByVariables = (prompt, variables) => {
20350
20351
  return variables[p1] ?? match;
20351
20352
  });
20352
20353
  };
20354
+ var getSafeCallbackPath = (value, fallback) => {
20355
+ if (!value || !value.startsWith("/") || value.startsWith("//")) {
20356
+ return fallback;
20357
+ }
20358
+ return value;
20359
+ };
20353
20360
  var getType = (value) => {
20354
20361
  return Object.prototype.toString.call(value).slice(8, -1);
20355
20362
  };
package/dist/web.esm.js CHANGED
@@ -20181,6 +20181,12 @@ var replaceByVariables = (prompt, variables) => {
20181
20181
  return variables[p1] ?? match;
20182
20182
  });
20183
20183
  };
20184
+ var getSafeCallbackPath = (value, fallback) => {
20185
+ if (!value || !value.startsWith("/") || value.startsWith("//")) {
20186
+ return fallback;
20187
+ }
20188
+ return value;
20189
+ };
20184
20190
  var getType = (value) => {
20185
20191
  return Object.prototype.toString.call(value).slice(8, -1);
20186
20192
  };
@@ -20620,6 +20626,7 @@ export {
20620
20626
  getType,
20621
20627
  getStrLength,
20622
20628
  getSliceStr,
20629
+ getSafeCallbackPath,
20623
20630
  getRandomString,
20624
20631
  getRandomColor,
20625
20632
  getPublicUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/utils",
3
- "version": "0.3.32",
3
+ "version": "0.3.36",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "sideEffects": false,
@@ -9,7 +9,8 @@
9
9
  "build-web-cjs": "bun build ./src/web.ts --outfile dist/web.cjs.js --format cjs",
10
10
  "build-node-esm": "bun build ./src/node.ts --outfile dist/node.esm.js --format esm --target node --external nodemailer --external fs-extra --external axios --external node:* --external ali-oss --external nedb --external cheerio --external json5 --external consola --external dayjs --external node-cron --external @aws-sdk/client-s3",
11
11
  "build-node-cjs": "bun build ./src/node.ts --outfile dist/node.cjs.js --format cjs --target node --external nodemailer --external fs-extra --external axios --external node:* --external ali-oss --external nedb --external cheerio --external json5 --external consola --external dayjs --external node-cron --external @aws-sdk/client-s3",
12
- "build": "rm -rf dist && bun run build-web-esm && bun run build-web-cjs && bun run build-node-esm && bun run build-node-cjs && tsc"
12
+ "build": "rm -rf dist && bun run build-web-esm && bun run build-web-cjs && bun run build-node-esm && bun run build-node-cjs && tsc",
13
+ "typecheck": "tsc --noEmit"
13
14
  },
14
15
  "files": [
15
16
  "dist"
@@ -71,7 +72,7 @@
71
72
  "@types/nodemailer": "^6.4.7",
72
73
  "@types/papaparse": "^5.3.15"
73
74
  },
74
- "gitHead": "260d8290106ef447ec42375d4656af2e89675b15",
75
+ "gitHead": "7db0faf741993d729a9e1c0742f480f364816222",
75
76
  "publishConfig": {
76
77
  "access": "public"
77
78
  }