@wzyjs/utils 0.3.22 → 0.3.24
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.
- package/dist/common/base/number.d.ts +1 -1
- package/dist/common/index.d.ts +1 -0
- package/dist/common/other/index.d.ts +6 -0
- package/dist/node/oss/cloudflare.d.ts +0 -6
- package/dist/node.cjs.js +23 -22
- package/dist/node.esm.js +23 -22
- package/dist/web.cjs.js +14538 -11696
- package/dist/web.d.ts +2 -1
- package/dist/web.esm.js +14379 -11523
- package/package.json +2 -2
|
@@ -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
|
|
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;
|
package/dist/common/index.d.ts
CHANGED
|
@@ -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,
|
|
@@ -38728,14 +38729,14 @@ var limitDecimals = (v, num = 2, isForce) => {
|
|
|
38728
38729
|
}
|
|
38729
38730
|
return value.toFixed(num).toString();
|
|
38730
38731
|
};
|
|
38731
|
-
var
|
|
38732
|
-
|
|
38733
|
-
|
|
38734
|
-
|
|
38735
|
-
|
|
38736
|
-
|
|
38737
|
-
|
|
38738
|
-
return `${(
|
|
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
|
@@ -37825,14 +37825,14 @@ var limitDecimals = (v, num = 2, isForce) => {
|
|
|
37825
37825
|
}
|
|
37826
37826
|
return value.toFixed(num).toString();
|
|
37827
37827
|
};
|
|
37828
|
-
var
|
|
37829
|
-
|
|
37830
|
-
|
|
37831
|
-
|
|
37832
|
-
|
|
37833
|
-
|
|
37834
|
-
|
|
37835
|
-
return `${(
|
|
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,
|