@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.
@@ -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/cjs/file.js DELETED
@@ -1,154 +0,0 @@
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,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/cjs/index.js DELETED
@@ -1,57 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- CrColorUtil: () => import_color.default,
34
- CrEventCenter: () => import_eventCenter.default,
35
- CrObjUtil: () => import_obj.default,
36
- CrStorage: () => import_storage.default,
37
- CrTreeUtil: () => import_tree.default,
38
- CrUtil: () => import_util.default
39
- });
40
- module.exports = __toCommonJS(src_exports);
41
- var import_color = __toESM(require("./color"));
42
- __reExport(src_exports, require("./file"), module.exports);
43
- var import_eventCenter = __toESM(require("./eventCenter"));
44
- var import_obj = __toESM(require("./obj"));
45
- var import_storage = __toESM(require("./storage"));
46
- var import_tree = __toESM(require("./tree"));
47
- var import_util = __toESM(require("./util"));
48
- // Annotate the CommonJS export names for ESM import in node:
49
- 0 && (module.exports = {
50
- CrColorUtil,
51
- CrEventCenter,
52
- CrObjUtil,
53
- CrStorage,
54
- CrTreeUtil,
55
- CrUtil,
56
- ...require("./file")
57
- });
package/dist/cjs/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/cjs/obj.js DELETED
@@ -1,37 +0,0 @@
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/obj.ts
20
- var obj_exports = {};
21
- __export(obj_exports, {
22
- default: () => CrObjUtil
23
- });
24
- module.exports = __toCommonJS(obj_exports);
25
- var import_lodash = require("lodash");
26
- var CrObjUtil = class {
27
- /**
28
- * 根据字段路径获取对象值
29
- * @param obj { 'a': [{ 'b': { 'c': 3 } }] }
30
- * @param path 'a[0].b.c' | ['a', '0', 'b', 'c']
31
- * @param defaultValue 找不到时返回的默认值
32
- * @returns
33
- */
34
- static getValueByPath(obj, propertyPath, defaultValue) {
35
- return (0, import_lodash.get)(obj, propertyPath, defaultValue);
36
- }
37
- };
@@ -1,44 +0,0 @@
1
- export default class CrStorage {
2
- /**
3
- * 设置本地存储
4
- * @param key
5
- * @param data
6
- */
7
- static setLocalItem(key: string, data: any): void;
8
- /**
9
- * 获取本地存储
10
- * @param key
11
- * @returns
12
- */
13
- static getLocalItem<T = any>(key: string): T | null;
14
- /**
15
- * 清除某个本地存储
16
- * @param key
17
- */
18
- static removeLocalItem(key: string): void;
19
- /**
20
- * 清除所有本地存储
21
- */
22
- static clearLocal(): void;
23
- /**
24
- * 设置会话存储
25
- * @param key
26
- * @param data
27
- */
28
- static setSessionItem(key: string, data: any): void;
29
- /**
30
- * 获取会话存储
31
- * @param key
32
- * @returns
33
- */
34
- static getSessionItem<T = any>(key: string): T | null;
35
- /**
36
- * 清除某个会话存储
37
- * @param key
38
- */
39
- static removeSessionItem(key: string): void;
40
- /**
41
- * 清除所有会话存储
42
- */
43
- static clearSession(): void;
44
- }
@@ -1,118 +0,0 @@
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/storage.ts
20
- var storage_exports = {};
21
- __export(storage_exports, {
22
- default: () => CrStorage
23
- });
24
- module.exports = __toCommonJS(storage_exports);
25
- var CrStorage = class {
26
- /**
27
- * 设置本地存储
28
- * @param key
29
- * @param data
30
- */
31
- static setLocalItem(key, data) {
32
- try {
33
- localStorage.setItem(key, JSON.stringify(data));
34
- } catch (error) {
35
- console.warn(`setLocalItem:${key}:${error}`);
36
- }
37
- }
38
- /**
39
- * 获取本地存储
40
- * @param key
41
- * @returns
42
- */
43
- static getLocalItem(key) {
44
- const str = localStorage.getItem(key);
45
- if (str) {
46
- if (str === "undefined") {
47
- return null;
48
- }
49
- try {
50
- return JSON.parse(str);
51
- } catch (error) {
52
- console.warn(`getLocalItem:${key}:${error}`);
53
- return null;
54
- }
55
- } else {
56
- return null;
57
- }
58
- }
59
- /**
60
- * 清除某个本地存储
61
- * @param key
62
- */
63
- static removeLocalItem(key) {
64
- localStorage.removeItem(key);
65
- }
66
- /**
67
- * 清除所有本地存储
68
- */
69
- static clearLocal() {
70
- localStorage.clear();
71
- }
72
- /**
73
- * 设置会话存储
74
- * @param key
75
- * @param data
76
- */
77
- static setSessionItem(key, data) {
78
- try {
79
- sessionStorage.setItem(key, JSON.stringify(data));
80
- } catch (error) {
81
- console.warn(`setSessionItem:${key}:${error}`);
82
- }
83
- }
84
- /**
85
- * 获取会话存储
86
- * @param key
87
- * @returns
88
- */
89
- static getSessionItem(key) {
90
- const str = sessionStorage.getItem(key);
91
- if (str) {
92
- if (str === "undefined") {
93
- return null;
94
- }
95
- try {
96
- return JSON.parse(str);
97
- } catch (error) {
98
- console.warn(`getSessionItem:${key}:${error}`);
99
- return null;
100
- }
101
- } else {
102
- return null;
103
- }
104
- }
105
- /**
106
- * 清除某个会话存储
107
- * @param key
108
- */
109
- static removeSessionItem(key) {
110
- sessionStorage.removeItem(key);
111
- }
112
- /**
113
- * 清除所有会话存储
114
- */
115
- static clearSession() {
116
- sessionStorage.clear();
117
- }
118
- };
@@ -1,52 +0,0 @@
1
- export default class CrTreeUtil {
2
- /**
3
- * 列表数据转树形数据
4
- * @param list
5
- * @param options
6
- * @param options.idField 默认值 id
7
- * @param options.parentIdField 默认值 parentId
8
- * @param options.childrenField 默认值 children
9
- * @param options.isCloneDeep 是否需要深拷贝, 默认值为 true
10
- * @param options.getData 处理数据
11
- * @returns
12
- */
13
- static listToTree<T extends Record<string, any>>(list: T[], options?: {
14
- idField?: string;
15
- parentIdField?: string;
16
- childrenField?: string;
17
- isCloneDeep?: boolean;
18
- getData?: (item: T) => any;
19
- }): any[];
20
- /**
21
- * 树形数据转列表数据
22
- * @param tree
23
- * @param options
24
- * @param options.idField 默认值 id
25
- * @param options.parentIdField 默认值 parentId
26
- * @param options.childrenField 默认值 children
27
- * @param options.rootParentValue 根节点的父值,默认值 null
28
- * @returns
29
- */
30
- static treeToList<T extends Record<string, any>>(tree: T[], options?: {
31
- idField?: string;
32
- parentIdField?: string;
33
- childrenField?: string;
34
- rootParentValue?: any;
35
- }): T[];
36
- /**
37
- * 获取扁平化父数据(包含自身)
38
- * @param listData
39
- * @param value
40
- * @param settings
41
- * @param settings.valueField 默认值 value
42
- * @param settings.idField 默认值 id
43
- * @param settings.parentIdField 默认值 parentId
44
- * @param settings.getData 过滤数据
45
- */
46
- static getFlatParentDatas<T = any, R extends Record<string, any> = any>(listData: R[], value: number | string, settings?: {
47
- valueField?: string;
48
- idField?: string;
49
- parentIdField?: string;
50
- getData?: (item: R) => T;
51
- }): T[];
52
- }