ly-utils-lib 1.0.12 → 2.4.0
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/LICENSE +21 -0
- package/README.md +889 -686
- package/dist/array.cjs +237 -0
- package/dist/array.cjs.map +1 -0
- package/dist/array.d.cts +2 -0
- package/dist/array.d.ts +2 -0
- package/dist/array.js +150 -0
- package/dist/array.js.map +1 -0
- package/dist/crypto.cjs +193 -0
- package/dist/crypto.cjs.map +1 -0
- package/dist/crypto.d.cts +3 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +144 -0
- package/dist/crypto.js.map +1 -0
- package/dist/date.cjs +563 -0
- package/dist/date.cjs.map +1 -0
- package/dist/date.d.cts +2 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +451 -0
- package/dist/date.js.map +1 -0
- package/dist/excel.cjs +227 -0
- package/dist/excel.cjs.map +1 -0
- package/dist/excel.d.cts +2 -0
- package/dist/excel.d.ts +2 -0
- package/dist/excel.js +196 -0
- package/dist/excel.js.map +1 -0
- package/dist/index-B80SEVzM.d.cts +382 -0
- package/dist/index-B80SEVzM.d.ts +382 -0
- package/dist/index-Ba1rjTzj.d.cts +299 -0
- package/dist/index-Ba1rjTzj.d.ts +299 -0
- package/dist/index-Bg1ise7y.d.cts +253 -0
- package/dist/index-Bg1ise7y.d.ts +253 -0
- package/dist/index-BoqNpwNa.d.cts +203 -0
- package/dist/index-BoqNpwNa.d.ts +203 -0
- package/dist/index-C0qUnb9Y.d.cts +533 -0
- package/dist/index-C0qUnb9Y.d.ts +533 -0
- package/dist/index-Cy-mb5v_.d.cts +262 -0
- package/dist/index-Cy-mb5v_.d.ts +262 -0
- package/dist/index-D1f9Sym2.d.cts +148 -0
- package/dist/index-D1f9Sym2.d.ts +148 -0
- package/dist/index-Dan5oF-5.d.cts +213 -0
- package/dist/index-Dan5oF-5.d.ts +213 -0
- package/dist/index-XABfrs7z.d.cts +596 -0
- package/dist/index-XABfrs7z.d.ts +596 -0
- package/dist/index-YXWfKCK7.d.cts +109 -0
- package/dist/index-YXWfKCK7.d.ts +109 -0
- package/dist/index.cjs +3355 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +3294 -0
- package/dist/index.js.map +1 -0
- package/dist/map.cjs +839 -0
- package/dist/map.cjs.map +1 -0
- package/dist/map.d.cts +6 -0
- package/dist/map.d.ts +6 -0
- package/dist/map.js +811 -0
- package/dist/map.js.map +1 -0
- package/dist/object.cjs +316 -0
- package/dist/object.cjs.map +1 -0
- package/dist/object.d.cts +2 -0
- package/dist/object.d.ts +2 -0
- package/dist/object.js +247 -0
- package/dist/object.js.map +1 -0
- package/dist/pdf.cjs +197 -0
- package/dist/pdf.cjs.map +1 -0
- package/dist/pdf.d.cts +3 -0
- package/dist/pdf.d.ts +3 -0
- package/dist/pdf.js +173 -0
- package/dist/pdf.js.map +1 -0
- package/dist/storage.cjs +255 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +1 -0
- package/dist/storage.d.ts +1 -0
- package/dist/storage.js +226 -0
- package/dist/storage.js.map +1 -0
- package/dist/string.cjs +232 -0
- package/dist/string.cjs.map +1 -0
- package/dist/string.d.cts +2 -0
- package/dist/string.d.ts +2 -0
- package/dist/string.js +170 -0
- package/dist/string.js.map +1 -0
- package/dist/utils.cjs +429 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +2 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +371 -0
- package/dist/utils.js.map +1 -0
- package/package.json +159 -33
- package/dist/ly-utils-lib.cjs.js +0 -115
- package/dist/ly-utils-lib.cjs.js.map +0 -1
- package/dist/ly-utils-lib.es.js +0 -58589
- package/dist/ly-utils-lib.es.js.map +0 -1
- package/dist/ly-utils-lib.umd.js +0 -115
- package/dist/ly-utils-lib.umd.js.map +0 -1
- package/dist/types/index.d.ts +0 -15
- package/dist/types/utils/esToolkit.d.ts +0 -2
- package/dist/types/utils/ol.d.ts +0 -175
- package/dist/types/utils/router.d.ts +0 -10
- package/dist/types/utils/storage.d.ts +0 -42
- package/dist/types/utils/time.d.ts +0 -66
- package/dist/types/utils/tool.d.ts +0 -80
- package/dist/vite.svg +0 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import html2canvas, { Options } from 'html2canvas';
|
|
2
|
+
import { jsPDF } from 'jspdf';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* PDF 工具模块
|
|
6
|
+
* 基于 html2canvas 和 jspdf 封装,提供常用的 PDF 处理功能
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface CaptureToPDFOptions {
|
|
10
|
+
filename?: string;
|
|
11
|
+
scale?: number;
|
|
12
|
+
useCORS?: boolean;
|
|
13
|
+
backgroundColor?: string;
|
|
14
|
+
logging?: boolean;
|
|
15
|
+
pagebreak?: {
|
|
16
|
+
mode?: string;
|
|
17
|
+
before?: string;
|
|
18
|
+
after?: string;
|
|
19
|
+
};
|
|
20
|
+
margin?: number;
|
|
21
|
+
}
|
|
22
|
+
interface PDFOptions {
|
|
23
|
+
orientation?: 'p' | 'portrait' | 'l' | 'landscape';
|
|
24
|
+
unit?: 'pt' | 'mm' | 'cm' | 'in';
|
|
25
|
+
format?: 'a0' | 'a1' | 'a2' | 'a3' | 'a4' | 'legal' | 'letter' | [number, number];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 将 DOM 元素转换为 PDF
|
|
29
|
+
* @param element DOM 元素
|
|
30
|
+
* @param options 选项
|
|
31
|
+
*/
|
|
32
|
+
declare const captureToPDF: (element: HTMLElement, options?: CaptureToPDFOptions) => Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* 将 DOM 元素转换为 PDF(分页)
|
|
35
|
+
* @param element DOM 元素
|
|
36
|
+
* @param options 选项
|
|
37
|
+
*/
|
|
38
|
+
declare const captureToPDFWithPagination: (element: HTMLElement, options?: CaptureToPDFOptions) => Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* 截取 DOM 元素为图片
|
|
41
|
+
* @param element DOM 元素
|
|
42
|
+
* @param options html2canvas 选项
|
|
43
|
+
*/
|
|
44
|
+
declare const captureToImage: (element: HTMLElement, options?: Partial<Options>) => Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* 截取 DOM 元素并下载为图片
|
|
47
|
+
* @param element DOM 元素
|
|
48
|
+
* @param filename 文件名
|
|
49
|
+
* @param options html2canvas 选项
|
|
50
|
+
*/
|
|
51
|
+
declare const captureToImageDownload: (element: HTMLElement, filename?: string, options?: Partial<Options>) => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* 创建空白 PDF
|
|
54
|
+
* @param options PDF 选项
|
|
55
|
+
*/
|
|
56
|
+
declare const createPDF: (options?: PDFOptions) => jsPDF;
|
|
57
|
+
/**
|
|
58
|
+
* 添加文本到 PDF
|
|
59
|
+
* @param pdf PDF 实例
|
|
60
|
+
* @param text 文本
|
|
61
|
+
* @param x X 坐标
|
|
62
|
+
* @param y Y 坐标
|
|
63
|
+
* @param options 选项
|
|
64
|
+
*/
|
|
65
|
+
declare const addTextToPDF: (pdf: jsPDF, text: string, x: number, y: number, options?: {
|
|
66
|
+
maxWidth?: number;
|
|
67
|
+
align?: "left" | "center" | "right";
|
|
68
|
+
fontSize?: number;
|
|
69
|
+
fontStyle?: "normal" | "bold" | "italic" | "bolditalic";
|
|
70
|
+
}) => void;
|
|
71
|
+
/**
|
|
72
|
+
* 添加图片到 PDF
|
|
73
|
+
* @param pdf PDF 实例
|
|
74
|
+
* @param imageData 图片数据(DataURL 或 URL)
|
|
75
|
+
* @param x X 坐标
|
|
76
|
+
* @param y Y 坐标
|
|
77
|
+
* @param width 宽度
|
|
78
|
+
* @param height 高度
|
|
79
|
+
*/
|
|
80
|
+
declare const addImageToPDF: (pdf: jsPDF, imageData: string, x: number, y: number, width: number, height: number) => void;
|
|
81
|
+
/**
|
|
82
|
+
* 添加表格到 PDF
|
|
83
|
+
* @param pdf PDF 实例
|
|
84
|
+
* @param headers 表头
|
|
85
|
+
* @param data 数据
|
|
86
|
+
* @param options 选项
|
|
87
|
+
*/
|
|
88
|
+
declare const addTableToPDF: (pdf: jsPDF, headers: string[], data: string[][], options?: {
|
|
89
|
+
x?: number;
|
|
90
|
+
y?: number;
|
|
91
|
+
cellWidth?: number;
|
|
92
|
+
cellHeight?: number;
|
|
93
|
+
headerBackgroundColor?: string;
|
|
94
|
+
headerTextColor?: string;
|
|
95
|
+
textColor?: string;
|
|
96
|
+
fontSize?: number;
|
|
97
|
+
lineWidth?: number;
|
|
98
|
+
lineColor?: number[];
|
|
99
|
+
}) => void;
|
|
100
|
+
/**
|
|
101
|
+
* 添加新页面
|
|
102
|
+
* @param pdf PDF 实例
|
|
103
|
+
*/
|
|
104
|
+
declare const addPage: (pdf: jsPDF) => void;
|
|
105
|
+
/**
|
|
106
|
+
* 保存 PDF
|
|
107
|
+
* @param pdf PDF 实例
|
|
108
|
+
* @param filename 文件名
|
|
109
|
+
*/
|
|
110
|
+
declare const savePDF: (pdf: jsPDF, filename?: string) => void;
|
|
111
|
+
/**
|
|
112
|
+
* PDF 转 DataURL
|
|
113
|
+
* @param pdf PDF 实例
|
|
114
|
+
*/
|
|
115
|
+
declare const pdfToDataURL: (pdf: jsPDF) => string;
|
|
116
|
+
/**
|
|
117
|
+
* PDF 转 Blob
|
|
118
|
+
* @param pdf PDF 实例
|
|
119
|
+
*/
|
|
120
|
+
declare const pdfToBlob: (pdf: jsPDF) => Blob;
|
|
121
|
+
/**
|
|
122
|
+
* 合并多个 PDF(需要使用 pdf-lib 库实现)
|
|
123
|
+
* @param _pdfs PDF 实例数组
|
|
124
|
+
*/
|
|
125
|
+
declare const mergePDFs: (_pdfs: jsPDF[]) => Promise<jsPDF>;
|
|
126
|
+
|
|
127
|
+
type index_CaptureToPDFOptions = CaptureToPDFOptions;
|
|
128
|
+
type index_PDFOptions = PDFOptions;
|
|
129
|
+
declare const index_addImageToPDF: typeof addImageToPDF;
|
|
130
|
+
declare const index_addPage: typeof addPage;
|
|
131
|
+
declare const index_addTableToPDF: typeof addTableToPDF;
|
|
132
|
+
declare const index_addTextToPDF: typeof addTextToPDF;
|
|
133
|
+
declare const index_captureToImage: typeof captureToImage;
|
|
134
|
+
declare const index_captureToImageDownload: typeof captureToImageDownload;
|
|
135
|
+
declare const index_captureToPDF: typeof captureToPDF;
|
|
136
|
+
declare const index_captureToPDFWithPagination: typeof captureToPDFWithPagination;
|
|
137
|
+
declare const index_createPDF: typeof createPDF;
|
|
138
|
+
declare const index_html2canvas: typeof html2canvas;
|
|
139
|
+
declare const index_jsPDF: typeof jsPDF;
|
|
140
|
+
declare const index_mergePDFs: typeof mergePDFs;
|
|
141
|
+
declare const index_pdfToBlob: typeof pdfToBlob;
|
|
142
|
+
declare const index_pdfToDataURL: typeof pdfToDataURL;
|
|
143
|
+
declare const index_savePDF: typeof savePDF;
|
|
144
|
+
declare namespace index {
|
|
145
|
+
export { type index_CaptureToPDFOptions as CaptureToPDFOptions, type index_PDFOptions as PDFOptions, index_addImageToPDF as addImageToPDF, index_addPage as addPage, index_addTableToPDF as addTableToPDF, index_addTextToPDF as addTextToPDF, index_captureToImage as captureToImage, index_captureToImageDownload as captureToImageDownload, index_captureToPDF as captureToPDF, index_captureToPDFWithPagination as captureToPDFWithPagination, index_createPDF as createPDF, index_html2canvas as html2canvas, index_jsPDF as jsPDF, index_mergePDFs as mergePDFs, index_pdfToBlob as pdfToBlob, index_pdfToDataURL as pdfToDataURL, index_savePDF as savePDF };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { type CaptureToPDFOptions as C, type PDFOptions as P, addImageToPDF as a, addPage as b, addTableToPDF as c, addTextToPDF as d, captureToImage as e, captureToImageDownload as f, captureToPDF as g, captureToPDFWithPagination as h, index as i, createPDF as j, pdfToDataURL as k, mergePDFs as m, pdfToBlob as p, savePDF as s };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { camelCase, capitalize, kebabCase, lowerFirst, snakeCase, startCase, trim, upperFirst } from 'es-toolkit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 字符串工具模块
|
|
5
|
+
* 基于 es-toolkit 封装,提供常用的字符串处理功能
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 判断字符串是否为空
|
|
10
|
+
* @param str 字符串
|
|
11
|
+
*/
|
|
12
|
+
declare const isEmpty: (str: string | null | undefined) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 生成随机字符串
|
|
15
|
+
* @param length 长度
|
|
16
|
+
* @param charset 字符集
|
|
17
|
+
*/
|
|
18
|
+
declare const random: (length?: number, charset?: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* 生成 UUID
|
|
21
|
+
*/
|
|
22
|
+
declare const uuid: () => string;
|
|
23
|
+
/**
|
|
24
|
+
* 生成短 ID
|
|
25
|
+
* @param length 长度
|
|
26
|
+
*/
|
|
27
|
+
declare const shortId: (length?: number) => string;
|
|
28
|
+
/**
|
|
29
|
+
* 字符串首字母大写
|
|
30
|
+
* @param str 字符串
|
|
31
|
+
*/
|
|
32
|
+
declare const firstUpperCase: (str: string) => string;
|
|
33
|
+
/**
|
|
34
|
+
* 字符串首字母小写
|
|
35
|
+
* @param str 字符串
|
|
36
|
+
*/
|
|
37
|
+
declare const firstLowerCase: (str: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* 反转字符串
|
|
40
|
+
* @param str 字符串
|
|
41
|
+
*/
|
|
42
|
+
declare const reverse: (str: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* 字符串重复
|
|
45
|
+
* @param str 字符串
|
|
46
|
+
* @param count 重复次数
|
|
47
|
+
*/
|
|
48
|
+
declare const repeat: (str: string, count: number) => string;
|
|
49
|
+
/**
|
|
50
|
+
* 填充字符串
|
|
51
|
+
* @param str 字符串
|
|
52
|
+
* @param length 目标长度
|
|
53
|
+
* @param char 填充字符
|
|
54
|
+
* @param isEnd 是否在末尾填充
|
|
55
|
+
*/
|
|
56
|
+
declare const pad: (str: string | number, length: number, char?: string, isEnd?: boolean) => string;
|
|
57
|
+
/**
|
|
58
|
+
* 获取文件扩展名
|
|
59
|
+
* @param filename 文件名
|
|
60
|
+
*/
|
|
61
|
+
declare const getExtension: (filename: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* 获取文件名(不带扩展名)
|
|
64
|
+
* @param filename 文件名
|
|
65
|
+
*/
|
|
66
|
+
declare const getFileName: (filename: string) => string;
|
|
67
|
+
/**
|
|
68
|
+
* 隐藏手机号中间四位
|
|
69
|
+
* @param phone 手机号
|
|
70
|
+
*/
|
|
71
|
+
declare const hidePhone: (phone: string) => string;
|
|
72
|
+
/**
|
|
73
|
+
* 隐藏邮箱
|
|
74
|
+
* @param email 邮箱
|
|
75
|
+
*/
|
|
76
|
+
declare const hideEmail: (email: string) => string;
|
|
77
|
+
/**
|
|
78
|
+
* 隐藏身份证号中间部分
|
|
79
|
+
* @param idCard 身份证号
|
|
80
|
+
*/
|
|
81
|
+
declare const hideIdCard: (idCard: string) => string;
|
|
82
|
+
/**
|
|
83
|
+
* 格式化金额
|
|
84
|
+
* @param amount 金额
|
|
85
|
+
* @param decimals 小数位数
|
|
86
|
+
* @param separator 千位分隔符
|
|
87
|
+
*/
|
|
88
|
+
declare const formatMoney: (amount: number, decimals?: number, separator?: string) => string;
|
|
89
|
+
/**
|
|
90
|
+
* 字符串转数字
|
|
91
|
+
* @param str 字符串
|
|
92
|
+
* @param defaultValue 默认值
|
|
93
|
+
*/
|
|
94
|
+
declare const toNumber: (str: string | number | null | undefined, defaultValue?: number) => number;
|
|
95
|
+
/**
|
|
96
|
+
* 字符串转布尔值
|
|
97
|
+
* @param str 字符串
|
|
98
|
+
* @param defaultValue 默认值
|
|
99
|
+
*/
|
|
100
|
+
declare const toBoolean: (str: string | boolean | null | undefined, defaultValue?: boolean) => boolean;
|
|
101
|
+
/**
|
|
102
|
+
* 提取字符串中的数字
|
|
103
|
+
* @param str 字符串
|
|
104
|
+
*/
|
|
105
|
+
declare const extractNumbers: (str: string) => number[];
|
|
106
|
+
/**
|
|
107
|
+
* 提取字符串中的手机号
|
|
108
|
+
* @param str 字符串
|
|
109
|
+
*/
|
|
110
|
+
declare const extractPhones: (str: string) => string[];
|
|
111
|
+
/**
|
|
112
|
+
* 提取字符串中的邮箱
|
|
113
|
+
* @param str 字符串
|
|
114
|
+
*/
|
|
115
|
+
declare const extractEmails: (str: string) => string[];
|
|
116
|
+
/**
|
|
117
|
+
* 验证手机号
|
|
118
|
+
* @param phone 手机号
|
|
119
|
+
*/
|
|
120
|
+
declare const isPhone: (phone: string) => boolean;
|
|
121
|
+
/**
|
|
122
|
+
* 验证邮箱
|
|
123
|
+
* @param email 邮箱
|
|
124
|
+
*/
|
|
125
|
+
declare const isEmail: (email: string) => boolean;
|
|
126
|
+
/**
|
|
127
|
+
* 验证身份证号
|
|
128
|
+
* @param idCard 身份证号
|
|
129
|
+
*/
|
|
130
|
+
declare const isIdCard: (idCard: string) => boolean;
|
|
131
|
+
/**
|
|
132
|
+
* 验证 URL
|
|
133
|
+
* @param url URL
|
|
134
|
+
*/
|
|
135
|
+
declare const isUrl: (url: string) => boolean;
|
|
136
|
+
/**
|
|
137
|
+
* 高亮关键词
|
|
138
|
+
* @param text 文本
|
|
139
|
+
* @param keyword 关键词
|
|
140
|
+
* @param highlightClass 高亮样式类名
|
|
141
|
+
*/
|
|
142
|
+
declare const highlight: (text: string, keyword: string, highlightClass?: string) => string;
|
|
143
|
+
/**
|
|
144
|
+
* 截断文本(支持 HTML)
|
|
145
|
+
* @param text 文本
|
|
146
|
+
* @param length 最大长度
|
|
147
|
+
* @param suffix 后缀
|
|
148
|
+
*/
|
|
149
|
+
declare const truncateText: (text: string, length?: number, suffix?: string) => string;
|
|
150
|
+
/**
|
|
151
|
+
* 转义 HTML
|
|
152
|
+
* @param str 字符串
|
|
153
|
+
*/
|
|
154
|
+
declare const escapeHtml: (str: string) => string;
|
|
155
|
+
/**
|
|
156
|
+
* 反转义 HTML
|
|
157
|
+
* @param str 字符串
|
|
158
|
+
*/
|
|
159
|
+
declare const unescapeHtml: (str: string) => string;
|
|
160
|
+
/**
|
|
161
|
+
* 移除 HTML 标签
|
|
162
|
+
* @param str 字符串
|
|
163
|
+
*/
|
|
164
|
+
declare const stripTags: (str: string) => string;
|
|
165
|
+
/**
|
|
166
|
+
* 字节长度
|
|
167
|
+
* @param str 字符串
|
|
168
|
+
*/
|
|
169
|
+
declare const byteLength: (str: string) => number;
|
|
170
|
+
|
|
171
|
+
declare const index_byteLength: typeof byteLength;
|
|
172
|
+
declare const index_camelCase: typeof camelCase;
|
|
173
|
+
declare const index_capitalize: typeof capitalize;
|
|
174
|
+
declare const index_escapeHtml: typeof escapeHtml;
|
|
175
|
+
declare const index_extractEmails: typeof extractEmails;
|
|
176
|
+
declare const index_extractNumbers: typeof extractNumbers;
|
|
177
|
+
declare const index_extractPhones: typeof extractPhones;
|
|
178
|
+
declare const index_firstLowerCase: typeof firstLowerCase;
|
|
179
|
+
declare const index_firstUpperCase: typeof firstUpperCase;
|
|
180
|
+
declare const index_formatMoney: typeof formatMoney;
|
|
181
|
+
declare const index_getExtension: typeof getExtension;
|
|
182
|
+
declare const index_getFileName: typeof getFileName;
|
|
183
|
+
declare const index_hideEmail: typeof hideEmail;
|
|
184
|
+
declare const index_hideIdCard: typeof hideIdCard;
|
|
185
|
+
declare const index_hidePhone: typeof hidePhone;
|
|
186
|
+
declare const index_highlight: typeof highlight;
|
|
187
|
+
declare const index_isEmail: typeof isEmail;
|
|
188
|
+
declare const index_isEmpty: typeof isEmpty;
|
|
189
|
+
declare const index_isIdCard: typeof isIdCard;
|
|
190
|
+
declare const index_isPhone: typeof isPhone;
|
|
191
|
+
declare const index_isUrl: typeof isUrl;
|
|
192
|
+
declare const index_kebabCase: typeof kebabCase;
|
|
193
|
+
declare const index_lowerFirst: typeof lowerFirst;
|
|
194
|
+
declare const index_pad: typeof pad;
|
|
195
|
+
declare const index_random: typeof random;
|
|
196
|
+
declare const index_repeat: typeof repeat;
|
|
197
|
+
declare const index_reverse: typeof reverse;
|
|
198
|
+
declare const index_shortId: typeof shortId;
|
|
199
|
+
declare const index_snakeCase: typeof snakeCase;
|
|
200
|
+
declare const index_startCase: typeof startCase;
|
|
201
|
+
declare const index_stripTags: typeof stripTags;
|
|
202
|
+
declare const index_toBoolean: typeof toBoolean;
|
|
203
|
+
declare const index_toNumber: typeof toNumber;
|
|
204
|
+
declare const index_trim: typeof trim;
|
|
205
|
+
declare const index_truncateText: typeof truncateText;
|
|
206
|
+
declare const index_unescapeHtml: typeof unescapeHtml;
|
|
207
|
+
declare const index_upperFirst: typeof upperFirst;
|
|
208
|
+
declare const index_uuid: typeof uuid;
|
|
209
|
+
declare namespace index {
|
|
210
|
+
export { index_byteLength as byteLength, index_camelCase as camelCase, index_capitalize as capitalize, index_escapeHtml as escapeHtml, index_extractEmails as extractEmails, index_extractNumbers as extractNumbers, index_extractPhones as extractPhones, index_firstLowerCase as firstLowerCase, index_firstUpperCase as firstUpperCase, index_formatMoney as formatMoney, index_getExtension as getExtension, index_getFileName as getFileName, index_hideEmail as hideEmail, index_hideIdCard as hideIdCard, index_hidePhone as hidePhone, index_highlight as highlight, index_isEmail as isEmail, index_isEmpty as isEmpty, index_isIdCard as isIdCard, index_isPhone as isPhone, index_isUrl as isUrl, index_kebabCase as kebabCase, index_lowerFirst as lowerFirst, index_pad as pad, index_random as random, index_repeat as repeat, index_reverse as reverse, index_shortId as shortId, index_snakeCase as snakeCase, index_startCase as startCase, index_stripTags as stripTags, index_toBoolean as toBoolean, index_toNumber as toNumber, index_trim as trim, index_truncateText as truncateText, index_unescapeHtml as unescapeHtml, index_upperFirst as upperFirst, index_uuid as uuid };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { toBoolean as A, toNumber as B, truncateText as C, unescapeHtml as D, uuid as E, extractEmails as a, byteLength as b, extractNumbers as c, extractPhones as d, escapeHtml as e, firstLowerCase as f, firstUpperCase as g, formatMoney as h, index as i, getExtension as j, getFileName as k, hideEmail as l, hideIdCard as m, hidePhone as n, highlight as o, isEmail as p, isEmpty as q, isIdCard as r, isPhone as s, isUrl as t, pad as u, random as v, repeat as w, reverse as x, shortId as y, stripTags as z };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { camelCase, capitalize, kebabCase, lowerFirst, snakeCase, startCase, trim, upperFirst } from 'es-toolkit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 字符串工具模块
|
|
5
|
+
* 基于 es-toolkit 封装,提供常用的字符串处理功能
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 判断字符串是否为空
|
|
10
|
+
* @param str 字符串
|
|
11
|
+
*/
|
|
12
|
+
declare const isEmpty: (str: string | null | undefined) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 生成随机字符串
|
|
15
|
+
* @param length 长度
|
|
16
|
+
* @param charset 字符集
|
|
17
|
+
*/
|
|
18
|
+
declare const random: (length?: number, charset?: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* 生成 UUID
|
|
21
|
+
*/
|
|
22
|
+
declare const uuid: () => string;
|
|
23
|
+
/**
|
|
24
|
+
* 生成短 ID
|
|
25
|
+
* @param length 长度
|
|
26
|
+
*/
|
|
27
|
+
declare const shortId: (length?: number) => string;
|
|
28
|
+
/**
|
|
29
|
+
* 字符串首字母大写
|
|
30
|
+
* @param str 字符串
|
|
31
|
+
*/
|
|
32
|
+
declare const firstUpperCase: (str: string) => string;
|
|
33
|
+
/**
|
|
34
|
+
* 字符串首字母小写
|
|
35
|
+
* @param str 字符串
|
|
36
|
+
*/
|
|
37
|
+
declare const firstLowerCase: (str: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* 反转字符串
|
|
40
|
+
* @param str 字符串
|
|
41
|
+
*/
|
|
42
|
+
declare const reverse: (str: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* 字符串重复
|
|
45
|
+
* @param str 字符串
|
|
46
|
+
* @param count 重复次数
|
|
47
|
+
*/
|
|
48
|
+
declare const repeat: (str: string, count: number) => string;
|
|
49
|
+
/**
|
|
50
|
+
* 填充字符串
|
|
51
|
+
* @param str 字符串
|
|
52
|
+
* @param length 目标长度
|
|
53
|
+
* @param char 填充字符
|
|
54
|
+
* @param isEnd 是否在末尾填充
|
|
55
|
+
*/
|
|
56
|
+
declare const pad: (str: string | number, length: number, char?: string, isEnd?: boolean) => string;
|
|
57
|
+
/**
|
|
58
|
+
* 获取文件扩展名
|
|
59
|
+
* @param filename 文件名
|
|
60
|
+
*/
|
|
61
|
+
declare const getExtension: (filename: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* 获取文件名(不带扩展名)
|
|
64
|
+
* @param filename 文件名
|
|
65
|
+
*/
|
|
66
|
+
declare const getFileName: (filename: string) => string;
|
|
67
|
+
/**
|
|
68
|
+
* 隐藏手机号中间四位
|
|
69
|
+
* @param phone 手机号
|
|
70
|
+
*/
|
|
71
|
+
declare const hidePhone: (phone: string) => string;
|
|
72
|
+
/**
|
|
73
|
+
* 隐藏邮箱
|
|
74
|
+
* @param email 邮箱
|
|
75
|
+
*/
|
|
76
|
+
declare const hideEmail: (email: string) => string;
|
|
77
|
+
/**
|
|
78
|
+
* 隐藏身份证号中间部分
|
|
79
|
+
* @param idCard 身份证号
|
|
80
|
+
*/
|
|
81
|
+
declare const hideIdCard: (idCard: string) => string;
|
|
82
|
+
/**
|
|
83
|
+
* 格式化金额
|
|
84
|
+
* @param amount 金额
|
|
85
|
+
* @param decimals 小数位数
|
|
86
|
+
* @param separator 千位分隔符
|
|
87
|
+
*/
|
|
88
|
+
declare const formatMoney: (amount: number, decimals?: number, separator?: string) => string;
|
|
89
|
+
/**
|
|
90
|
+
* 字符串转数字
|
|
91
|
+
* @param str 字符串
|
|
92
|
+
* @param defaultValue 默认值
|
|
93
|
+
*/
|
|
94
|
+
declare const toNumber: (str: string | number | null | undefined, defaultValue?: number) => number;
|
|
95
|
+
/**
|
|
96
|
+
* 字符串转布尔值
|
|
97
|
+
* @param str 字符串
|
|
98
|
+
* @param defaultValue 默认值
|
|
99
|
+
*/
|
|
100
|
+
declare const toBoolean: (str: string | boolean | null | undefined, defaultValue?: boolean) => boolean;
|
|
101
|
+
/**
|
|
102
|
+
* 提取字符串中的数字
|
|
103
|
+
* @param str 字符串
|
|
104
|
+
*/
|
|
105
|
+
declare const extractNumbers: (str: string) => number[];
|
|
106
|
+
/**
|
|
107
|
+
* 提取字符串中的手机号
|
|
108
|
+
* @param str 字符串
|
|
109
|
+
*/
|
|
110
|
+
declare const extractPhones: (str: string) => string[];
|
|
111
|
+
/**
|
|
112
|
+
* 提取字符串中的邮箱
|
|
113
|
+
* @param str 字符串
|
|
114
|
+
*/
|
|
115
|
+
declare const extractEmails: (str: string) => string[];
|
|
116
|
+
/**
|
|
117
|
+
* 验证手机号
|
|
118
|
+
* @param phone 手机号
|
|
119
|
+
*/
|
|
120
|
+
declare const isPhone: (phone: string) => boolean;
|
|
121
|
+
/**
|
|
122
|
+
* 验证邮箱
|
|
123
|
+
* @param email 邮箱
|
|
124
|
+
*/
|
|
125
|
+
declare const isEmail: (email: string) => boolean;
|
|
126
|
+
/**
|
|
127
|
+
* 验证身份证号
|
|
128
|
+
* @param idCard 身份证号
|
|
129
|
+
*/
|
|
130
|
+
declare const isIdCard: (idCard: string) => boolean;
|
|
131
|
+
/**
|
|
132
|
+
* 验证 URL
|
|
133
|
+
* @param url URL
|
|
134
|
+
*/
|
|
135
|
+
declare const isUrl: (url: string) => boolean;
|
|
136
|
+
/**
|
|
137
|
+
* 高亮关键词
|
|
138
|
+
* @param text 文本
|
|
139
|
+
* @param keyword 关键词
|
|
140
|
+
* @param highlightClass 高亮样式类名
|
|
141
|
+
*/
|
|
142
|
+
declare const highlight: (text: string, keyword: string, highlightClass?: string) => string;
|
|
143
|
+
/**
|
|
144
|
+
* 截断文本(支持 HTML)
|
|
145
|
+
* @param text 文本
|
|
146
|
+
* @param length 最大长度
|
|
147
|
+
* @param suffix 后缀
|
|
148
|
+
*/
|
|
149
|
+
declare const truncateText: (text: string, length?: number, suffix?: string) => string;
|
|
150
|
+
/**
|
|
151
|
+
* 转义 HTML
|
|
152
|
+
* @param str 字符串
|
|
153
|
+
*/
|
|
154
|
+
declare const escapeHtml: (str: string) => string;
|
|
155
|
+
/**
|
|
156
|
+
* 反转义 HTML
|
|
157
|
+
* @param str 字符串
|
|
158
|
+
*/
|
|
159
|
+
declare const unescapeHtml: (str: string) => string;
|
|
160
|
+
/**
|
|
161
|
+
* 移除 HTML 标签
|
|
162
|
+
* @param str 字符串
|
|
163
|
+
*/
|
|
164
|
+
declare const stripTags: (str: string) => string;
|
|
165
|
+
/**
|
|
166
|
+
* 字节长度
|
|
167
|
+
* @param str 字符串
|
|
168
|
+
*/
|
|
169
|
+
declare const byteLength: (str: string) => number;
|
|
170
|
+
|
|
171
|
+
declare const index_byteLength: typeof byteLength;
|
|
172
|
+
declare const index_camelCase: typeof camelCase;
|
|
173
|
+
declare const index_capitalize: typeof capitalize;
|
|
174
|
+
declare const index_escapeHtml: typeof escapeHtml;
|
|
175
|
+
declare const index_extractEmails: typeof extractEmails;
|
|
176
|
+
declare const index_extractNumbers: typeof extractNumbers;
|
|
177
|
+
declare const index_extractPhones: typeof extractPhones;
|
|
178
|
+
declare const index_firstLowerCase: typeof firstLowerCase;
|
|
179
|
+
declare const index_firstUpperCase: typeof firstUpperCase;
|
|
180
|
+
declare const index_formatMoney: typeof formatMoney;
|
|
181
|
+
declare const index_getExtension: typeof getExtension;
|
|
182
|
+
declare const index_getFileName: typeof getFileName;
|
|
183
|
+
declare const index_hideEmail: typeof hideEmail;
|
|
184
|
+
declare const index_hideIdCard: typeof hideIdCard;
|
|
185
|
+
declare const index_hidePhone: typeof hidePhone;
|
|
186
|
+
declare const index_highlight: typeof highlight;
|
|
187
|
+
declare const index_isEmail: typeof isEmail;
|
|
188
|
+
declare const index_isEmpty: typeof isEmpty;
|
|
189
|
+
declare const index_isIdCard: typeof isIdCard;
|
|
190
|
+
declare const index_isPhone: typeof isPhone;
|
|
191
|
+
declare const index_isUrl: typeof isUrl;
|
|
192
|
+
declare const index_kebabCase: typeof kebabCase;
|
|
193
|
+
declare const index_lowerFirst: typeof lowerFirst;
|
|
194
|
+
declare const index_pad: typeof pad;
|
|
195
|
+
declare const index_random: typeof random;
|
|
196
|
+
declare const index_repeat: typeof repeat;
|
|
197
|
+
declare const index_reverse: typeof reverse;
|
|
198
|
+
declare const index_shortId: typeof shortId;
|
|
199
|
+
declare const index_snakeCase: typeof snakeCase;
|
|
200
|
+
declare const index_startCase: typeof startCase;
|
|
201
|
+
declare const index_stripTags: typeof stripTags;
|
|
202
|
+
declare const index_toBoolean: typeof toBoolean;
|
|
203
|
+
declare const index_toNumber: typeof toNumber;
|
|
204
|
+
declare const index_trim: typeof trim;
|
|
205
|
+
declare const index_truncateText: typeof truncateText;
|
|
206
|
+
declare const index_unescapeHtml: typeof unescapeHtml;
|
|
207
|
+
declare const index_upperFirst: typeof upperFirst;
|
|
208
|
+
declare const index_uuid: typeof uuid;
|
|
209
|
+
declare namespace index {
|
|
210
|
+
export { index_byteLength as byteLength, index_camelCase as camelCase, index_capitalize as capitalize, index_escapeHtml as escapeHtml, index_extractEmails as extractEmails, index_extractNumbers as extractNumbers, index_extractPhones as extractPhones, index_firstLowerCase as firstLowerCase, index_firstUpperCase as firstUpperCase, index_formatMoney as formatMoney, index_getExtension as getExtension, index_getFileName as getFileName, index_hideEmail as hideEmail, index_hideIdCard as hideIdCard, index_hidePhone as hidePhone, index_highlight as highlight, index_isEmail as isEmail, index_isEmpty as isEmpty, index_isIdCard as isIdCard, index_isPhone as isPhone, index_isUrl as isUrl, index_kebabCase as kebabCase, index_lowerFirst as lowerFirst, index_pad as pad, index_random as random, index_repeat as repeat, index_reverse as reverse, index_shortId as shortId, index_snakeCase as snakeCase, index_startCase as startCase, index_stripTags as stripTags, index_toBoolean as toBoolean, index_toNumber as toNumber, index_trim as trim, index_truncateText as truncateText, index_unescapeHtml as unescapeHtml, index_upperFirst as upperFirst, index_uuid as uuid };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { toBoolean as A, toNumber as B, truncateText as C, unescapeHtml as D, uuid as E, extractEmails as a, byteLength as b, extractNumbers as c, extractPhones as d, escapeHtml as e, firstLowerCase as f, firstUpperCase as g, formatMoney as h, index as i, getExtension as j, getFileName as k, hideEmail as l, hideIdCard as m, hidePhone as n, highlight as o, isEmail as p, isEmpty as q, isIdCard as r, isPhone as s, isUrl as t, pad as u, random as v, repeat as w, reverse as x, shortId as y, stripTags as z };
|