@vef-framework/shared 1.0.134 → 2.0.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/README +15 -0
- package/dist/cjs/color/color-ops.cjs +76 -0
- package/dist/cjs/color/index.cjs +24 -0
- package/dist/cjs/color/name.cjs +49 -0
- package/dist/cjs/color/palette.cjs +126 -0
- package/dist/cjs/constants/color-names.cjs +1580 -0
- package/dist/cjs/constants/color-palettes.cjs +372 -0
- package/dist/cjs/constants/index.cjs +14 -0
- package/dist/cjs/index.cjs +339 -0
- package/dist/cjs/types/color.cjs +3 -0
- package/dist/cjs/types/common.cjs +3 -0
- package/dist/cjs/types/deep-keys.cjs +3 -0
- package/dist/cjs/types/index.cjs +7 -0
- package/dist/cjs/utils/chrono.cjs +139 -0
- package/dist/cjs/utils/equal.cjs +175 -0
- package/dist/cjs/utils/error.cjs +60 -0
- package/dist/cjs/utils/event.cjs +62 -0
- package/dist/cjs/utils/format.cjs +31 -0
- package/dist/cjs/utils/function.cjs +49 -0
- package/dist/cjs/utils/id.cjs +38 -0
- package/dist/cjs/utils/index.cjs +86 -0
- package/dist/cjs/utils/key.cjs +34 -0
- package/dist/cjs/utils/lib.cjs +234 -0
- package/dist/cjs/utils/object.cjs +20 -0
- package/dist/cjs/utils/path.cjs +63 -0
- package/dist/cjs/utils/pinyin.cjs +53 -0
- package/dist/cjs/utils/security.cjs +44 -0
- package/dist/cjs/utils/string.cjs +13 -0
- package/dist/cjs/utils/task.cjs +17 -0
- package/dist/cjs/utils/tree.cjs +262 -0
- package/dist/cjs/utils/zod.cjs +14 -0
- package/dist/es/color/color-ops.js +62 -0
- package/dist/es/color/index.js +4 -0
- package/dist/es/color/name.js +45 -0
- package/dist/es/color/palette.js +122 -0
- package/dist/es/constants/color-names.js +1575 -0
- package/dist/es/constants/color-palettes.js +367 -0
- package/dist/es/constants/index.js +3 -0
- package/dist/es/index.js +30 -0
- package/dist/es/types/color.js +1 -0
- package/dist/es/types/common.js +1 -0
- package/dist/es/types/deep-keys.js +1 -0
- package/dist/es/types/index.js +4 -0
- package/dist/es/utils/chrono.js +121 -0
- package/dist/es/utils/equal.js +170 -0
- package/dist/es/utils/error.js +33 -0
- package/dist/es/utils/event.js +57 -0
- package/dist/es/utils/format.js +26 -0
- package/dist/es/utils/function.js +41 -0
- package/dist/es/utils/id.js +34 -0
- package/dist/es/utils/index.js +18 -0
- package/dist/es/utils/key.js +30 -0
- package/dist/es/utils/lib.js +10 -0
- package/dist/es/utils/object.js +16 -0
- package/dist/es/utils/path.js +49 -0
- package/dist/es/utils/pinyin.js +47 -0
- package/dist/es/utils/security.js +39 -0
- package/dist/es/utils/string.js +9 -0
- package/dist/es/utils/task.js +13 -0
- package/dist/es/utils/tree.js +252 -0
- package/dist/es/utils/zod.js +6 -0
- package/dist/types/color/color-ops.d.ts +84 -0
- package/dist/types/color/index.d.ts +3 -0
- package/dist/types/color/name.d.ts +7 -0
- package/dist/types/color/palette.d.ts +8 -0
- package/dist/types/constants/color-names.d.ts +11 -0
- package/dist/types/constants/color-palettes.d.ts +823 -0
- package/dist/types/constants/index.d.ts +2 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/types/color.d.ts +73 -0
- package/dist/types/types/common.d.ts +25 -0
- package/dist/types/types/deep-keys.d.ts +9 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/utils/chrono.d.ts +162 -0
- package/dist/types/utils/equal.d.ts +16 -0
- package/dist/types/utils/error.d.ts +38 -0
- package/dist/types/utils/event.d.ts +68 -0
- package/dist/types/utils/format.d.ts +33 -0
- package/dist/types/utils/function.d.ts +59 -0
- package/{types → dist/types/utils}/id.d.ts +2 -2
- package/dist/types/utils/index.d.ts +17 -0
- package/dist/types/utils/key.d.ts +7 -0
- package/dist/types/utils/lib.d.ts +5 -0
- package/dist/types/utils/object.d.ts +9 -0
- package/dist/types/utils/path.d.ts +76 -0
- package/dist/types/utils/pinyin.d.ts +41 -0
- package/dist/types/utils/security.d.ts +18 -0
- package/dist/types/utils/string.d.ts +7 -0
- package/dist/types/utils/task.d.ts +6 -0
- package/dist/types/utils/tree.d.ts +208 -0
- package/dist/types/utils/zod.d.ts +1 -0
- package/package.json +58 -56
- package/README.md +0 -25
- package/cjs/color.cjs +0 -2
- package/cjs/constants.cjs +0 -2
- package/cjs/context.cjs +0 -2
- package/cjs/dom.cjs +0 -2
- package/cjs/error.cjs +0 -2
- package/cjs/event.cjs +0 -2
- package/cjs/expression.cjs +0 -2
- package/cjs/function.cjs +0 -2
- package/cjs/id.cjs +0 -2
- package/cjs/index.cjs +0 -2
- package/cjs/json.cjs +0 -2
- package/cjs/module.cjs +0 -2
- package/cjs/path.cjs +0 -2
- package/cjs/pinyin.cjs +0 -2
- package/cjs/security.cjs +0 -2
- package/cjs/store.cjs +0 -2
- package/cjs/styles.cjs +0 -2
- package/cjs/temporal.cjs +0 -2
- package/cjs/theme-variables.cjs +0 -2
- package/cjs/types.cjs +0 -2
- package/cjs/utils.cjs +0 -2
- package/cjs/validation.cjs +0 -2
- package/cjs/yaml.cjs +0 -2
- package/cjs/zod.cjs +0 -2
- package/esm/color.js +0 -2
- package/esm/constants.js +0 -2
- package/esm/context.js +0 -2
- package/esm/dom.js +0 -2
- package/esm/error.js +0 -2
- package/esm/event.js +0 -2
- package/esm/expression.js +0 -2
- package/esm/function.js +0 -2
- package/esm/id.js +0 -2
- package/esm/index.js +0 -2
- package/esm/json.js +0 -2
- package/esm/module.js +0 -2
- package/esm/path.js +0 -2
- package/esm/pinyin.js +0 -2
- package/esm/security.js +0 -2
- package/esm/store.js +0 -2
- package/esm/styles.js +0 -2
- package/esm/temporal.js +0 -2
- package/esm/theme-variables.js +0 -2
- package/esm/types.js +0 -2
- package/esm/utils.js +0 -2
- package/esm/validation.js +0 -2
- package/esm/yaml.js +0 -2
- package/esm/zod.js +0 -2
- package/types/color.d.ts +0 -7
- package/types/constants.d.ts +0 -28
- package/types/context.d.ts +0 -21
- package/types/dom.d.ts +0 -9
- package/types/error.d.ts +0 -16
- package/types/event.d.ts +0 -6
- package/types/expression.d.ts +0 -23
- package/types/function.d.ts +0 -8
- package/types/index.d.ts +0 -23
- package/types/json.d.ts +0 -7
- package/types/module.d.ts +0 -7
- package/types/path.d.ts +0 -43
- package/types/pinyin.d.ts +0 -14
- package/types/security.d.ts +0 -16
- package/types/store.d.ts +0 -78
- package/types/styles.d.ts +0 -21
- package/types/temporal.d.ts +0 -18
- package/types/theme-variables.d.ts +0 -348
- package/types/types.d.ts +0 -905
- package/types/utils.d.ts +0 -77
- package/types/validation.d.ts +0 -38
- package/types/yaml.d.ts +0 -7
- package/types/zod.d.ts +0 -6
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
function isShallowEqual(value1, value2) {
|
|
3
|
+
if (Object.is(value1, value2)) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
if (typeof value1 !== "object" || value1 === null || typeof value2 !== "object" || value2 === null) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (value1 instanceof Map && value2 instanceof Map) {
|
|
10
|
+
if (value1.size !== value2.size) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
for (const [k, v] of value1) {
|
|
14
|
+
if (!value2.has(k) || !Object.is(v, value2.get(k))) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (value1 instanceof Set && value2 instanceof Set) {
|
|
21
|
+
if (value1.size !== value2.size) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
for (const v of value1) {
|
|
25
|
+
if (!value2.has(v)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const isArray1 = Array.isArray(value1);
|
|
32
|
+
const isArray2 = Array.isArray(value2);
|
|
33
|
+
if (isArray1 !== isArray2) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (value1.constructor !== value2.constructor) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const keysA = Object.keys(value1);
|
|
40
|
+
if (keysA.length !== Object.keys(value2).length) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
for (const element of keysA) {
|
|
44
|
+
if (!Object.hasOwn(value2, element) || !Object.is(value1[element], value2[element])) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
function isDeepEqual(value1, value2) {
|
|
51
|
+
const { valueOf, toString } = Object.prototype;
|
|
52
|
+
const visited = /* @__PURE__ */ new WeakMap();
|
|
53
|
+
const compareValues = (currentFirst, currentSecond) => {
|
|
54
|
+
if (currentFirst === currentSecond) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (typeof currentFirst !== "object" || typeof currentSecond !== "object" || !currentFirst || !currentSecond) {
|
|
58
|
+
return currentFirst !== currentFirst && currentSecond !== currentSecond;
|
|
59
|
+
}
|
|
60
|
+
if (Object.getPrototypeOf(currentFirst) !== Object.getPrototypeOf(currentSecond)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const { constructor } = currentFirst;
|
|
64
|
+
if (constructor === Date) {
|
|
65
|
+
return currentFirst.getTime() === currentSecond.getTime();
|
|
66
|
+
}
|
|
67
|
+
if (constructor === RegExp) {
|
|
68
|
+
const firstRegex = currentFirst;
|
|
69
|
+
const secondRegex = currentSecond;
|
|
70
|
+
return firstRegex.source === secondRegex.source && firstRegex.flags === secondRegex.flags;
|
|
71
|
+
}
|
|
72
|
+
if (constructor === Set) {
|
|
73
|
+
const firstSet = currentFirst;
|
|
74
|
+
const secondSet = currentSecond;
|
|
75
|
+
if (firstSet.size !== secondSet.size) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
for (const value of firstSet) {
|
|
79
|
+
let found = false;
|
|
80
|
+
for (const secondValue of secondSet) {
|
|
81
|
+
if (compareValues(value, secondValue)) {
|
|
82
|
+
found = true;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!found) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (constructor === ArrayBuffer) {
|
|
93
|
+
const firstView = new DataView(currentFirst);
|
|
94
|
+
const secondView = new DataView(currentSecond);
|
|
95
|
+
return compareValues(firstView, secondView);
|
|
96
|
+
}
|
|
97
|
+
if (constructor === DataView || ArrayBuffer.isView(currentFirst)) {
|
|
98
|
+
let firstView;
|
|
99
|
+
let secondView;
|
|
100
|
+
if (constructor === DataView) {
|
|
101
|
+
firstView = currentFirst;
|
|
102
|
+
secondView = currentSecond;
|
|
103
|
+
} else {
|
|
104
|
+
const firstTyped = currentFirst;
|
|
105
|
+
const secondTyped = currentSecond;
|
|
106
|
+
firstView = new DataView(firstTyped.buffer, firstTyped.byteOffset, firstTyped.byteLength);
|
|
107
|
+
secondView = new DataView(secondTyped.buffer, secondTyped.byteOffset, secondTyped.byteLength);
|
|
108
|
+
}
|
|
109
|
+
if (firstView.byteLength !== secondView.byteLength) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
for (let index = firstView.byteLength; index-- !== 0; ) {
|
|
113
|
+
if (firstView.getUint8(index) !== secondView.getUint8(index)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (visited.has(currentFirst) && visited.get(currentFirst) === currentSecond) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
visited.set(currentFirst, currentSecond);
|
|
123
|
+
if (constructor === Array) {
|
|
124
|
+
const firstArray = currentFirst;
|
|
125
|
+
const secondArray = currentSecond;
|
|
126
|
+
if (firstArray.length !== secondArray.length) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
for (let index = firstArray.length; index-- !== 0; ) {
|
|
130
|
+
if (!compareValues(firstArray[index], secondArray[index])) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (constructor === Map) {
|
|
137
|
+
const firstMap = currentFirst;
|
|
138
|
+
const secondMap = currentSecond;
|
|
139
|
+
if (firstMap.size !== secondMap.size) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
for (const [key, value] of firstMap) {
|
|
143
|
+
if (!secondMap.has(key) || !compareValues(value, secondMap.get(key))) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
const firstAsAny = currentFirst;
|
|
150
|
+
const secondAsAny = currentSecond;
|
|
151
|
+
if (firstAsAny.valueOf !== valueOf && typeof firstAsAny.valueOf === "function" && typeof secondAsAny.valueOf === "function") {
|
|
152
|
+
return firstAsAny.valueOf() === secondAsAny.valueOf();
|
|
153
|
+
}
|
|
154
|
+
if (firstAsAny.toString !== toString && typeof firstAsAny.toString === "function" && typeof secondAsAny.toString === "function") {
|
|
155
|
+
return firstAsAny.toString() === secondAsAny.toString();
|
|
156
|
+
}
|
|
157
|
+
const firstKeys = Object.keys(currentFirst);
|
|
158
|
+
let currentKey;
|
|
159
|
+
for (let index = firstKeys.length; index-- !== 0; ) {
|
|
160
|
+
currentKey = firstKeys[index];
|
|
161
|
+
if (!Object.hasOwn(currentSecond, currentKey) || !compareValues(firstAsAny[currentKey], secondAsAny[currentKey])) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return Object.keys(currentSecond).length === firstKeys.length;
|
|
166
|
+
};
|
|
167
|
+
return compareValues(value1, value2);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { isDeepEqual, isShallowEqual };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import * as stackTrace from 'stacktrace-js';
|
|
3
|
+
import { getBaseName } from './path.js';
|
|
4
|
+
|
|
5
|
+
async function parseErrorStack(error, filter) {
|
|
6
|
+
return await stackTrace.fromError(error, {
|
|
7
|
+
offline: true,
|
|
8
|
+
filter
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function filterUserFrame(stackFrame) {
|
|
12
|
+
return !stackFrame.fileName || !stackFrame.fileName.includes("node_modules");
|
|
13
|
+
}
|
|
14
|
+
async function getSanitizedErrorStack(error) {
|
|
15
|
+
const frames = await parseErrorStack(error, filterUserFrame);
|
|
16
|
+
const cleanStack = frames.map((frame) => ` at ${frame.functionName || "anonymous"} (${frame.fileName ? getBaseName(frame.fileName, true) : "unknown"}:${frame.lineNumber}:${frame.columnNumber})`).join("\n");
|
|
17
|
+
return `${error.name}: ${error.message}
|
|
18
|
+
${cleanStack}`;
|
|
19
|
+
}
|
|
20
|
+
async function getCurrentStack(filter) {
|
|
21
|
+
return await stackTrace.get({
|
|
22
|
+
offline: true,
|
|
23
|
+
filter
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function getCurrentStackSync(filter) {
|
|
27
|
+
return stackTrace.getSync({
|
|
28
|
+
offline: true,
|
|
29
|
+
filter
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { filterUserFrame, getCurrentStack, getCurrentStackSync, getSanitizedErrorStack, parseErrorStack };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import mitt from 'mitt';
|
|
3
|
+
|
|
4
|
+
class EventEmitter {
|
|
5
|
+
/** Private mitt instance for handling the actual event operations */
|
|
6
|
+
#bus = mitt();
|
|
7
|
+
/**
|
|
8
|
+
* Subscribe to an event with a listener function.
|
|
9
|
+
* Returns an unsubscribe function for easy cleanup.
|
|
10
|
+
*
|
|
11
|
+
* @param eventType - The type of event to listen for
|
|
12
|
+
* @param eventListener - The function to call when the event is emitted
|
|
13
|
+
* @returns A function that removes this specific listener when called
|
|
14
|
+
*/
|
|
15
|
+
on(eventType, eventListener) {
|
|
16
|
+
this.#bus.on(eventType, eventListener);
|
|
17
|
+
return () => {
|
|
18
|
+
this.#bus.off(eventType, eventListener);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
emit(eventType, eventPayload) {
|
|
22
|
+
if (eventPayload) {
|
|
23
|
+
this.#bus.emit(eventType, eventPayload);
|
|
24
|
+
} else {
|
|
25
|
+
this.#bus.emit(eventType);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Remove a specific listener for an event type.
|
|
30
|
+
* If no listener is provided, removes all listeners for that event type.
|
|
31
|
+
*
|
|
32
|
+
* @param eventType - The type of event to remove listeners from
|
|
33
|
+
* @param eventListener - Optional specific listener to remove
|
|
34
|
+
*/
|
|
35
|
+
off(eventType, eventListener) {
|
|
36
|
+
this.#bus.off(eventType, eventListener);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Remove all event listeners from all event types.
|
|
40
|
+
* Useful for cleanup when the emitter is no longer needed.
|
|
41
|
+
*/
|
|
42
|
+
clear() {
|
|
43
|
+
this.#bus.all.clear();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get all registered listeners for debugging purposes.
|
|
47
|
+
* Returns a Map of event types to their listener arrays.
|
|
48
|
+
*/
|
|
49
|
+
getAllListeners() {
|
|
50
|
+
return this.#bus.all;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createEventEmitter() {
|
|
54
|
+
return new EventEmitter();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { EventEmitter, createEventEmitter };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
const BYTES_UNIT = 1024;
|
|
3
|
+
const BYTE_SIZES = ["B", "KB", "MB", "GB", "TB", "PB"];
|
|
4
|
+
const NUMBER_UNIT = 1e3;
|
|
5
|
+
const NUMBER_UNITS = ["", "K", "M", "B", "T"];
|
|
6
|
+
function formatBytes(bytes, decimals = 2) {
|
|
7
|
+
if (bytes === 0) {
|
|
8
|
+
return "0 B";
|
|
9
|
+
}
|
|
10
|
+
const dm = Math.max(decimals, 0);
|
|
11
|
+
const i = Math.floor(Math.log(bytes) / Math.log(BYTES_UNIT));
|
|
12
|
+
return `${Number.parseFloat((bytes / BYTES_UNIT ** i).toFixed(dm))} ${BYTE_SIZES[i]}`;
|
|
13
|
+
}
|
|
14
|
+
function formatNumber(num, decimals = 2) {
|
|
15
|
+
if (num === 0) {
|
|
16
|
+
return "0";
|
|
17
|
+
}
|
|
18
|
+
if (num < NUMBER_UNIT) {
|
|
19
|
+
return num.toString();
|
|
20
|
+
}
|
|
21
|
+
const dm = Math.max(decimals, 0);
|
|
22
|
+
const i = Math.floor(Math.log(num) / Math.log(NUMBER_UNIT));
|
|
23
|
+
return `${Number.parseFloat((num / NUMBER_UNIT ** i).toFixed(dm))} ${NUMBER_UNITS[i]}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { formatBytes, formatNumber };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
function isAsyncFunction(fn) {
|
|
3
|
+
return fn.constructor.name === "AsyncFunction" || Object.prototype.toString.call(fn) === "[object AsyncFunction]" || fn.toString().startsWith("async ");
|
|
4
|
+
}
|
|
5
|
+
async function invokeAwaitableFn(fn, args, options) {
|
|
6
|
+
const {
|
|
7
|
+
onInvoke,
|
|
8
|
+
onSuccess,
|
|
9
|
+
onError,
|
|
10
|
+
onFinally
|
|
11
|
+
} = options;
|
|
12
|
+
const returned = fn(...args);
|
|
13
|
+
if (returned instanceof Promise) {
|
|
14
|
+
let context;
|
|
15
|
+
try {
|
|
16
|
+
context = onInvoke?.();
|
|
17
|
+
const result = await returned;
|
|
18
|
+
onSuccess?.(result, context);
|
|
19
|
+
return result;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
onError?.(error, context);
|
|
22
|
+
throw error;
|
|
23
|
+
} finally {
|
|
24
|
+
onFinally?.(context);
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
return returned;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function identity(value) {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function createThrowNotImplementedFn(feature) {
|
|
34
|
+
return () => throwNotImplemented(feature);
|
|
35
|
+
}
|
|
36
|
+
function throwNotImplemented(feature) {
|
|
37
|
+
const label = feature ? `${feature} not implemented` : "Not implemented";
|
|
38
|
+
throw new Error(label);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { createThrowNotImplementedFn, identity, invokeAwaitableFn, isAsyncFunction, throwNotImplemented };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import { init } from '@paralleldrive/cuid2';
|
|
3
|
+
import { isNullish } from 'radashi';
|
|
4
|
+
|
|
5
|
+
function isFingerprintSupported() {
|
|
6
|
+
if (isNullish(navigator)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (navigator.userAgent.includes("jsdom")) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
let createId = init({
|
|
15
|
+
length: 16,
|
|
16
|
+
// vef-framework default fingerprint
|
|
17
|
+
fingerprint: "0cd902ccad1f26c27b8db84af2282b7b"
|
|
18
|
+
});
|
|
19
|
+
if (isFingerprintSupported()) {
|
|
20
|
+
import('@fingerprintjs/fingerprintjs').then(({ load }) => load()).then((fp) => fp.get()).then((result) => {
|
|
21
|
+
const fingerprint = result.visitorId;
|
|
22
|
+
createId = init({
|
|
23
|
+
length: 16,
|
|
24
|
+
fingerprint
|
|
25
|
+
});
|
|
26
|
+
}).catch((error) => {
|
|
27
|
+
console.error("Failed to initialize fingerprint:", error);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function generateId() {
|
|
31
|
+
return createId();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { generateId };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
export { DEFAULT_DATETIME_FORMAT, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT, LOCALIZED_DATETIME_FORMAT, LOCALIZED_DATE_FORMAT, formatDate, formatDuration, getLocalizedDateTime, getNow, getNowDateString, getNowDateTimeString, getNowTimeString, getTemporalFormats, parseDate, tryParseDate } from './chrono.js';
|
|
3
|
+
export { isDeepEqual, isShallowEqual } from './equal.js';
|
|
4
|
+
export { filterUserFrame, getCurrentStack, getCurrentStackSync, getSanitizedErrorStack, parseErrorStack } from './error.js';
|
|
5
|
+
export { EventEmitter, createEventEmitter } from './event.js';
|
|
6
|
+
export { formatBytes, formatNumber } from './format.js';
|
|
7
|
+
export { createThrowNotImplementedFn, identity, invokeAwaitableFn, isAsyncFunction, throwNotImplemented } from './function.js';
|
|
8
|
+
export { generateId } from './id.js';
|
|
9
|
+
export { hashKey } from './key.js';
|
|
10
|
+
export { alwaysFalse, alwaysTrue } from './lib.js';
|
|
11
|
+
export { mergeWith } from './object.js';
|
|
12
|
+
export { formatPath, getBaseName, getDirName, getExtName, getRelativePath, isAbsolutePath, joinPaths, normalizePath, parsePath, pathSeparator, resolvePath } from './path.js';
|
|
13
|
+
export { getPinyin, getPinyinInitials, withPinyin } from './pinyin.js';
|
|
14
|
+
export { decryptUsingRSA, encryptUsingRSA } from './security.js';
|
|
15
|
+
export { constantCase } from './string.js';
|
|
16
|
+
export { scheduleMicrotask } from './task.js';
|
|
17
|
+
export { buildTree, filterTree, filterTreeWithAncestors, findNodeInTree, flattenTree, mapTree, traverseTree } from './tree.js';
|
|
18
|
+
import './zod.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import './lib.js';
|
|
3
|
+
import { isPlainObject } from 'radashi';
|
|
4
|
+
|
|
5
|
+
function hashKey(key) {
|
|
6
|
+
return JSON.stringify(
|
|
7
|
+
key,
|
|
8
|
+
(_, value) => {
|
|
9
|
+
if (isPlainObject(value)) {
|
|
10
|
+
const stringKeys = Object.keys(value).toSorted();
|
|
11
|
+
const symbolKeys = Object.getOwnPropertySymbols(value);
|
|
12
|
+
const result = {};
|
|
13
|
+
for (const key2 of stringKeys) {
|
|
14
|
+
result[key2] = value[key2];
|
|
15
|
+
}
|
|
16
|
+
const symbolResult = {};
|
|
17
|
+
for (const sym of symbolKeys) {
|
|
18
|
+
symbolResult[sym.toString()] = value[sym];
|
|
19
|
+
}
|
|
20
|
+
for (const key2 of Object.keys(symbolResult).toSorted()) {
|
|
21
|
+
result[`@@${key2}`] = symbolResult[key2];
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { hashKey };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import { always } from 'radashi';
|
|
3
|
+
export { always, assign, camel as camelCase, capitalize, cluster, debounce, first, get, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFloat, isFunction, isInt, isIntString, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet, dash as kebabCase, last, max, memo as memoize, min, noop, omit, once, pascal as pascalCase, pick, set, similarity, snake as snakeCase, sum, template, throttle, toFloat, toInt, trim, unique } from 'radashi';
|
|
4
|
+
export { klona as cloneDeep } from 'klona';
|
|
5
|
+
export { parse as decodeQueryString, stringify as encodeQueryString } from 'qs';
|
|
6
|
+
|
|
7
|
+
const alwaysTrue = always(true);
|
|
8
|
+
const alwaysFalse = always(false);
|
|
9
|
+
|
|
10
|
+
export { alwaysFalse, alwaysTrue };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import './lib.js';
|
|
3
|
+
import { isUndefined } from 'radashi';
|
|
4
|
+
|
|
5
|
+
function mergeWith(target, source, overrideExisting = false) {
|
|
6
|
+
const validEntries = Object.entries(source).filter(([_, value]) => !isUndefined(value));
|
|
7
|
+
for (const [key, value] of validEntries) {
|
|
8
|
+
const targetKey = key;
|
|
9
|
+
if (overrideExisting || isUndefined(target[targetKey])) {
|
|
10
|
+
target[targetKey] = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { mergeWith };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import path from 'path-browserify';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
basename,
|
|
6
|
+
dirname,
|
|
7
|
+
extname,
|
|
8
|
+
isAbsolute,
|
|
9
|
+
join,
|
|
10
|
+
normalize,
|
|
11
|
+
parse,
|
|
12
|
+
relative,
|
|
13
|
+
resolve,
|
|
14
|
+
format,
|
|
15
|
+
sep: pathSeparator
|
|
16
|
+
} = path;
|
|
17
|
+
function getBaseName(path2, keepExt = true) {
|
|
18
|
+
const ext = keepExt ? void 0 : extname(path2);
|
|
19
|
+
return basename(path2, ext);
|
|
20
|
+
}
|
|
21
|
+
function getExtName(path2) {
|
|
22
|
+
return extname(path2);
|
|
23
|
+
}
|
|
24
|
+
function getDirName(path2) {
|
|
25
|
+
return dirname(path2);
|
|
26
|
+
}
|
|
27
|
+
function joinPaths(...paths) {
|
|
28
|
+
return join(...paths);
|
|
29
|
+
}
|
|
30
|
+
function isAbsolutePath(path2) {
|
|
31
|
+
return isAbsolute(path2);
|
|
32
|
+
}
|
|
33
|
+
function normalizePath(path2) {
|
|
34
|
+
return normalize(path2);
|
|
35
|
+
}
|
|
36
|
+
function parsePath(path2) {
|
|
37
|
+
return parse(path2);
|
|
38
|
+
}
|
|
39
|
+
function formatPath(pathObject) {
|
|
40
|
+
return format(pathObject);
|
|
41
|
+
}
|
|
42
|
+
function getRelativePath(from, to) {
|
|
43
|
+
return relative(from, to);
|
|
44
|
+
}
|
|
45
|
+
function resolvePath(...pathSegments) {
|
|
46
|
+
return resolve(...pathSegments);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { formatPath, getBaseName, getDirName, getExtName, getRelativePath, isAbsolutePath, joinPaths, normalizePath, parsePath, pathSeparator, resolvePath };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import ModernChineseDict from '@pinyin-pro/data/modern';
|
|
3
|
+
import { addDict, pinyin } from 'pinyin-pro';
|
|
4
|
+
import './lib.js';
|
|
5
|
+
import { isString } from 'radashi';
|
|
6
|
+
|
|
7
|
+
addDict(ModernChineseDict);
|
|
8
|
+
const baseOptions = {
|
|
9
|
+
type: "array",
|
|
10
|
+
toneType: "none",
|
|
11
|
+
multiple: false,
|
|
12
|
+
nonZh: "consecutive",
|
|
13
|
+
surname: "head"
|
|
14
|
+
};
|
|
15
|
+
function getPinyin(text) {
|
|
16
|
+
return pinyin(
|
|
17
|
+
text,
|
|
18
|
+
{
|
|
19
|
+
...baseOptions,
|
|
20
|
+
pattern: "pinyin"
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
function getPinyinInitials(text) {
|
|
25
|
+
return pinyin(
|
|
26
|
+
text,
|
|
27
|
+
{
|
|
28
|
+
...baseOptions,
|
|
29
|
+
pattern: "first"
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function withPinyin(obj, ...keys) {
|
|
34
|
+
const result = { ...obj };
|
|
35
|
+
for (const key of keys) {
|
|
36
|
+
const value = obj[key];
|
|
37
|
+
if (isString(value)) {
|
|
38
|
+
const pinyinKey = `${key}Pinyin`;
|
|
39
|
+
const initialsKey = `${key}PinyinInitials`;
|
|
40
|
+
result[pinyinKey] = getPinyin(value).join("");
|
|
41
|
+
result[initialsKey] = getPinyinInitials(value).join("");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { getPinyin, getPinyinInitials, withPinyin };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import JSEncrypt from 'jsencrypt';
|
|
3
|
+
import './lib.js';
|
|
4
|
+
import { isNullish } from 'radashi';
|
|
5
|
+
|
|
6
|
+
function encryptUsingRSA(value, publicKey) {
|
|
7
|
+
if (isNullish(value)) {
|
|
8
|
+
throw new Error(`Failed to encrypt data [${value}] using RSA`);
|
|
9
|
+
}
|
|
10
|
+
if (!publicKey || publicKey.trim() === "") {
|
|
11
|
+
throw new Error(`Failed to encrypt data [${value}] using RSA`);
|
|
12
|
+
}
|
|
13
|
+
const rsa = new JSEncrypt();
|
|
14
|
+
rsa.setPublicKey(publicKey);
|
|
15
|
+
const encrypted = rsa.encrypt(value);
|
|
16
|
+
if (!encrypted) {
|
|
17
|
+
console.error("Failed to encrypt data using RSA", value);
|
|
18
|
+
throw new Error(`Failed to encrypt data [${value}] using RSA`);
|
|
19
|
+
}
|
|
20
|
+
return encrypted;
|
|
21
|
+
}
|
|
22
|
+
function decryptUsingRSA(value, privateKey) {
|
|
23
|
+
if (isNullish(value)) {
|
|
24
|
+
throw new Error(`Failed to decrypt data [${value}] using RSA`);
|
|
25
|
+
}
|
|
26
|
+
if (!privateKey || privateKey.trim() === "") {
|
|
27
|
+
throw new Error(`Failed to decrypt data [${value}] using RSA`);
|
|
28
|
+
}
|
|
29
|
+
const rsa = new JSEncrypt();
|
|
30
|
+
rsa.setPrivateKey(privateKey);
|
|
31
|
+
const decrypted = rsa.decrypt(value);
|
|
32
|
+
if (!decrypted) {
|
|
33
|
+
console.error("Failed to decrypt data using RSA", value);
|
|
34
|
+
throw new Error(`Failed to decrypt data [${value}] using RSA`);
|
|
35
|
+
}
|
|
36
|
+
return decrypted;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { decryptUsingRSA, encryptUsingRSA };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! @vef-framework/shared v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:28.916Z */
|
|
2
|
+
import './lib.js';
|
|
3
|
+
import { isFunction } from 'radashi';
|
|
4
|
+
|
|
5
|
+
function scheduleMicrotask(task) {
|
|
6
|
+
if (isFunction(queueMicrotask)) {
|
|
7
|
+
queueMicrotask(task);
|
|
8
|
+
} else {
|
|
9
|
+
Promise.resolve().then(task);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { scheduleMicrotask };
|