@zcrkey/js-utils 0.0.12 → 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/{esm → types}/obj.d.ts +1 -1
- package/dist/{esm → types}/storage.d.ts +1 -1
- package/dist/{cjs → 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 -186
- package/dist/cjs/index.d.ts +0 -10
- package/dist/cjs/index.js +0 -57
- package/dist/cjs/obj.d.ts +0 -20
- package/dist/cjs/obj.js +0 -47
- package/dist/cjs/storage.d.ts +0 -44
- package/dist/cjs/storage.js +0 -118
- 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 -268
- package/dist/esm/index.d.ts +0 -10
- package/dist/esm/index.js +0 -7
- package/dist/esm/obj.js +0 -41
- package/dist/esm/storage.js +0 -130
- package/dist/esm/tree.d.ts +0 -52
- 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
package/dist/cjs/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 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,186 +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
|
-
{
|
|
76
|
-
ext: "pdf",
|
|
77
|
-
type: "document" /* DOCUMENT */,
|
|
78
|
-
documentType: "pdf" /* PDF */
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
ext: "doc",
|
|
82
|
-
type: "document" /* DOCUMENT */,
|
|
83
|
-
documentType: "doc" /* DOC */
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
ext: "docx",
|
|
87
|
-
type: "document" /* DOCUMENT */,
|
|
88
|
-
documentType: "docx" /* DOCX */
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
ext: "xls",
|
|
92
|
-
type: "document" /* DOCUMENT */,
|
|
93
|
-
documentType: "xls" /* XLS */
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
ext: "xlsx",
|
|
97
|
-
type: "document" /* DOCUMENT */,
|
|
98
|
-
documentType: "xlsx" /* XLSX */
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
ext: "ppt",
|
|
102
|
-
type: "document" /* DOCUMENT */,
|
|
103
|
-
documentType: "ppt" /* PPT */
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
ext: "pptx",
|
|
107
|
-
type: "document" /* DOCUMENT */,
|
|
108
|
-
documentType: "pptx" /* PPTX */
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
ext: "txt",
|
|
112
|
-
type: "document" /* DOCUMENT */,
|
|
113
|
-
documentType: "txt" /* TXT */
|
|
114
|
-
},
|
|
115
|
-
{ ext: "md", type: "document" /* DOCUMENT */ },
|
|
116
|
-
{ ext: "csv", type: "document" /* DOCUMENT */ },
|
|
117
|
-
{ ext: "json", type: "document" /* DOCUMENT */ },
|
|
118
|
-
/* ---------- archive ---------- */
|
|
119
|
-
{ ext: "zip", type: "archive" /* ARCHIVE */ },
|
|
120
|
-
{ ext: "rar", type: "archive" /* ARCHIVE */ },
|
|
121
|
-
{ ext: "7z", type: "archive" /* ARCHIVE */ },
|
|
122
|
-
{ ext: "tar", type: "archive" /* ARCHIVE */ },
|
|
123
|
-
{ ext: "gz", type: "archive" /* ARCHIVE */ }
|
|
124
|
-
];
|
|
125
|
-
var FILE_META_MAP = /* @__PURE__ */ new Map();
|
|
126
|
-
FILE_META_LIST.forEach((item) => {
|
|
127
|
-
FILE_META_MAP.set(item.ext, item);
|
|
128
|
-
});
|
|
129
|
-
var DEFAULT_META = {
|
|
130
|
-
ext: "",
|
|
131
|
-
type: "other" /* OTHER */,
|
|
132
|
-
documentType: "other" /* OTHER */
|
|
133
|
-
};
|
|
134
|
-
var CrFileUtil = class {
|
|
135
|
-
/**
|
|
136
|
-
* 提取扩展名(不含 .)
|
|
137
|
-
*/
|
|
138
|
-
static getExt(filename) {
|
|
139
|
-
var _a;
|
|
140
|
-
if (!filename || typeof filename !== "string")
|
|
141
|
-
return "";
|
|
142
|
-
return ((_a = filename.trim().split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* 获取文件完整信息
|
|
146
|
-
*/
|
|
147
|
-
static getMeta(filename) {
|
|
148
|
-
const ext = this.getExt(filename);
|
|
149
|
-
if (!ext)
|
|
150
|
-
return DEFAULT_META;
|
|
151
|
-
return FILE_META_MAP.get(ext) || { ...DEFAULT_META, ext };
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* 文件类型
|
|
155
|
-
*/
|
|
156
|
-
static getType(filename) {
|
|
157
|
-
return this.getMeta(filename).type;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* 文档类型
|
|
161
|
-
*/
|
|
162
|
-
static getDocumentType(filename) {
|
|
163
|
-
return this.getMeta(filename).documentType || "other" /* OTHER */;
|
|
164
|
-
}
|
|
165
|
-
static isImage(filename) {
|
|
166
|
-
return this.getType(filename) === "image" /* IMAGE */;
|
|
167
|
-
}
|
|
168
|
-
static isVideo(filename) {
|
|
169
|
-
return this.getType(filename) === "video" /* VIDEO */;
|
|
170
|
-
}
|
|
171
|
-
static isAudio(filename) {
|
|
172
|
-
return this.getType(filename) === "audio" /* AUDIO */;
|
|
173
|
-
}
|
|
174
|
-
static isDocument(filename) {
|
|
175
|
-
return this.getType(filename) === "document" /* DOCUMENT */;
|
|
176
|
-
}
|
|
177
|
-
static isArchive(filename) {
|
|
178
|
-
return this.getType(filename) === "archive" /* ARCHIVE */;
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
182
|
-
0 && (module.exports = {
|
|
183
|
-
CrFileUtil,
|
|
184
|
-
DocumentTypeEnum,
|
|
185
|
-
FileTypeEnum
|
|
186
|
-
});
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as CrColorUtil } from './color';
|
|
2
|
-
export type * from './eventCenter';
|
|
3
|
-
export { default as CrEventCenter } from './eventCenter';
|
|
4
|
-
export * from './file';
|
|
5
|
-
export type * from './obj';
|
|
6
|
-
export { default as CrObjUtil } from './obj';
|
|
7
|
-
export { default as CrStorage } from './storage';
|
|
8
|
-
export type * from './tree';
|
|
9
|
-
export { default as CrTreeUtil } from './tree';
|
|
10
|
-
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
|
-
var import_eventCenter = __toESM(require("./eventCenter"));
|
|
43
|
-
__reExport(src_exports, require("./file"), module.exports);
|
|
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,20 +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
|
-
/**
|
|
13
|
-
* 根据字段路径设置对象值(可变更新,直接修改原对象)
|
|
14
|
-
* @param obj 要修改的原对象 { 'a': [{ 'b': { 'c': 3 } }] }
|
|
15
|
-
* @param propertyPath 路径 'a[0].b.c' | ['a', '0', 'b', 'c']
|
|
16
|
-
* @param value 要设置的值
|
|
17
|
-
* @returns 修改后的原对象(和入参obj是同一个引用)
|
|
18
|
-
*/
|
|
19
|
-
static setValueByPath(obj: Record<string | number | symbol, any>, propertyPath: PropertyPath, value: any): Record<string | number | symbol, any>;
|
|
20
|
-
}
|
package/dist/cjs/obj.js
DELETED
|
@@ -1,47 +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
|
-
/**
|
|
38
|
-
* 根据字段路径设置对象值(可变更新,直接修改原对象)
|
|
39
|
-
* @param obj 要修改的原对象 { 'a': [{ 'b': { 'c': 3 } }] }
|
|
40
|
-
* @param propertyPath 路径 'a[0].b.c' | ['a', '0', 'b', 'c']
|
|
41
|
-
* @param value 要设置的值
|
|
42
|
-
* @returns 修改后的原对象(和入参obj是同一个引用)
|
|
43
|
-
*/
|
|
44
|
-
static setValueByPath(obj, propertyPath, value) {
|
|
45
|
-
return (0, import_lodash.set)(obj, propertyPath, value);
|
|
46
|
-
}
|
|
47
|
-
};
|
package/dist/cjs/storage.d.ts
DELETED
|
@@ -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
|
-
}
|
package/dist/cjs/storage.js
DELETED
|
@@ -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
|
-
};
|