@react-fabric/utilities 1.0.0-beta.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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/_ascii.js +76 -0
- package/dist/cjs/_boundingBox.js +59 -0
- package/dist/cjs/_countries.js +2805 -0
- package/dist/cjs/_debounce.js +53 -0
- package/dist/cjs/_dedupe.js +63 -0
- package/dist/cjs/_fetch.js +128 -0
- package/dist/cjs/_fileType.js +967 -0
- package/dist/cjs/_format.js +118 -0
- package/dist/cjs/_getByPath.js +125 -0
- package/dist/cjs/_hash.js +67 -0
- package/dist/cjs/_interpolate.js +47 -0
- package/dist/cjs/_isEqual.js +108 -0
- package/dist/cjs/_isType.js +98 -0
- package/dist/cjs/_mergeRefs.js +40 -0
- package/dist/cjs/_tokenize.js +67 -0
- package/dist/cjs/getImageColorset.js +70 -0
- package/dist/cjs/index.js +116 -0
- package/dist/cjs/useLogger.js +339 -0
- package/dist/cjs/yup.js +172 -0
- package/dist/esm/_ascii.js +76 -0
- package/dist/esm/_boundingBox.js +58 -0
- package/dist/esm/_countries.js +2805 -0
- package/dist/esm/_debounce.js +53 -0
- package/dist/esm/_dedupe.js +60 -0
- package/dist/esm/_fetch.js +128 -0
- package/dist/esm/_fileType.js +967 -0
- package/dist/esm/_format.js +120 -0
- package/dist/esm/_getByPath.js +124 -0
- package/dist/esm/_hash.js +65 -0
- package/dist/esm/_interpolate.js +46 -0
- package/dist/esm/_isEqual.js +106 -0
- package/dist/esm/_isType.js +85 -0
- package/dist/esm/_mergeRefs.js +40 -0
- package/dist/esm/_tokenize.js +66 -0
- package/dist/esm/getImageColorset.js +70 -0
- package/dist/esm/index.js +52 -0
- package/dist/esm/useLogger.js +339 -0
- package/dist/esm/yup.js +152 -0
- package/dist/types/_ascii.d.ts +5 -0
- package/dist/types/_boundingBox.d.ts +10 -0
- package/dist/types/_countries.d.ts +85 -0
- package/dist/types/_debounce.d.ts +8 -0
- package/dist/types/_dedupe.d.ts +4 -0
- package/dist/types/_fetch.d.ts +23 -0
- package/dist/types/_fileType.d.ts +926 -0
- package/dist/types/_format.d.ts +27 -0
- package/dist/types/_getByPath.d.ts +10 -0
- package/dist/types/_hash.d.ts +16 -0
- package/dist/types/_interpolate.d.ts +6 -0
- package/dist/types/_isEqual.d.ts +15 -0
- package/dist/types/_isType.d.ts +14 -0
- package/dist/types/_mergeRefs.d.ts +1 -0
- package/dist/types/_tokenize.d.ts +8 -0
- package/dist/types/getImageColorset.d.ts +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/useLogger.d.ts +25 -0
- package/dist/types/yup.d.ts +1 -0
- package/package.json +48 -0
- package/src/_ascii.ts +93 -0
- package/src/_boundingBox.ts +72 -0
- package/src/_countries.ts +3046 -0
- package/src/_debounce.ts +42 -0
- package/src/_dedupe.ts +56 -0
- package/src/_fetch.ts +109 -0
- package/src/_fileType.ts +993 -0
- package/src/_format.ts +141 -0
- package/src/_getByPath.ts +108 -0
- package/src/_hash.ts +62 -0
- package/src/_interpolate.ts +42 -0
- package/src/_isEqual.ts +102 -0
- package/src/_isType.ts +105 -0
- package/src/_mergeRefs.ts +33 -0
- package/src/_tokenize.ts +69 -0
- package/src/getImageColorset.ts +81 -0
- package/src/index.ts +51 -0
- package/src/useLogger.ts +304 -0
- package/src/yup.ts +75 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* istanbul ignore file */
|
|
25
|
+
|
|
26
|
+
export const getImageColorset = (el: HTMLImageElement) => {
|
|
27
|
+
// create canvas
|
|
28
|
+
const canvas = document.createElement("canvas");
|
|
29
|
+
canvas.width = Math.min(500, el.naturalWidth);
|
|
30
|
+
canvas.height = Math.min(500, el.naturalHeight);
|
|
31
|
+
|
|
32
|
+
const ctx = canvas.getContext("2d");
|
|
33
|
+
if (ctx != null) {
|
|
34
|
+
ctx.drawImage(
|
|
35
|
+
el,
|
|
36
|
+
0,
|
|
37
|
+
0,
|
|
38
|
+
el.naturalWidth,
|
|
39
|
+
el.naturalHeight,
|
|
40
|
+
0,
|
|
41
|
+
0,
|
|
42
|
+
canvas.width,
|
|
43
|
+
canvas.height,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
47
|
+
const data = imageData.data;
|
|
48
|
+
let r, g, b;
|
|
49
|
+
let dark = 0;
|
|
50
|
+
let light = 0;
|
|
51
|
+
let totalPixels = 0;
|
|
52
|
+
let transparent = data?.[3] === 0;
|
|
53
|
+
|
|
54
|
+
for (let x = 0, len = data.length; x < len; x += 4) {
|
|
55
|
+
if (data[x + 3] === 0) {
|
|
56
|
+
transparent = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (transparent && data[x - 1] === 1) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
r = data[x];
|
|
63
|
+
g = data[x + 1];
|
|
64
|
+
b = data[x + 2];
|
|
65
|
+
totalPixels++;
|
|
66
|
+
0.2126 * r + 0.7152 * g + 0.0722 * b < 128 ? dark++ : light++;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const diff = light / totalPixels - dark / totalPixels;
|
|
70
|
+
let ret = diff > 0 ? "light" : "dark";
|
|
71
|
+
if (transparent) {
|
|
72
|
+
ret += "_transparent";
|
|
73
|
+
}
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
76
|
+
return "light";
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
if (typeof window !== "undefined")
|
|
80
|
+
// @ts-expect-error ignore
|
|
81
|
+
window.getImageColorset = getImageColorset;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* istanbul ignore file */
|
|
25
|
+
|
|
26
|
+
export * from "./_ascii";
|
|
27
|
+
export * from "./_boundingBox";
|
|
28
|
+
export { getBoundingBox, getBox } from "./_boundingBox";
|
|
29
|
+
export { default as Countries } from "./_countries";
|
|
30
|
+
export type { Country } from "./_countries";
|
|
31
|
+
export * from "./_debounce";
|
|
32
|
+
export * from "./_dedupe";
|
|
33
|
+
export { _fetch as fetch } from "./_fetch";
|
|
34
|
+
export { default as FileUtil } from "./_fileType";
|
|
35
|
+
export * from "./_format";
|
|
36
|
+
export * from "./_getByPath";
|
|
37
|
+
export * from "./_hash";
|
|
38
|
+
export * from "./_interpolate";
|
|
39
|
+
export * from "./_isEqual";
|
|
40
|
+
export * from "./_isType";
|
|
41
|
+
export * from "./_mergeRefs";
|
|
42
|
+
export * from "./_tokenize";
|
|
43
|
+
export { getImageColorset } from "./getImageColorset";
|
|
44
|
+
export { useLogger } from "./useLogger";
|
|
45
|
+
export * from "./yup";
|
|
46
|
+
|
|
47
|
+
export const EMPTY_ARRAY = [];
|
|
48
|
+
Object.freeze(EMPTY_ARRAY);
|
|
49
|
+
|
|
50
|
+
export const EMPTY_OBJECT = {};
|
|
51
|
+
Object.freeze(EMPTY_OBJECT);
|
package/src/useLogger.ts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
interface LogDetail {
|
|
25
|
+
module?: string;
|
|
26
|
+
process?: string;
|
|
27
|
+
duration?: number;
|
|
28
|
+
totalTime?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
enum LOG_LEVEL {
|
|
32
|
+
OFF,
|
|
33
|
+
WARNING,
|
|
34
|
+
INFO,
|
|
35
|
+
DEBUG,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* istanbul ignore file */
|
|
39
|
+
|
|
40
|
+
const NODE = {
|
|
41
|
+
LOG: "\u001B[38;5;144m",
|
|
42
|
+
INFO: "\u001B[38;5;81m",
|
|
43
|
+
DEBUG: "\u001B[38;5;110m",
|
|
44
|
+
ERROR: "\u001B[38;5;161m",
|
|
45
|
+
WARNING: "\u001B[38;5;209m",
|
|
46
|
+
TIME: "\u001B[38;5;72m",
|
|
47
|
+
PROCESS: "\u001B[38;5;108m",
|
|
48
|
+
DURATION: "\u001B[38;5;140m",
|
|
49
|
+
RESET: "\u001B[0m",
|
|
50
|
+
|
|
51
|
+
logLevel() {
|
|
52
|
+
return (
|
|
53
|
+
// @ts-expect-error ignore
|
|
54
|
+
global.LOG_LEVEL ??
|
|
55
|
+
(process.env.NODE_ENV !== "production"
|
|
56
|
+
? LOG_LEVEL.DEBUG
|
|
57
|
+
: LOG_LEVEL.WARNING)
|
|
58
|
+
);
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
makeLog(
|
|
62
|
+
level: string,
|
|
63
|
+
{ process, module, duration, totalTime }: LogDetail = {},
|
|
64
|
+
) {
|
|
65
|
+
const ret = [];
|
|
66
|
+
if (process) ret.push(`${this.PROCESS}Process: ${process}${this.RESET}`);
|
|
67
|
+
if (module) ret.push(`${this.PROCESS}Module: ${module}${this.RESET}`);
|
|
68
|
+
if (duration)
|
|
69
|
+
ret.push(`${this.DURATION}Duration: ${duration}${this.RESET}`);
|
|
70
|
+
if (module)
|
|
71
|
+
ret.push(`${this.DURATION}TotalTime: ${totalTime}${this.RESET}`);
|
|
72
|
+
|
|
73
|
+
return [
|
|
74
|
+
`[${this.TIME}${new Date().toISOString()}${this.RESET}] ${level}`,
|
|
75
|
+
ret.join(" "),
|
|
76
|
+
]
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.join("\n");
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
log(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
82
|
+
if (+this.logLevel() < LOG_LEVEL.DEBUG) return;
|
|
83
|
+
console.log(
|
|
84
|
+
this.makeLog(`${this.LOG}LOG${this.RESET}`, opts),
|
|
85
|
+
`\n${msg}\n`,
|
|
86
|
+
...rest,
|
|
87
|
+
);
|
|
88
|
+
},
|
|
89
|
+
debug(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
90
|
+
if (+this.logLevel() < LOG_LEVEL.DEBUG) return;
|
|
91
|
+
console.debug(
|
|
92
|
+
this.makeLog(`${this.DEBUG}DEBUG${this.RESET}`, opts),
|
|
93
|
+
`\n${msg}\n`,
|
|
94
|
+
...rest,
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
info(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
98
|
+
if (+this.logLevel() < LOG_LEVEL.INFO) return;
|
|
99
|
+
console.info(
|
|
100
|
+
this.makeLog(`${this.INFO}INFO${this.RESET}`, opts),
|
|
101
|
+
`\n${msg}\n`,
|
|
102
|
+
...rest,
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
error(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
106
|
+
console.error(
|
|
107
|
+
this.makeLog(`${this.ERROR}ERROR${this.RESET}`, opts),
|
|
108
|
+
`\n${msg}\n`,
|
|
109
|
+
...rest,
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
warning(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
113
|
+
if (+this.logLevel() < LOG_LEVEL.WARNING) return;
|
|
114
|
+
console.warn(
|
|
115
|
+
this.makeLog(`${this.WARNING}WARNING${this.RESET}`, opts),
|
|
116
|
+
`\n${msg}\n`,
|
|
117
|
+
...rest,
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const BROWSER = {
|
|
123
|
+
LOG: "#afaf87",
|
|
124
|
+
INFO: "#5fd7ff",
|
|
125
|
+
DEBUG: "#87afd7",
|
|
126
|
+
ERROR: "#d7005f",
|
|
127
|
+
WARNING: "#ff875f",
|
|
128
|
+
TIME: "#5faf87",
|
|
129
|
+
PROCESS: "#87af87",
|
|
130
|
+
DURATION: "#af87d7",
|
|
131
|
+
|
|
132
|
+
logLevel() {
|
|
133
|
+
return (
|
|
134
|
+
// @ts-expect-error ignore
|
|
135
|
+
(typeof window !== "undefined" ? window.LOG_LEVEL : undefined) ??
|
|
136
|
+
(process.env.NODE_ENV !== "production"
|
|
137
|
+
? LOG_LEVEL.DEBUG
|
|
138
|
+
: LOG_LEVEL.WARNING)
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
makeLog(
|
|
143
|
+
level: string,
|
|
144
|
+
color: string,
|
|
145
|
+
{ process, module, duration, totalTime }: LogDetail = {},
|
|
146
|
+
) {
|
|
147
|
+
const ret = [];
|
|
148
|
+
const colors = [
|
|
149
|
+
`color:${this.TIME};font-weight:bold;`,
|
|
150
|
+
`color:${color};font-weight:bold;`,
|
|
151
|
+
];
|
|
152
|
+
if (module) ret.push(`%cModule: ${module}`);
|
|
153
|
+
if (process) ret.push(`%cProcess: ${process}`);
|
|
154
|
+
if (duration) ret.push(`%cDuration: ${duration}`);
|
|
155
|
+
if (module) ret.push(`%cTotalTime: ${totalTime}`);
|
|
156
|
+
if (module) colors.push(`color:${this.PROCESS}`);
|
|
157
|
+
if (process) colors.push(`color:${this.PROCESS}`);
|
|
158
|
+
if (duration) colors.push(`color:${this.DURATION}`);
|
|
159
|
+
if (module) colors.push(`color:${this.DURATION}`);
|
|
160
|
+
|
|
161
|
+
return [
|
|
162
|
+
[`%c[${new Date().toISOString()}] ${level}`, ret.join(" ")]
|
|
163
|
+
.filter(Boolean)
|
|
164
|
+
.join("\n"),
|
|
165
|
+
colors,
|
|
166
|
+
];
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
log(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
170
|
+
if (+this.logLevel() < LOG_LEVEL.DEBUG) return;
|
|
171
|
+
const [logs, colors] = this.makeLog(`%cLOG`, this.LOG, opts);
|
|
172
|
+
console.log(logs, ...colors, `\n${msg}\n`, ...rest);
|
|
173
|
+
},
|
|
174
|
+
debug(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
175
|
+
if (+this.logLevel() < LOG_LEVEL.DEBUG) return;
|
|
176
|
+
const [logs, colors] = this.makeLog(`%cDEBUG`, this.DEBUG, opts);
|
|
177
|
+
console.debug(logs, ...colors, `\n${msg}\n`, ...rest);
|
|
178
|
+
},
|
|
179
|
+
info(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
180
|
+
if (+this.logLevel() < LOG_LEVEL.INFO) return;
|
|
181
|
+
const [logs, colors] = this.makeLog(`%cINFO`, this.INFO, opts);
|
|
182
|
+
console.info(logs, ...colors, `\n${msg}\n`, ...rest);
|
|
183
|
+
},
|
|
184
|
+
error(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
185
|
+
const [logs, colors] = this.makeLog(`%cERROR`, this.ERROR, opts);
|
|
186
|
+
console.error(logs, ...colors, `\n${msg}\n`, ...rest);
|
|
187
|
+
},
|
|
188
|
+
warning(msg: string, opts: LogDetail, ...rest: unknown[]) {
|
|
189
|
+
if (+this.logLevel() < LOG_LEVEL.WARNING) return;
|
|
190
|
+
const [logs, colors] = this.makeLog(`%cWARNING`, this.WARNING, opts);
|
|
191
|
+
console.warn(logs, ...colors, `\n${msg}\ntest`, ...rest);
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const logger = () => {
|
|
196
|
+
if (typeof window === "undefined") return NODE;
|
|
197
|
+
if (typeof window !== "undefined") return BROWSER;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
export const useLogger = (mod?: string) => ({
|
|
204
|
+
timer(process: string) {
|
|
205
|
+
const startTime = new Date().getTime();
|
|
206
|
+
let nextTime = new Date().getTime();
|
|
207
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
208
|
+
const self = this;
|
|
209
|
+
const getTime = () => {
|
|
210
|
+
const ret = (new Date().getTime() - nextTime) / 1000;
|
|
211
|
+
nextTime = new Date().getTime();
|
|
212
|
+
return ret;
|
|
213
|
+
};
|
|
214
|
+
const getFullTime = () => {
|
|
215
|
+
return (new Date().getTime() - startTime) / 1000;
|
|
216
|
+
};
|
|
217
|
+
return {
|
|
218
|
+
log: (msg: string, ...rest: unknown[]) =>
|
|
219
|
+
self.log(
|
|
220
|
+
msg,
|
|
221
|
+
{
|
|
222
|
+
process,
|
|
223
|
+
duration: getTime(),
|
|
224
|
+
totalTime: getFullTime(),
|
|
225
|
+
},
|
|
226
|
+
...rest,
|
|
227
|
+
),
|
|
228
|
+
debug: (msg: string, ...rest: unknown[]) =>
|
|
229
|
+
self.debug(
|
|
230
|
+
msg,
|
|
231
|
+
{
|
|
232
|
+
process,
|
|
233
|
+
duration: getTime(),
|
|
234
|
+
totalTime: getFullTime(),
|
|
235
|
+
},
|
|
236
|
+
...rest,
|
|
237
|
+
),
|
|
238
|
+
info: (msg: string, ...rest: unknown[]) =>
|
|
239
|
+
self.info(
|
|
240
|
+
msg,
|
|
241
|
+
{
|
|
242
|
+
process,
|
|
243
|
+
duration: getTime(),
|
|
244
|
+
totalTime: getFullTime(),
|
|
245
|
+
},
|
|
246
|
+
...rest,
|
|
247
|
+
),
|
|
248
|
+
error: (msg: string, ...rest: unknown[]) =>
|
|
249
|
+
self.error(
|
|
250
|
+
msg,
|
|
251
|
+
{
|
|
252
|
+
process,
|
|
253
|
+
duration: getTime(),
|
|
254
|
+
totalTime: getFullTime(),
|
|
255
|
+
},
|
|
256
|
+
...rest,
|
|
257
|
+
),
|
|
258
|
+
warning: (msg: string, ...rest: unknown[]) =>
|
|
259
|
+
self.warning(
|
|
260
|
+
msg,
|
|
261
|
+
{
|
|
262
|
+
process,
|
|
263
|
+
duration: getTime(),
|
|
264
|
+
totalTime: getFullTime(),
|
|
265
|
+
},
|
|
266
|
+
...rest,
|
|
267
|
+
),
|
|
268
|
+
end: (msg = "completed", ...rest: unknown[]) =>
|
|
269
|
+
self.info(
|
|
270
|
+
msg,
|
|
271
|
+
{
|
|
272
|
+
process,
|
|
273
|
+
duration: getTime(),
|
|
274
|
+
totalTime: getFullTime(),
|
|
275
|
+
},
|
|
276
|
+
...rest,
|
|
277
|
+
),
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
log(msg: string, { module = mod, ...opts }: LogDetail, ...rest: unknown[]) {
|
|
282
|
+
logger()?.log(msg, opts, ...rest);
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
debug(msg: string, { module = mod, ...opts }: LogDetail, ...rest: unknown[]) {
|
|
286
|
+
logger()?.debug(msg, opts, ...rest);
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
info(msg: string, { module = mod, ...opts }: LogDetail, ...rest: unknown[]) {
|
|
290
|
+
logger()?.info(msg, opts, ...rest);
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
error(msg: string, { module = mod, ...opts }: LogDetail, ...rest: unknown[]) {
|
|
294
|
+
logger()?.error(msg, opts, ...rest);
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
warning(
|
|
298
|
+
msg: string,
|
|
299
|
+
{ module = mod, ...opts }: LogDetail,
|
|
300
|
+
...rest: unknown[]
|
|
301
|
+
) {
|
|
302
|
+
logger()?.warning(msg, opts, ...rest);
|
|
303
|
+
},
|
|
304
|
+
});
|
package/src/yup.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* istanbul ignore file */
|
|
25
|
+
|
|
26
|
+
import * as _yup from "yup";
|
|
27
|
+
|
|
28
|
+
_yup.setLocale({
|
|
29
|
+
mixed: {
|
|
30
|
+
default: ({ path, label }) => ({
|
|
31
|
+
key: "form:yup.invalid",
|
|
32
|
+
values: { path, label },
|
|
33
|
+
}),
|
|
34
|
+
required: ({ path, label }) => ({
|
|
35
|
+
key: "form:yup.required",
|
|
36
|
+
values: { path, label },
|
|
37
|
+
}),
|
|
38
|
+
notType: ({ type, path, label }) => ({
|
|
39
|
+
key: "form:yup.invalidType",
|
|
40
|
+
values: { type, path, label },
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
array: {
|
|
44
|
+
min: ({ min, path, label }) => ({
|
|
45
|
+
key: "form:yup.arrayMin",
|
|
46
|
+
values: { min, path, label },
|
|
47
|
+
}),
|
|
48
|
+
max: ({ max, path, label }) => ({
|
|
49
|
+
key: "form:yup.arrayMax",
|
|
50
|
+
values: { max, path, label },
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
string: {
|
|
54
|
+
min: ({ min, path, label }) => ({
|
|
55
|
+
key: "form:yup.stringMin",
|
|
56
|
+
values: { min, path, label },
|
|
57
|
+
}),
|
|
58
|
+
max: ({ max, path, label }) => ({
|
|
59
|
+
key: "form:yup.stringMax",
|
|
60
|
+
values: { max, path, label },
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
number: {
|
|
64
|
+
min: ({ min, path, label }) => ({
|
|
65
|
+
key: "form:yup.numberMin",
|
|
66
|
+
values: { min, path, label },
|
|
67
|
+
}),
|
|
68
|
+
max: ({ max, path, label }) => ({
|
|
69
|
+
key: "form:yup.numberMax",
|
|
70
|
+
values: { max, path, label },
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
boolean: {},
|
|
74
|
+
});
|
|
75
|
+
export * as yup from "yup";
|