@zcrkey/js-utils 0.0.9 → 0.0.10

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.
@@ -0,0 +1,71 @@
1
+ /**
2
+ * 文件类型
3
+ * - OTHER 其他
4
+ * - IMAGE 图片
5
+ * - VIDEO 视频
6
+ * - AUDIO 音频
7
+ * - DOCUMENT 文档
8
+ * - ARCHIVE 压缩包
9
+ */
10
+ export declare enum FileTypeEnum {
11
+ OTHER = "other",
12
+ IMAGE = "image",
13
+ VIDEO = "video",
14
+ AUDIO = "audio",
15
+ DOCUMENT = "document",
16
+ ARCHIVE = "archive"
17
+ }
18
+ /**
19
+ * 文档类型
20
+ * - OTHER
21
+ * - PDF
22
+ * - DOC
23
+ * - DOCX
24
+ * - XLS
25
+ * - XLSX
26
+ * - PPT
27
+ * - PPTX
28
+ * - TXT
29
+ */
30
+ export declare const enum DocumentTypeEnum {
31
+ OTHER = "other",
32
+ PDF = "pdf",
33
+ DOC = "doc",
34
+ DOCX = "docx",
35
+ XLS = "xls",
36
+ XLSX = "xlsx",
37
+ PPT = "ppt",
38
+ PPTX = "pptx",
39
+ TXT = "txt"
40
+ }
41
+ /**
42
+ * 文件元信息
43
+ */
44
+ export interface CrFileMeta {
45
+ ext: string;
46
+ type: FileTypeEnum;
47
+ documentType?: DocumentTypeEnum;
48
+ }
49
+ export declare class CrFileUtil {
50
+ /**
51
+ * 提取扩展名(不含 .)
52
+ */
53
+ static getExt(filename?: string): string;
54
+ /**
55
+ * 获取文件完整信息
56
+ */
57
+ static getMeta(filename: string): CrFileMeta;
58
+ /**
59
+ * 文件类型
60
+ */
61
+ static getType(filename: string): FileTypeEnum;
62
+ /**
63
+ * 文档类型
64
+ */
65
+ static getDocumentType(filename: string): DocumentTypeEnum;
66
+ static isImage(filename: string): boolean;
67
+ static isVideo(filename: string): boolean;
68
+ static isAudio(filename: string): boolean;
69
+ static isDocument(filename: string): boolean;
70
+ static isArchive(filename: string): boolean;
71
+ }
@@ -0,0 +1,154 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/file.ts
20
+ var file_exports = {};
21
+ __export(file_exports, {
22
+ CrFileUtil: () => CrFileUtil,
23
+ DocumentTypeEnum: () => DocumentTypeEnum,
24
+ FileTypeEnum: () => FileTypeEnum
25
+ });
26
+ module.exports = __toCommonJS(file_exports);
27
+ var FileTypeEnum = /* @__PURE__ */ ((FileTypeEnum2) => {
28
+ FileTypeEnum2["OTHER"] = "other";
29
+ FileTypeEnum2["IMAGE"] = "image";
30
+ FileTypeEnum2["VIDEO"] = "video";
31
+ FileTypeEnum2["AUDIO"] = "audio";
32
+ FileTypeEnum2["DOCUMENT"] = "document";
33
+ FileTypeEnum2["ARCHIVE"] = "archive";
34
+ return FileTypeEnum2;
35
+ })(FileTypeEnum || {});
36
+ var DocumentTypeEnum = /* @__PURE__ */ ((DocumentTypeEnum2) => {
37
+ DocumentTypeEnum2["OTHER"] = "other";
38
+ DocumentTypeEnum2["PDF"] = "pdf";
39
+ DocumentTypeEnum2["DOC"] = "doc";
40
+ DocumentTypeEnum2["DOCX"] = "docx";
41
+ DocumentTypeEnum2["XLS"] = "xls";
42
+ DocumentTypeEnum2["XLSX"] = "xlsx";
43
+ DocumentTypeEnum2["PPT"] = "ppt";
44
+ DocumentTypeEnum2["PPTX"] = "pptx";
45
+ DocumentTypeEnum2["TXT"] = "txt";
46
+ return DocumentTypeEnum2;
47
+ })(DocumentTypeEnum || {});
48
+ var FILE_META_LIST = [
49
+ /* ---------- image ---------- */
50
+ { ext: "jpg", type: "image" /* IMAGE */ },
51
+ { ext: "jpeg", type: "image" /* IMAGE */ },
52
+ { ext: "png", type: "image" /* IMAGE */ },
53
+ { ext: "gif", type: "image" /* IMAGE */ },
54
+ { ext: "bmp", type: "image" /* IMAGE */ },
55
+ { ext: "webp", type: "image" /* IMAGE */ },
56
+ { ext: "svg", type: "image" /* IMAGE */ },
57
+ { ext: "ico", type: "image" /* IMAGE */ },
58
+ { ext: "heic", type: "image" /* IMAGE */ },
59
+ { ext: "avif", type: "image" /* IMAGE */ },
60
+ /* ---------- video ---------- */
61
+ { ext: "mp4", type: "video" /* VIDEO */ },
62
+ { ext: "mkv", type: "video" /* VIDEO */ },
63
+ { ext: "mov", type: "video" /* VIDEO */ },
64
+ { ext: "avi", type: "video" /* VIDEO */ },
65
+ { ext: "webm", type: "video" /* VIDEO */ },
66
+ { ext: "flv", type: "video" /* VIDEO */ },
67
+ /* ---------- audio ---------- */
68
+ { ext: "mp3", type: "audio" /* AUDIO */ },
69
+ { ext: "wav", type: "audio" /* AUDIO */ },
70
+ { ext: "aac", type: "audio" /* AUDIO */ },
71
+ { ext: "flac", type: "audio" /* AUDIO */ },
72
+ { ext: "ogg", type: "audio" /* AUDIO */ },
73
+ { ext: "m4a", type: "audio" /* AUDIO */ },
74
+ /* ---------- document ---------- */
75
+ { ext: "pdf", type: "document" /* DOCUMENT */, documentType: "pdf" /* PDF */ },
76
+ { ext: "doc", type: "document" /* DOCUMENT */, documentType: "doc" /* DOC */ },
77
+ { ext: "docx", type: "document" /* DOCUMENT */, documentType: "docx" /* DOCX */ },
78
+ { ext: "xls", type: "document" /* DOCUMENT */, documentType: "xls" /* XLS */ },
79
+ { ext: "xlsx", type: "document" /* DOCUMENT */, documentType: "xlsx" /* XLSX */ },
80
+ { ext: "ppt", type: "document" /* DOCUMENT */, documentType: "ppt" /* PPT */ },
81
+ { ext: "pptx", type: "document" /* DOCUMENT */, documentType: "pptx" /* PPTX */ },
82
+ { ext: "txt", type: "document" /* DOCUMENT */, documentType: "txt" /* TXT */ },
83
+ { ext: "md", type: "document" /* DOCUMENT */ },
84
+ { ext: "csv", type: "document" /* DOCUMENT */ },
85
+ { ext: "json", type: "document" /* DOCUMENT */ },
86
+ /* ---------- archive ---------- */
87
+ { ext: "zip", type: "archive" /* ARCHIVE */ },
88
+ { ext: "rar", type: "archive" /* ARCHIVE */ },
89
+ { ext: "7z", type: "archive" /* ARCHIVE */ },
90
+ { ext: "tar", type: "archive" /* ARCHIVE */ },
91
+ { ext: "gz", type: "archive" /* ARCHIVE */ }
92
+ ];
93
+ var FILE_META_MAP = /* @__PURE__ */ new Map();
94
+ FILE_META_LIST.forEach((item) => {
95
+ FILE_META_MAP.set(item.ext, item);
96
+ });
97
+ var DEFAULT_META = {
98
+ ext: "",
99
+ type: "other" /* OTHER */,
100
+ documentType: "other" /* OTHER */
101
+ };
102
+ var CrFileUtil = class {
103
+ /**
104
+ * 提取扩展名(不含 .)
105
+ */
106
+ static getExt(filename) {
107
+ var _a;
108
+ if (!filename || typeof filename !== "string")
109
+ return "";
110
+ return ((_a = filename.trim().split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
111
+ }
112
+ /**
113
+ * 获取文件完整信息
114
+ */
115
+ static getMeta(filename) {
116
+ const ext = this.getExt(filename);
117
+ if (!ext)
118
+ return DEFAULT_META;
119
+ return FILE_META_MAP.get(ext) || { ...DEFAULT_META, ext };
120
+ }
121
+ /**
122
+ * 文件类型
123
+ */
124
+ static getType(filename) {
125
+ return this.getMeta(filename).type;
126
+ }
127
+ /**
128
+ * 文档类型
129
+ */
130
+ static getDocumentType(filename) {
131
+ return this.getMeta(filename).documentType || "other" /* OTHER */;
132
+ }
133
+ static isImage(filename) {
134
+ return this.getType(filename) === "image" /* IMAGE */;
135
+ }
136
+ static isVideo(filename) {
137
+ return this.getType(filename) === "video" /* VIDEO */;
138
+ }
139
+ static isAudio(filename) {
140
+ return this.getType(filename) === "audio" /* AUDIO */;
141
+ }
142
+ static isDocument(filename) {
143
+ return this.getType(filename) === "document" /* DOCUMENT */;
144
+ }
145
+ static isArchive(filename) {
146
+ return this.getType(filename) === "archive" /* ARCHIVE */;
147
+ }
148
+ };
149
+ // Annotate the CommonJS export names for ESM import in node:
150
+ 0 && (module.exports = {
151
+ CrFileUtil,
152
+ DocumentTypeEnum,
153
+ FileTypeEnum
154
+ });
@@ -1,4 +1,6 @@
1
1
  export { default as CrColorUtil } from './color';
2
+ export * from './file';
3
+ export type * from './file';
2
4
  export type * from './eventCenter';
3
5
  export { default as CrEventCenter } from './eventCenter';
4
6
  export type * from './obj';
package/dist/cjs/index.js CHANGED
@@ -16,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
21
  // If the importer is in node compatibility mode or this is not an ESM
21
22
  // file that has been converted to a CommonJS file using a Babel-
@@ -38,6 +39,7 @@ __export(src_exports, {
38
39
  });
39
40
  module.exports = __toCommonJS(src_exports);
40
41
  var import_color = __toESM(require("./color"));
42
+ __reExport(src_exports, require("./file"), module.exports);
41
43
  var import_eventCenter = __toESM(require("./eventCenter"));
42
44
  var import_obj = __toESM(require("./obj"));
43
45
  var import_storage = __toESM(require("./storage"));
@@ -50,5 +52,6 @@ var import_util = __toESM(require("./util"));
50
52
  CrObjUtil,
51
53
  CrStorage,
52
54
  CrTreeUtil,
53
- CrUtil
55
+ CrUtil,
56
+ ...require("./file")
54
57
  });
package/dist/cjs/util.js CHANGED
@@ -571,8 +571,8 @@ var CrUtil = class {
571
571
  }
572
572
  /**
573
573
  * 格式化为千分位格式
574
- * @param value
575
- * @returns
574
+ * @param value
575
+ * @returns
576
576
  */
577
577
  static formatThousands(value) {
578
578
  if (value == null)
@@ -596,8 +596,8 @@ var CrUtil = class {
596
596
  }
597
597
  /**
598
598
  * 解析千分位格式
599
- * @param value
600
- * @returns
599
+ * @param value
600
+ * @returns
601
601
  */
602
602
  static parseThousands(value) {
603
603
  if (value == null)
@@ -0,0 +1,71 @@
1
+ /**
2
+ * 文件类型
3
+ * - OTHER 其他
4
+ * - IMAGE 图片
5
+ * - VIDEO 视频
6
+ * - AUDIO 音频
7
+ * - DOCUMENT 文档
8
+ * - ARCHIVE 压缩包
9
+ */
10
+ export declare enum FileTypeEnum {
11
+ OTHER = "other",
12
+ IMAGE = "image",
13
+ VIDEO = "video",
14
+ AUDIO = "audio",
15
+ DOCUMENT = "document",
16
+ ARCHIVE = "archive"
17
+ }
18
+ /**
19
+ * 文档类型
20
+ * - OTHER
21
+ * - PDF
22
+ * - DOC
23
+ * - DOCX
24
+ * - XLS
25
+ * - XLSX
26
+ * - PPT
27
+ * - PPTX
28
+ * - TXT
29
+ */
30
+ export declare const enum DocumentTypeEnum {
31
+ OTHER = "other",
32
+ PDF = "pdf",
33
+ DOC = "doc",
34
+ DOCX = "docx",
35
+ XLS = "xls",
36
+ XLSX = "xlsx",
37
+ PPT = "ppt",
38
+ PPTX = "pptx",
39
+ TXT = "txt"
40
+ }
41
+ /**
42
+ * 文件元信息
43
+ */
44
+ export interface CrFileMeta {
45
+ ext: string;
46
+ type: FileTypeEnum;
47
+ documentType?: DocumentTypeEnum;
48
+ }
49
+ export declare class CrFileUtil {
50
+ /**
51
+ * 提取扩展名(不含 .)
52
+ */
53
+ static getExt(filename?: string): string;
54
+ /**
55
+ * 获取文件完整信息
56
+ */
57
+ static getMeta(filename: string): CrFileMeta;
58
+ /**
59
+ * 文件类型
60
+ */
61
+ static getType(filename: string): FileTypeEnum;
62
+ /**
63
+ * 文档类型
64
+ */
65
+ static getDocumentType(filename: string): DocumentTypeEnum;
66
+ static isImage(filename: string): boolean;
67
+ static isVideo(filename: string): boolean;
68
+ static isAudio(filename: string): boolean;
69
+ static isDocument(filename: string): boolean;
70
+ static isArchive(filename: string): boolean;
71
+ }
@@ -0,0 +1,267 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
+ /**
11
+ * 文件类型
12
+ * - OTHER 其他
13
+ * - IMAGE 图片
14
+ * - VIDEO 视频
15
+ * - AUDIO 音频
16
+ * - DOCUMENT 文档
17
+ * - ARCHIVE 压缩包
18
+ */
19
+ export var FileTypeEnum = /*#__PURE__*/function (FileTypeEnum) {
20
+ FileTypeEnum["OTHER"] = "other";
21
+ FileTypeEnum["IMAGE"] = "image";
22
+ FileTypeEnum["VIDEO"] = "video";
23
+ FileTypeEnum["AUDIO"] = "audio";
24
+ FileTypeEnum["DOCUMENT"] = "document";
25
+ FileTypeEnum["ARCHIVE"] = "archive";
26
+ return FileTypeEnum;
27
+ }({});
28
+
29
+ /**
30
+ * 文档类型
31
+ * - OTHER
32
+ * - PDF
33
+ * - DOC
34
+ * - DOCX
35
+ * - XLS
36
+ * - XLSX
37
+ * - PPT
38
+ * - PPTX
39
+ * - TXT
40
+ */
41
+ export var DocumentTypeEnum = {
42
+ OTHER: "other",
43
+ PDF: "pdf",
44
+ DOC: "doc",
45
+ DOCX: "docx",
46
+ XLS: "xls",
47
+ XLSX: "xlsx",
48
+ PPT: "ppt",
49
+ PPTX: "pptx",
50
+ TXT: "txt"
51
+ };
52
+
53
+ /**
54
+ * 文件元信息
55
+ */
56
+
57
+ var FILE_META_LIST = [/* ---------- image ---------- */
58
+ {
59
+ ext: 'jpg',
60
+ type: FileTypeEnum.IMAGE
61
+ }, {
62
+ ext: 'jpeg',
63
+ type: FileTypeEnum.IMAGE
64
+ }, {
65
+ ext: 'png',
66
+ type: FileTypeEnum.IMAGE
67
+ }, {
68
+ ext: 'gif',
69
+ type: FileTypeEnum.IMAGE
70
+ }, {
71
+ ext: 'bmp',
72
+ type: FileTypeEnum.IMAGE
73
+ }, {
74
+ ext: 'webp',
75
+ type: FileTypeEnum.IMAGE
76
+ }, {
77
+ ext: 'svg',
78
+ type: FileTypeEnum.IMAGE
79
+ }, {
80
+ ext: 'ico',
81
+ type: FileTypeEnum.IMAGE
82
+ }, {
83
+ ext: 'heic',
84
+ type: FileTypeEnum.IMAGE
85
+ }, {
86
+ ext: 'avif',
87
+ type: FileTypeEnum.IMAGE
88
+ }, /* ---------- video ---------- */
89
+ {
90
+ ext: 'mp4',
91
+ type: FileTypeEnum.VIDEO
92
+ }, {
93
+ ext: 'mkv',
94
+ type: FileTypeEnum.VIDEO
95
+ }, {
96
+ ext: 'mov',
97
+ type: FileTypeEnum.VIDEO
98
+ }, {
99
+ ext: 'avi',
100
+ type: FileTypeEnum.VIDEO
101
+ }, {
102
+ ext: 'webm',
103
+ type: FileTypeEnum.VIDEO
104
+ }, {
105
+ ext: 'flv',
106
+ type: FileTypeEnum.VIDEO
107
+ }, /* ---------- audio ---------- */
108
+ {
109
+ ext: 'mp3',
110
+ type: FileTypeEnum.AUDIO
111
+ }, {
112
+ ext: 'wav',
113
+ type: FileTypeEnum.AUDIO
114
+ }, {
115
+ ext: 'aac',
116
+ type: FileTypeEnum.AUDIO
117
+ }, {
118
+ ext: 'flac',
119
+ type: FileTypeEnum.AUDIO
120
+ }, {
121
+ ext: 'ogg',
122
+ type: FileTypeEnum.AUDIO
123
+ }, {
124
+ ext: 'm4a',
125
+ type: FileTypeEnum.AUDIO
126
+ }, /* ---------- document ---------- */
127
+ {
128
+ ext: 'pdf',
129
+ type: FileTypeEnum.DOCUMENT,
130
+ documentType: DocumentTypeEnum.PDF
131
+ }, {
132
+ ext: 'doc',
133
+ type: FileTypeEnum.DOCUMENT,
134
+ documentType: DocumentTypeEnum.DOC
135
+ }, {
136
+ ext: 'docx',
137
+ type: FileTypeEnum.DOCUMENT,
138
+ documentType: DocumentTypeEnum.DOCX
139
+ }, {
140
+ ext: 'xls',
141
+ type: FileTypeEnum.DOCUMENT,
142
+ documentType: DocumentTypeEnum.XLS
143
+ }, {
144
+ ext: 'xlsx',
145
+ type: FileTypeEnum.DOCUMENT,
146
+ documentType: DocumentTypeEnum.XLSX
147
+ }, {
148
+ ext: 'ppt',
149
+ type: FileTypeEnum.DOCUMENT,
150
+ documentType: DocumentTypeEnum.PPT
151
+ }, {
152
+ ext: 'pptx',
153
+ type: FileTypeEnum.DOCUMENT,
154
+ documentType: DocumentTypeEnum.PPTX
155
+ }, {
156
+ ext: 'txt',
157
+ type: FileTypeEnum.DOCUMENT,
158
+ documentType: DocumentTypeEnum.TXT
159
+ }, {
160
+ ext: 'md',
161
+ type: FileTypeEnum.DOCUMENT
162
+ }, {
163
+ ext: 'csv',
164
+ type: FileTypeEnum.DOCUMENT
165
+ }, {
166
+ ext: 'json',
167
+ type: FileTypeEnum.DOCUMENT
168
+ }, /* ---------- archive ---------- */
169
+ {
170
+ ext: 'zip',
171
+ type: FileTypeEnum.ARCHIVE
172
+ }, {
173
+ ext: 'rar',
174
+ type: FileTypeEnum.ARCHIVE
175
+ }, {
176
+ ext: '7z',
177
+ type: FileTypeEnum.ARCHIVE
178
+ }, {
179
+ ext: 'tar',
180
+ type: FileTypeEnum.ARCHIVE
181
+ }, {
182
+ ext: 'gz',
183
+ type: FileTypeEnum.ARCHIVE
184
+ }];
185
+ var FILE_META_MAP = new Map();
186
+ FILE_META_LIST.forEach(function (item) {
187
+ FILE_META_MAP.set(item.ext, item);
188
+ });
189
+ var DEFAULT_META = {
190
+ ext: '',
191
+ type: FileTypeEnum.OTHER,
192
+ documentType: DocumentTypeEnum.OTHER
193
+ };
194
+ export var CrFileUtil = /*#__PURE__*/function () {
195
+ function CrFileUtil() {
196
+ _classCallCheck(this, CrFileUtil);
197
+ }
198
+ _createClass(CrFileUtil, null, [{
199
+ key: "getExt",
200
+ value:
201
+ /**
202
+ * 提取扩展名(不含 .)
203
+ */
204
+ function getExt(filename) {
205
+ var _filename$trim$split$;
206
+ if (!filename || typeof filename !== 'string') return '';
207
+ return ((_filename$trim$split$ = filename.trim().split('.').pop()) === null || _filename$trim$split$ === void 0 ? void 0 : _filename$trim$split$.toLowerCase()) || '';
208
+ }
209
+
210
+ /**
211
+ * 获取文件完整信息
212
+ */
213
+ }, {
214
+ key: "getMeta",
215
+ value: function getMeta(filename) {
216
+ var ext = this.getExt(filename);
217
+ if (!ext) return DEFAULT_META;
218
+ return FILE_META_MAP.get(ext) || _objectSpread(_objectSpread({}, DEFAULT_META), {}, {
219
+ ext: ext
220
+ });
221
+ }
222
+
223
+ /**
224
+ * 文件类型
225
+ */
226
+ }, {
227
+ key: "getType",
228
+ value: function getType(filename) {
229
+ return this.getMeta(filename).type;
230
+ }
231
+
232
+ /**
233
+ * 文档类型
234
+ */
235
+ }, {
236
+ key: "getDocumentType",
237
+ value: function getDocumentType(filename) {
238
+ return this.getMeta(filename).documentType || DocumentTypeEnum.OTHER;
239
+ }
240
+ }, {
241
+ key: "isImage",
242
+ value: function isImage(filename) {
243
+ return this.getType(filename) === FileTypeEnum.IMAGE;
244
+ }
245
+ }, {
246
+ key: "isVideo",
247
+ value: function isVideo(filename) {
248
+ return this.getType(filename) === FileTypeEnum.VIDEO;
249
+ }
250
+ }, {
251
+ key: "isAudio",
252
+ value: function isAudio(filename) {
253
+ return this.getType(filename) === FileTypeEnum.AUDIO;
254
+ }
255
+ }, {
256
+ key: "isDocument",
257
+ value: function isDocument(filename) {
258
+ return this.getType(filename) === FileTypeEnum.DOCUMENT;
259
+ }
260
+ }, {
261
+ key: "isArchive",
262
+ value: function isArchive(filename) {
263
+ return this.getType(filename) === FileTypeEnum.ARCHIVE;
264
+ }
265
+ }]);
266
+ return CrFileUtil;
267
+ }();
@@ -1,4 +1,6 @@
1
1
  export { default as CrColorUtil } from './color';
2
+ export * from './file';
3
+ export type * from './file';
2
4
  export type * from './eventCenter';
3
5
  export { default as CrEventCenter } from './eventCenter';
4
6
  export type * from './obj';
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as CrColorUtil } from "./color";
2
+ export * from "./file";
2
3
  export { default as CrEventCenter } from "./eventCenter";
3
4
  export { default as CrObjUtil } from "./obj";
4
5
  export { default as CrStorage } from "./storage";
package/dist/esm/util.js CHANGED
@@ -692,8 +692,8 @@ var CrUtil = /*#__PURE__*/function () {
692
692
 
693
693
  /**
694
694
  * 格式化为千分位格式
695
- * @param value
696
- * @returns
695
+ * @param value
696
+ * @returns
697
697
  */
698
698
  }, {
699
699
  key: "formatThousands",
@@ -726,8 +726,8 @@ var CrUtil = /*#__PURE__*/function () {
726
726
 
727
727
  /**
728
728
  * 解析千分位格式
729
- * @param value
730
- * @returns
729
+ * @param value
730
+ * @returns
731
731
  */
732
732
  }, {
733
733
  key: "parseThousands",