@wzyjs/utils 0.3.23 → 0.3.25

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,5 @@
1
1
  export declare const getRandomNum: (min: number, max: number) => number;
2
2
  export declare const limitDecimals: (v: string, num: number, isForce: boolean) => string;
3
- export declare const getFileSize: (size: number) => string;
3
+ export declare const formatFileSize: (bytes?: number) => string;
4
4
  export declare const isValidNumber: (value: any) => boolean;
5
5
  export declare const numberWithCommas: (x?: number | string) => string;
@@ -2,4 +2,5 @@ export * as ai from './ai';
2
2
  export * from './base';
3
3
  export * from './enum';
4
4
  export * from './image';
5
+ export * from './other';
5
6
  export { default as dayjs, type Dayjs, Timezone, initChinaDayjs, chinaDayjs } from './dayjs';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 拼接 Cloudflare R2 文件的公开访问 URL
3
+ * @param objectKey - 文件在 R2 中的 Key
4
+ * @returns 文件的完整访问 URL
5
+ */
6
+ export declare function getPublicUrl(objectKey: string): string;
@@ -11,12 +11,6 @@ interface UploadFile {
11
11
  export declare function uploadFile(params: UploadFile): Promise<{
12
12
  objectKey: string;
13
13
  }>;
14
- /**
15
- * 拼接 Cloudflare R2 文件的公开访问 URL
16
- * @param objectKey - 文件在 R2 中的 Key
17
- * @returns 文件的完整访问 URL
18
- */
19
- export declare function getPublicUrl(objectKey: string): string;
20
14
  /**
21
15
  * 从 Cloudflare R2 删除文件
22
16
  * @param objectKey - 文件在 S3 中的 Key
package/dist/node.cjs.js CHANGED
@@ -31554,10 +31554,10 @@ __export(exports_node, {
31554
31554
  getRandomString: () => getRandomString,
31555
31555
  getRandomNum: () => getRandomNum,
31556
31556
  getRandomColor: () => getRandomColor,
31557
+ getPublicUrl: () => getPublicUrl,
31557
31558
  getProxyUrl: () => getProxyUrl,
31558
31559
  getParsedType: () => getParsedType,
31559
31560
  getLength: () => getLength,
31560
- getFileSize: () => getFileSize,
31561
31561
  getErrorMap: () => getErrorMap,
31562
31562
  getCookie: () => getCookie,
31563
31563
  getChineseByStr: () => getChineseByStr,
@@ -31565,6 +31565,7 @@ __export(exports_node, {
31565
31565
  generateUniqueFileName: () => generateUniqueFileName,
31566
31566
  generateAlphabetArray: () => generateAlphabetArray,
31567
31567
  function: () => functionType,
31568
+ formatFileSize: () => formatFileSize,
31568
31569
  findItem: () => findItem,
31569
31570
  filterParams: () => filterParams,
31570
31571
  file: () => exports_file,
@@ -35646,7 +35647,7 @@ __export(exports_302, {
35646
35647
 
35647
35648
  // src/common/ai/302/axios.ts
35648
35649
  var import_axios = __toESM(require("axios"));
35649
- var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
35650
+ var key = process.env.AI_302_KEY;
35650
35651
  var axios = import_axios.default.create({
35651
35652
  baseURL: "https://api.302.ai",
35652
35653
  headers: {
@@ -38728,14 +38729,14 @@ var limitDecimals = (v, num = 2, isForce) => {
38728
38729
  }
38729
38730
  return value.toFixed(num).toString();
38730
38731
  };
38731
- var getFileSize = (size) => {
38732
- let d = "G";
38733
- let s = size / 1024 / 1024 / 1024;
38734
- if (s < 1) {
38735
- d = "M";
38736
- s *= 1024;
38737
- }
38738
- return `${(s.toFixed(1) / 1).toString()}${d}`;
38732
+ var formatFileSize = (bytes) => {
38733
+ if (!bytes || bytes === 0) {
38734
+ return "0 B";
38735
+ }
38736
+ const base = 1024;
38737
+ const sizes = ["B", "KB", "MB", "GB"];
38738
+ const index = Math.floor(Math.log(bytes) / Math.log(base));
38739
+ return `${(bytes / Math.pow(base, index)).toFixed(1).replace(/\.0$/, "")} ${sizes[index]}`;
38739
38740
  };
38740
38741
  var isValidNumber = (value) => {
38741
38742
  if (typeof value !== "number") {
@@ -38887,6 +38888,19 @@ async function imageToBase64(url2) {
38887
38888
  throw error;
38888
38889
  }
38889
38890
  }
38891
+ // src/common/other/index.ts
38892
+ function getPublicUrl(objectKey) {
38893
+ if (!objectKey) {
38894
+ return "";
38895
+ }
38896
+ const publicUrl = process.env.CLOUDFLARE_PUBLIC_URL || process.env.NEXT_PUBLIC_CLOUDFLARE_PUBLIC_URL;
38897
+ if (!publicUrl) {
38898
+ throw new Error("CLOUDFLARE_PUBLIC_URL environment variable is not set");
38899
+ }
38900
+ const baseUrl = publicUrl.endsWith("/") ? publicUrl.slice(0, -1) : publicUrl;
38901
+ const key2 = objectKey.startsWith("/") ? objectKey : `/${objectKey}`;
38902
+ return `${baseUrl}${key2}`;
38903
+ }
38890
38904
  // src/common/dayjs/index.ts
38891
38905
  var import_dayjs = __toESM(require("dayjs"));
38892
38906
  var import_isBetween = __toESM(require("dayjs/plugin/isBetween"));
@@ -38978,7 +38992,6 @@ var uploadFileToOss = async (params) => {
38978
38992
  var exports_cloudflare = {};
38979
38993
  __export(exports_cloudflare, {
38980
38994
  uploadFile: () => uploadFile,
38981
- getPublicUrl: () => getPublicUrl,
38982
38995
  deleteFile: () => deleteFile
38983
38996
  });
38984
38997
  var import_client_s3 = require("@aws-sdk/client-s3");
@@ -39033,18 +39046,6 @@ async function uploadFile(params) {
39033
39046
  throw new Error(`上传到 Cloudflare 失败: ${error}`);
39034
39047
  }
39035
39048
  }
39036
- function getPublicUrl(objectKey) {
39037
- if (!objectKey) {
39038
- return "";
39039
- }
39040
- const publicUrl = process.env.CLOUDFLARE_PUBLIC_URL;
39041
- if (!publicUrl) {
39042
- throw new Error("CLOUDFLARE_PUBLIC_URL environment variable is not set");
39043
- }
39044
- const baseUrl = publicUrl.endsWith("/") ? publicUrl.slice(0, -1) : publicUrl;
39045
- const key2 = objectKey.startsWith("/") ? objectKey : `/${objectKey}`;
39046
- return `${baseUrl}${key2}`;
39047
- }
39048
39049
  async function deleteFile(objectKey) {
39049
39050
  const client = getS3Client();
39050
39051
  try {
package/dist/node.esm.js CHANGED
@@ -34743,7 +34743,7 @@ __export(exports_302, {
34743
34743
 
34744
34744
  // src/common/ai/302/axios.ts
34745
34745
  import axios_ from "axios";
34746
- var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
34746
+ var key = process.env.AI_302_KEY;
34747
34747
  var axios = axios_.create({
34748
34748
  baseURL: "https://api.302.ai",
34749
34749
  headers: {
@@ -37825,14 +37825,14 @@ var limitDecimals = (v, num = 2, isForce) => {
37825
37825
  }
37826
37826
  return value.toFixed(num).toString();
37827
37827
  };
37828
- var getFileSize = (size) => {
37829
- let d = "G";
37830
- let s = size / 1024 / 1024 / 1024;
37831
- if (s < 1) {
37832
- d = "M";
37833
- s *= 1024;
37834
- }
37835
- return `${(s.toFixed(1) / 1).toString()}${d}`;
37828
+ var formatFileSize = (bytes) => {
37829
+ if (!bytes || bytes === 0) {
37830
+ return "0 B";
37831
+ }
37832
+ const base = 1024;
37833
+ const sizes = ["B", "KB", "MB", "GB"];
37834
+ const index = Math.floor(Math.log(bytes) / Math.log(base));
37835
+ return `${(bytes / Math.pow(base, index)).toFixed(1).replace(/\.0$/, "")} ${sizes[index]}`;
37836
37836
  };
37837
37837
  var isValidNumber = (value) => {
37838
37838
  if (typeof value !== "number") {
@@ -37984,6 +37984,19 @@ async function imageToBase64(url2) {
37984
37984
  throw error;
37985
37985
  }
37986
37986
  }
37987
+ // src/common/other/index.ts
37988
+ function getPublicUrl(objectKey) {
37989
+ if (!objectKey) {
37990
+ return "";
37991
+ }
37992
+ const publicUrl = process.env.CLOUDFLARE_PUBLIC_URL || process.env.NEXT_PUBLIC_CLOUDFLARE_PUBLIC_URL;
37993
+ if (!publicUrl) {
37994
+ throw new Error("CLOUDFLARE_PUBLIC_URL environment variable is not set");
37995
+ }
37996
+ const baseUrl = publicUrl.endsWith("/") ? publicUrl.slice(0, -1) : publicUrl;
37997
+ const key2 = objectKey.startsWith("/") ? objectKey : `/${objectKey}`;
37998
+ return `${baseUrl}${key2}`;
37999
+ }
37987
38000
  // src/common/dayjs/index.ts
37988
38001
  import dayjs from "dayjs";
37989
38002
  import isBetween from "dayjs/plugin/isBetween";
@@ -38075,7 +38088,6 @@ var uploadFileToOss = async (params) => {
38075
38088
  var exports_cloudflare = {};
38076
38089
  __export(exports_cloudflare, {
38077
38090
  uploadFile: () => uploadFile,
38078
- getPublicUrl: () => getPublicUrl,
38079
38091
  deleteFile: () => deleteFile
38080
38092
  });
38081
38093
  import { S3Client, PutObjectCommand, DeleteObjectCommand } from "@aws-sdk/client-s3";
@@ -38803,18 +38815,6 @@ async function uploadFile(params) {
38803
38815
  throw new Error(`上传到 Cloudflare 失败: ${error}`);
38804
38816
  }
38805
38817
  }
38806
- function getPublicUrl(objectKey) {
38807
- if (!objectKey) {
38808
- return "";
38809
- }
38810
- const publicUrl = process.env.CLOUDFLARE_PUBLIC_URL;
38811
- if (!publicUrl) {
38812
- throw new Error("CLOUDFLARE_PUBLIC_URL environment variable is not set");
38813
- }
38814
- const baseUrl = publicUrl.endsWith("/") ? publicUrl.slice(0, -1) : publicUrl;
38815
- const key2 = objectKey.startsWith("/") ? objectKey : `/${objectKey}`;
38816
- return `${baseUrl}${key2}`;
38817
- }
38818
38818
  async function deleteFile(objectKey) {
38819
38819
  const client = getS3Client();
38820
38820
  try {
@@ -39133,10 +39133,10 @@ export {
39133
39133
  getRandomString,
39134
39134
  getRandomNum,
39135
39135
  getRandomColor,
39136
+ getPublicUrl,
39136
39137
  getProxyUrl,
39137
39138
  getParsedType,
39138
39139
  getLength,
39139
- getFileSize,
39140
39140
  getErrorMap,
39141
39141
  getCookie,
39142
39142
  getChineseByStr,
@@ -39144,6 +39144,7 @@ export {
39144
39144
  generateUniqueFileName,
39145
39145
  generateAlphabetArray,
39146
39146
  functionType as function,
39147
+ formatFileSize,
39147
39148
  findItem,
39148
39149
  filterParams,
39149
39150
  exports_file as file,
package/dist/web.cjs.js CHANGED
@@ -10400,10 +10400,10 @@ __export(exports_web, {
10400
10400
  getRandomString: () => getRandomString,
10401
10401
  getRandomNum: () => getRandomNum,
10402
10402
  getRandomColor: () => getRandomColor,
10403
+ getPublicUrl: () => getPublicUrl,
10403
10404
  getProxyUrl: () => getProxyUrl,
10404
10405
  getParsedType: () => getParsedType,
10405
10406
  getLength: () => getLength,
10406
- getFileSize: () => getFileSize,
10407
10407
  getErrorMap: () => getErrorMap,
10408
10408
  getElement: () => getElement,
10409
10409
  getCookie: () => getCookie,
@@ -10412,6 +10412,7 @@ __export(exports_web, {
10412
10412
  generateUniqueFileName: () => generateUniqueFileName,
10413
10413
  generateAlphabetArray: () => generateAlphabetArray,
10414
10414
  function: () => functionType,
10415
+ formatFileSize: () => formatFileSize,
10415
10416
  flashBorder: () => flashBorder,
10416
10417
  flashBackground: () => flashBackground,
10417
10418
  findItem: () => findItem,
@@ -18316,7 +18317,7 @@ __export(exports_302, {
18316
18317
  });
18317
18318
 
18318
18319
  // src/common/ai/302/axios.ts
18319
- var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
18320
+ var key = process.env.AI_302_KEY;
18320
18321
  var axios2 = axios_default.create({
18321
18322
  baseURL: "https://api.302.ai",
18322
18323
  headers: {
@@ -22053,14 +22054,14 @@ var limitDecimals = (v, num = 2, isForce) => {
22053
22054
  }
22054
22055
  return value.toFixed(num).toString();
22055
22056
  };
22056
- var getFileSize = (size) => {
22057
- let d = "G";
22058
- let s = size / 1024 / 1024 / 1024;
22059
- if (s < 1) {
22060
- d = "M";
22061
- s *= 1024;
22062
- }
22063
- return `${(s.toFixed(1) / 1).toString()}${d}`;
22057
+ var formatFileSize = (bytes) => {
22058
+ if (!bytes || bytes === 0) {
22059
+ return "0 B";
22060
+ }
22061
+ const base = 1024;
22062
+ const sizes = ["B", "KB", "MB", "GB"];
22063
+ const index = Math.floor(Math.log(bytes) / Math.log(base));
22064
+ return `${(bytes / Math.pow(base, index)).toFixed(1).replace(/\.0$/, "")} ${sizes[index]}`;
22064
22065
  };
22065
22066
  var isValidNumber = (value) => {
22066
22067
  if (typeof value !== "number") {
@@ -22211,6 +22212,19 @@ async function imageToBase64(url) {
22211
22212
  throw error;
22212
22213
  }
22213
22214
  }
22215
+ // src/common/other/index.ts
22216
+ function getPublicUrl(objectKey) {
22217
+ if (!objectKey) {
22218
+ return "";
22219
+ }
22220
+ const publicUrl = process.env.CLOUDFLARE_PUBLIC_URL || process.env.NEXT_PUBLIC_CLOUDFLARE_PUBLIC_URL;
22221
+ if (!publicUrl) {
22222
+ throw new Error("CLOUDFLARE_PUBLIC_URL environment variable is not set");
22223
+ }
22224
+ const baseUrl = publicUrl.endsWith("/") ? publicUrl.slice(0, -1) : publicUrl;
22225
+ const key2 = objectKey.startsWith("/") ? objectKey : `/${objectKey}`;
22226
+ return `${baseUrl}${key2}`;
22227
+ }
22214
22228
  // src/common/dayjs/index.ts
22215
22229
  var import_dayjs = __toESM(require_dayjs_min(), 1);
22216
22230
  var import_isBetween = __toESM(require_isBetween(), 1);
package/dist/web.esm.js CHANGED
@@ -18126,7 +18126,7 @@ __export(exports_302, {
18126
18126
  });
18127
18127
 
18128
18128
  // src/common/ai/302/axios.ts
18129
- var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
18129
+ var key = process.env.AI_302_KEY;
18130
18130
  var axios2 = axios_default.create({
18131
18131
  baseURL: "https://api.302.ai",
18132
18132
  headers: {
@@ -21863,14 +21863,14 @@ var limitDecimals = (v, num = 2, isForce) => {
21863
21863
  }
21864
21864
  return value.toFixed(num).toString();
21865
21865
  };
21866
- var getFileSize = (size) => {
21867
- let d = "G";
21868
- let s = size / 1024 / 1024 / 1024;
21869
- if (s < 1) {
21870
- d = "M";
21871
- s *= 1024;
21872
- }
21873
- return `${(s.toFixed(1) / 1).toString()}${d}`;
21866
+ var formatFileSize = (bytes) => {
21867
+ if (!bytes || bytes === 0) {
21868
+ return "0 B";
21869
+ }
21870
+ const base = 1024;
21871
+ const sizes = ["B", "KB", "MB", "GB"];
21872
+ const index = Math.floor(Math.log(bytes) / Math.log(base));
21873
+ return `${(bytes / Math.pow(base, index)).toFixed(1).replace(/\.0$/, "")} ${sizes[index]}`;
21874
21874
  };
21875
21875
  var isValidNumber = (value) => {
21876
21876
  if (typeof value !== "number") {
@@ -22021,6 +22021,19 @@ async function imageToBase64(url) {
22021
22021
  throw error;
22022
22022
  }
22023
22023
  }
22024
+ // src/common/other/index.ts
22025
+ function getPublicUrl(objectKey) {
22026
+ if (!objectKey) {
22027
+ return "";
22028
+ }
22029
+ const publicUrl = process.env.CLOUDFLARE_PUBLIC_URL || process.env.NEXT_PUBLIC_CLOUDFLARE_PUBLIC_URL;
22030
+ if (!publicUrl) {
22031
+ throw new Error("CLOUDFLARE_PUBLIC_URL environment variable is not set");
22032
+ }
22033
+ const baseUrl = publicUrl.endsWith("/") ? publicUrl.slice(0, -1) : publicUrl;
22034
+ const key2 = objectKey.startsWith("/") ? objectKey : `/${objectKey}`;
22035
+ return `${baseUrl}${key2}`;
22036
+ }
22024
22037
  // src/common/dayjs/index.ts
22025
22038
  var import_dayjs = __toESM(require_dayjs_min(), 1);
22026
22039
  var import_isBetween = __toESM(require_isBetween(), 1);
@@ -22268,10 +22281,10 @@ export {
22268
22281
  getRandomString,
22269
22282
  getRandomNum,
22270
22283
  getRandomColor,
22284
+ getPublicUrl,
22271
22285
  getProxyUrl,
22272
22286
  getParsedType,
22273
22287
  getLength,
22274
- getFileSize,
22275
22288
  getErrorMap,
22276
22289
  getElement,
22277
22290
  getCookie,
@@ -22280,6 +22293,7 @@ export {
22280
22293
  generateUniqueFileName,
22281
22294
  generateAlphabetArray,
22282
22295
  functionType as function,
22296
+ formatFileSize,
22283
22297
  flashBorder,
22284
22298
  flashBackground,
22285
22299
  findItem,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/utils",
3
- "version": "0.3.23",
3
+ "version": "0.3.25",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "sideEffects": false,
@@ -70,7 +70,7 @@
70
70
  "@types/nodemailer": "^6.4.7",
71
71
  "@types/papaparse": "^5.3.15"
72
72
  },
73
- "gitHead": "7fdb40c0c0b5fcccd0166722cd81e77df55885fb",
73
+ "gitHead": "ccab22c313d0a8023b98f9711f65c5ed59d886a8",
74
74
  "publishConfig": {
75
75
  "access": "public"
76
76
  }