@zcrkey/js-utils 0.0.11 → 0.0.15
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/index.cjs.js +23 -0
- package/dist/index.es.js +5943 -0
- package/dist/index.umd.js +23 -0
- package/dist/types/color.d.ts +303 -0
- package/dist/{cjs → types}/eventCenter.d.ts +5 -5
- package/dist/types/file.d.ts +481 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/obj.d.ts +20 -0
- package/dist/{esm → types}/storage.d.ts +1 -1
- package/dist/{esm → types}/tree.d.ts +1 -1
- package/dist/{cjs → types}/util.d.ts +27 -7
- package/package.json +14 -19
- package/dist/cjs/color.d.ts +0 -195
- package/dist/cjs/color.js +0 -357
- package/dist/cjs/eventCenter.js +0 -120
- package/dist/cjs/file.d.ts +0 -71
- package/dist/cjs/file.js +0 -154
- package/dist/cjs/index.d.ts +0 -11
- package/dist/cjs/index.js +0 -57
- package/dist/cjs/obj.d.ts +0 -12
- package/dist/cjs/obj.js +0 -37
- package/dist/cjs/storage.d.ts +0 -44
- package/dist/cjs/storage.js +0 -118
- package/dist/cjs/tree.d.ts +0 -52
- package/dist/cjs/tree.js +0 -179
- package/dist/cjs/util.js +0 -607
- package/dist/esm/color.d.ts +0 -195
- package/dist/esm/color.js +0 -500
- package/dist/esm/eventCenter.d.ts +0 -59
- package/dist/esm/eventCenter.js +0 -134
- package/dist/esm/file.d.ts +0 -71
- package/dist/esm/file.js +0 -267
- package/dist/esm/index.d.ts +0 -11
- package/dist/esm/index.js +0 -7
- package/dist/esm/obj.d.ts +0 -12
- package/dist/esm/obj.js +0 -28
- package/dist/esm/storage.js +0 -130
- package/dist/esm/tree.js +0 -214
- package/dist/esm/util.d.ts +0 -221
- package/dist/esm/util.js +0 -744
- package/dist/umd/index.umd.js +0 -1
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export type TSubscribers = {
|
|
2
|
-
key: string;
|
|
3
|
-
listeners: Array<(...args: any) => void>;
|
|
4
|
-
};
|
|
5
|
-
export type TSubscription = {
|
|
6
|
-
key: string;
|
|
7
|
-
listener: (...args: any) => void;
|
|
8
|
-
remove: () => void;
|
|
9
|
-
};
|
|
10
|
-
export default class CrEventCenter {
|
|
11
|
-
/**
|
|
12
|
-
* 储存订阅者
|
|
13
|
-
*/
|
|
14
|
-
static subscribers: TSubscribers[];
|
|
15
|
-
/**
|
|
16
|
-
* 新增订阅
|
|
17
|
-
*
|
|
18
|
-
* @param {*} key 名称
|
|
19
|
-
* @param {*} listener 执行函数
|
|
20
|
-
* @returns 订阅信息
|
|
21
|
-
* @example
|
|
22
|
-
this.subscription = CrEventCenter.on('名称', (参数) => {});
|
|
23
|
-
*/
|
|
24
|
-
static on(key: string, listener: (...args: any) => void): TSubscription;
|
|
25
|
-
/**
|
|
26
|
-
* 移除订阅
|
|
27
|
-
*
|
|
28
|
-
* @param {*} subscription
|
|
29
|
-
* @param {*} type 'all'
|
|
30
|
-
* @example
|
|
31
|
-
CrEventCenter.off(this.subscription);
|
|
32
|
-
*/
|
|
33
|
-
static off(subscription: TSubscription, type?: 'all'): void;
|
|
34
|
-
/**
|
|
35
|
-
* 派发事件
|
|
36
|
-
*
|
|
37
|
-
* @param {*} key 名称
|
|
38
|
-
* @param {*} args 其余参数
|
|
39
|
-
* @example
|
|
40
|
-
CrEventCenter.emit('名称', 参数数据);
|
|
41
|
-
*/
|
|
42
|
-
static emit(key: string, ...args: any): void;
|
|
43
|
-
/**
|
|
44
|
-
* 查找事件
|
|
45
|
-
*
|
|
46
|
-
* @param {*} key 名称
|
|
47
|
-
* @example
|
|
48
|
-
let subscriber = CrEventCenter.find('名称');
|
|
49
|
-
*/
|
|
50
|
-
static find(key: string): TSubscribers | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* 清理所有事件
|
|
53
|
-
*
|
|
54
|
-
* @memberof CrEventCenter
|
|
55
|
-
* @example
|
|
56
|
-
CrEventCenter.clear();
|
|
57
|
-
*/
|
|
58
|
-
static clear(): void;
|
|
59
|
-
}
|
package/dist/esm/eventCenter.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
-
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); } }
|
|
4
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
-
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; }
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
-
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); }
|
|
8
|
-
var CrEventCenter = /*#__PURE__*/function () {
|
|
9
|
-
function CrEventCenter() {
|
|
10
|
-
_classCallCheck(this, CrEventCenter);
|
|
11
|
-
}
|
|
12
|
-
_createClass(CrEventCenter, null, [{
|
|
13
|
-
key: "on",
|
|
14
|
-
value:
|
|
15
|
-
/**
|
|
16
|
-
* 新增订阅
|
|
17
|
-
*
|
|
18
|
-
* @param {*} key 名称
|
|
19
|
-
* @param {*} listener 执行函数
|
|
20
|
-
* @returns 订阅信息
|
|
21
|
-
* @example
|
|
22
|
-
this.subscription = CrEventCenter.on('名称', (参数) => {});
|
|
23
|
-
*/
|
|
24
|
-
function on(key, listener) {
|
|
25
|
-
var _this = this;
|
|
26
|
-
var subscriber = this.subscribers.find(function (item) {
|
|
27
|
-
return item.key == key;
|
|
28
|
-
});
|
|
29
|
-
if (subscriber) {
|
|
30
|
-
subscriber.listeners.push(listener);
|
|
31
|
-
} else {
|
|
32
|
-
this.subscribers.push({
|
|
33
|
-
key: key,
|
|
34
|
-
listeners: [listener]
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
var subscription = {
|
|
38
|
-
key: key,
|
|
39
|
-
listener: listener,
|
|
40
|
-
remove: function remove() {
|
|
41
|
-
_this.off(subscription);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
return subscription;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 移除订阅
|
|
49
|
-
*
|
|
50
|
-
* @param {*} subscription
|
|
51
|
-
* @param {*} type 'all'
|
|
52
|
-
* @example
|
|
53
|
-
CrEventCenter.off(this.subscription);
|
|
54
|
-
*/
|
|
55
|
-
}, {
|
|
56
|
-
key: "off",
|
|
57
|
-
value: function off(subscription, type) {
|
|
58
|
-
var index = this.subscribers.findIndex(function (item) {
|
|
59
|
-
return item.key == subscription.key;
|
|
60
|
-
});
|
|
61
|
-
if (index > -1) {
|
|
62
|
-
if (type == 'all') {
|
|
63
|
-
this.subscribers.splice(index, 1);
|
|
64
|
-
} else {
|
|
65
|
-
var subscriber = this.subscribers[index];
|
|
66
|
-
var _index = subscriber.listeners.findIndex(function (item) {
|
|
67
|
-
return item == subscription.listener;
|
|
68
|
-
});
|
|
69
|
-
if (_index > -1) {
|
|
70
|
-
subscriber.listeners.splice(_index, 1);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 派发事件
|
|
78
|
-
*
|
|
79
|
-
* @param {*} key 名称
|
|
80
|
-
* @param {*} args 其余参数
|
|
81
|
-
* @example
|
|
82
|
-
CrEventCenter.emit('名称', 参数数据);
|
|
83
|
-
*/
|
|
84
|
-
}, {
|
|
85
|
-
key: "emit",
|
|
86
|
-
value: function emit(key) {
|
|
87
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
88
|
-
args[_key - 1] = arguments[_key];
|
|
89
|
-
}
|
|
90
|
-
var subscriber = this.subscribers.find(function (item) {
|
|
91
|
-
return item.key == key;
|
|
92
|
-
});
|
|
93
|
-
if (subscriber && subscriber.listeners && subscriber.listeners.length > 0) {
|
|
94
|
-
subscriber.listeners.forEach(function (listener) {
|
|
95
|
-
listener.apply(void 0, args);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 查找事件
|
|
102
|
-
*
|
|
103
|
-
* @param {*} key 名称
|
|
104
|
-
* @example
|
|
105
|
-
let subscriber = CrEventCenter.find('名称');
|
|
106
|
-
*/
|
|
107
|
-
}, {
|
|
108
|
-
key: "find",
|
|
109
|
-
value: function find(key) {
|
|
110
|
-
return this.subscribers.find(function (item) {
|
|
111
|
-
return item.key == key;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* 清理所有事件
|
|
117
|
-
*
|
|
118
|
-
* @memberof CrEventCenter
|
|
119
|
-
* @example
|
|
120
|
-
CrEventCenter.clear();
|
|
121
|
-
*/
|
|
122
|
-
}, {
|
|
123
|
-
key: "clear",
|
|
124
|
-
value: function clear() {
|
|
125
|
-
this.subscribers.length = 0;
|
|
126
|
-
}
|
|
127
|
-
}]);
|
|
128
|
-
return CrEventCenter;
|
|
129
|
-
}();
|
|
130
|
-
/**
|
|
131
|
-
* 储存订阅者
|
|
132
|
-
*/
|
|
133
|
-
_defineProperty(CrEventCenter, "subscribers", []);
|
|
134
|
-
export { CrEventCenter as default };
|
package/dist/esm/file.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/esm/file.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
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
|
-
}();
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { default as CrColorUtil } from './color';
|
|
2
|
-
export * from './file';
|
|
3
|
-
export type * from './file';
|
|
4
|
-
export type * from './eventCenter';
|
|
5
|
-
export { default as CrEventCenter } from './eventCenter';
|
|
6
|
-
export type * from './obj';
|
|
7
|
-
export { default as CrObjUtil } from './obj';
|
|
8
|
-
export { default as CrStorage } from './storage';
|
|
9
|
-
export type * from './tree';
|
|
10
|
-
export { default as CrTreeUtil } from './tree';
|
|
11
|
-
export { default as CrUtil } from './util';
|
package/dist/esm/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as CrColorUtil } from "./color";
|
|
2
|
-
export * from "./file";
|
|
3
|
-
export { default as CrEventCenter } from "./eventCenter";
|
|
4
|
-
export { default as CrObjUtil } from "./obj";
|
|
5
|
-
export { default as CrStorage } from "./storage";
|
|
6
|
-
export { default as CrTreeUtil } from "./tree";
|
|
7
|
-
export { default as CrUtil } from "./util";
|
package/dist/esm/obj.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PropertyPath } from 'lodash';
|
|
2
|
-
export type { PropertyPath };
|
|
3
|
-
export default class CrObjUtil {
|
|
4
|
-
/**
|
|
5
|
-
* 根据字段路径获取对象值
|
|
6
|
-
* @param obj { 'a': [{ 'b': { 'c': 3 } }] }
|
|
7
|
-
* @param path 'a[0].b.c' | ['a', '0', 'b', 'c']
|
|
8
|
-
* @param defaultValue 找不到时返回的默认值
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
static getValueByPath(obj: Record<string | number | symbol, any>, propertyPath: PropertyPath, defaultValue?: any): any;
|
|
12
|
-
}
|
package/dist/esm/obj.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
-
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); } }
|
|
4
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
-
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); }
|
|
7
|
-
import { get } from 'lodash';
|
|
8
|
-
var CrObjUtil = /*#__PURE__*/function () {
|
|
9
|
-
function CrObjUtil() {
|
|
10
|
-
_classCallCheck(this, CrObjUtil);
|
|
11
|
-
}
|
|
12
|
-
_createClass(CrObjUtil, null, [{
|
|
13
|
-
key: "getValueByPath",
|
|
14
|
-
value:
|
|
15
|
-
/**
|
|
16
|
-
* 根据字段路径获取对象值
|
|
17
|
-
* @param obj { 'a': [{ 'b': { 'c': 3 } }] }
|
|
18
|
-
* @param path 'a[0].b.c' | ['a', '0', 'b', 'c']
|
|
19
|
-
* @param defaultValue 找不到时返回的默认值
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
function getValueByPath(obj, propertyPath, defaultValue) {
|
|
23
|
-
return get(obj, propertyPath, defaultValue);
|
|
24
|
-
}
|
|
25
|
-
}]);
|
|
26
|
-
return CrObjUtil;
|
|
27
|
-
}();
|
|
28
|
-
export { CrObjUtil as default };
|