typetify 0.1.1
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 +327 -0
- package/dist/async/index.d.mts +152 -0
- package/dist/async/index.d.ts +152 -0
- package/dist/async/index.js +49 -0
- package/dist/async/index.js.map +1 -0
- package/dist/async/index.mjs +4 -0
- package/dist/async/index.mjs.map +1 -0
- package/dist/chunk-2LJ6NZ6K.js +108 -0
- package/dist/chunk-2LJ6NZ6K.js.map +1 -0
- package/dist/chunk-44Y5JSGU.js +145 -0
- package/dist/chunk-44Y5JSGU.js.map +1 -0
- package/dist/chunk-4NXETABV.mjs +116 -0
- package/dist/chunk-4NXETABV.mjs.map +1 -0
- package/dist/chunk-6ZBTL74K.js +129 -0
- package/dist/chunk-6ZBTL74K.js.map +1 -0
- package/dist/chunk-CN3GYRJN.mjs +137 -0
- package/dist/chunk-CN3GYRJN.mjs.map +1 -0
- package/dist/chunk-CNTE6ZVH.js +359 -0
- package/dist/chunk-CNTE6ZVH.js.map +1 -0
- package/dist/chunk-DBENOSTA.js +156 -0
- package/dist/chunk-DBENOSTA.js.map +1 -0
- package/dist/chunk-DWIG5GF2.js +135 -0
- package/dist/chunk-DWIG5GF2.js.map +1 -0
- package/dist/chunk-EAUTTWTQ.mjs +231 -0
- package/dist/chunk-EAUTTWTQ.mjs.map +1 -0
- package/dist/chunk-FXWYPHA3.mjs +13 -0
- package/dist/chunk-FXWYPHA3.mjs.map +1 -0
- package/dist/chunk-GS3PP67B.js +200 -0
- package/dist/chunk-GS3PP67B.js.map +1 -0
- package/dist/chunk-J5LGTIGS.mjs +9 -0
- package/dist/chunk-J5LGTIGS.mjs.map +1 -0
- package/dist/chunk-JAOGY4JO.mjs +1007 -0
- package/dist/chunk-JAOGY4JO.mjs.map +1 -0
- package/dist/chunk-JB6UXRKD.mjs +97 -0
- package/dist/chunk-JB6UXRKD.mjs.map +1 -0
- package/dist/chunk-JQHUBZ4M.js +88 -0
- package/dist/chunk-JQHUBZ4M.js.map +1 -0
- package/dist/chunk-L3M7LGKL.mjs +128 -0
- package/dist/chunk-L3M7LGKL.mjs.map +1 -0
- package/dist/chunk-LT7JK7RJ.js +87 -0
- package/dist/chunk-LT7JK7RJ.js.map +1 -0
- package/dist/chunk-OEJK37LO.mjs +328 -0
- package/dist/chunk-OEJK37LO.mjs.map +1 -0
- package/dist/chunk-OPVES6W2.js +16 -0
- package/dist/chunk-OPVES6W2.js.map +1 -0
- package/dist/chunk-OWNUKWXV.js +291 -0
- package/dist/chunk-OWNUKWXV.js.map +1 -0
- package/dist/chunk-PQTXSQ4P.js +369 -0
- package/dist/chunk-PQTXSQ4P.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +11 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-QFR7DVAJ.mjs +63 -0
- package/dist/chunk-QFR7DVAJ.mjs.map +1 -0
- package/dist/chunk-SGQNLTRK.js +73 -0
- package/dist/chunk-SGQNLTRK.js.map +1 -0
- package/dist/chunk-SIA5BSVY.js +1054 -0
- package/dist/chunk-SIA5BSVY.js.map +1 -0
- package/dist/chunk-SRDWUHDY.mjs +188 -0
- package/dist/chunk-SRDWUHDY.mjs.map +1 -0
- package/dist/chunk-TXU7NTT4.js +249 -0
- package/dist/chunk-TXU7NTT4.js.map +1 -0
- package/dist/chunk-TZEWREAC.mjs +277 -0
- package/dist/chunk-TZEWREAC.mjs.map +1 -0
- package/dist/chunk-V6CWFDIJ.mjs +123 -0
- package/dist/chunk-V6CWFDIJ.mjs.map +1 -0
- package/dist/chunk-YBJC5WMX.mjs +341 -0
- package/dist/chunk-YBJC5WMX.mjs.map +1 -0
- package/dist/chunk-YOPAXITF.mjs +75 -0
- package/dist/chunk-YOPAXITF.mjs.map +1 -0
- package/dist/chunk-ZE4FDBRI.mjs +79 -0
- package/dist/chunk-ZE4FDBRI.mjs.map +1 -0
- package/dist/collection/index.d.mts +291 -0
- package/dist/collection/index.d.ts +291 -0
- package/dist/collection/index.js +125 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/index.mjs +4 -0
- package/dist/collection/index.mjs.map +1 -0
- package/dist/core/index.d.mts +85 -0
- package/dist/core/index.d.ts +85 -0
- package/dist/core/index.js +41 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +4 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/decorator/index.d.mts +165 -0
- package/dist/decorator/index.d.ts +165 -0
- package/dist/decorator/index.js +57 -0
- package/dist/decorator/index.js.map +1 -0
- package/dist/decorator/index.mjs +4 -0
- package/dist/decorator/index.mjs.map +1 -0
- package/dist/dx/index.d.mts +125 -0
- package/dist/dx/index.d.ts +125 -0
- package/dist/dx/index.js +53 -0
- package/dist/dx/index.js.map +1 -0
- package/dist/dx/index.mjs +4 -0
- package/dist/dx/index.mjs.map +1 -0
- package/dist/flow/index.d.mts +165 -0
- package/dist/flow/index.d.ts +165 -0
- package/dist/flow/index.js +50 -0
- package/dist/flow/index.js.map +1 -0
- package/dist/flow/index.mjs +5 -0
- package/dist/flow/index.mjs.map +1 -0
- package/dist/fn/index.d.mts +77 -0
- package/dist/fn/index.d.ts +77 -0
- package/dist/fn/index.js +37 -0
- package/dist/fn/index.js.map +1 -0
- package/dist/fn/index.mjs +4 -0
- package/dist/fn/index.mjs.map +1 -0
- package/dist/guards/index.d.mts +165 -0
- package/dist/guards/index.d.ts +165 -0
- package/dist/guards/index.js +69 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/index.mjs +4 -0
- package/dist/guards/index.mjs.map +1 -0
- package/dist/index.d.mts +228 -0
- package/dist/index.d.ts +228 -0
- package/dist/index.js +775 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +51 -0
- package/dist/index.mjs.map +1 -0
- package/dist/input/index.d.mts +185 -0
- package/dist/input/index.d.ts +185 -0
- package/dist/input/index.js +74 -0
- package/dist/input/index.js.map +1 -0
- package/dist/input/index.mjs +5 -0
- package/dist/input/index.mjs.map +1 -0
- package/dist/iterator/index.d.mts +209 -0
- package/dist/iterator/index.d.ts +209 -0
- package/dist/iterator/index.js +522 -0
- package/dist/iterator/index.js.map +1 -0
- package/dist/iterator/index.mjs +502 -0
- package/dist/iterator/index.mjs.map +1 -0
- package/dist/logic/index.d.mts +531 -0
- package/dist/logic/index.d.ts +531 -0
- package/dist/logic/index.js +416 -0
- package/dist/logic/index.js.map +1 -0
- package/dist/logic/index.mjs +367 -0
- package/dist/logic/index.mjs.map +1 -0
- package/dist/math/index.d.mts +86 -0
- package/dist/math/index.d.ts +86 -0
- package/dist/math/index.js +45 -0
- package/dist/math/index.js.map +1 -0
- package/dist/math/index.mjs +4 -0
- package/dist/math/index.mjs.map +1 -0
- package/dist/narrowing/index.d.mts +429 -0
- package/dist/narrowing/index.d.ts +429 -0
- package/dist/narrowing/index.js +220 -0
- package/dist/narrowing/index.js.map +1 -0
- package/dist/narrowing/index.mjs +186 -0
- package/dist/narrowing/index.mjs.map +1 -0
- package/dist/object/index.d.mts +327 -0
- package/dist/object/index.d.ts +327 -0
- package/dist/object/index.js +113 -0
- package/dist/object/index.js.map +1 -0
- package/dist/object/index.mjs +4 -0
- package/dist/object/index.mjs.map +1 -0
- package/dist/result/index.d.mts +201 -0
- package/dist/result/index.d.ts +201 -0
- package/dist/result/index.js +86 -0
- package/dist/result/index.js.map +1 -0
- package/dist/result/index.mjs +5 -0
- package/dist/result/index.mjs.map +1 -0
- package/dist/schema/index.d.mts +216 -0
- package/dist/schema/index.d.ts +216 -0
- package/dist/schema/index.js +410 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/index.mjs +384 -0
- package/dist/schema/index.mjs.map +1 -0
- package/dist/string/index.d.mts +102 -0
- package/dist/string/index.d.ts +102 -0
- package/dist/string/index.js +49 -0
- package/dist/string/index.js.map +1 -0
- package/dist/string/index.mjs +4 -0
- package/dist/string/index.mjs.map +1 -0
- package/dist/typed/index.d.mts +1962 -0
- package/dist/typed/index.d.ts +1962 -0
- package/dist/typed/index.js +193 -0
- package/dist/typed/index.js.map +1 -0
- package/dist/typed/index.mjs +4 -0
- package/dist/typed/index.mjs.map +1 -0
- package/dist/types-Db0vauC3.d.mts +258 -0
- package/dist/types-Db0vauC3.d.ts +258 -0
- package/dist/types-VsDp2t8s.d.mts +30 -0
- package/dist/types-VsDp2t8s.d.ts +30 -0
- package/package.json +157 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkOPVES6W2_js = require('./chunk-OPVES6W2.js');
|
|
4
|
+
var chunkPZ5AY32C_js = require('./chunk-PZ5AY32C.js');
|
|
5
|
+
|
|
6
|
+
// src/input/index.ts
|
|
7
|
+
var input_exports = {};
|
|
8
|
+
chunkPZ5AY32C_js.__export(input_exports, {
|
|
9
|
+
clamp: () => clamp,
|
|
10
|
+
coerceArray: () => coerceArray,
|
|
11
|
+
coerceString: () => coerceString,
|
|
12
|
+
defaults: () => defaults,
|
|
13
|
+
isEmail: () => isEmail,
|
|
14
|
+
isIpAddress: () => isIpAddress,
|
|
15
|
+
isUrl: () => isUrl,
|
|
16
|
+
isUuid: () => isUuid,
|
|
17
|
+
parseBoolean: () => parseBoolean,
|
|
18
|
+
parseDate: () => parseDate,
|
|
19
|
+
parseInteger: () => parseInteger,
|
|
20
|
+
parseNumber: () => parseNumber,
|
|
21
|
+
parseUrl: () => parseUrl,
|
|
22
|
+
safeJsonParse: () => safeJsonParse,
|
|
23
|
+
safeJsonStringify: () => safeJsonStringify,
|
|
24
|
+
trimAll: () => trimAll
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// src/input/safeJsonParse.ts
|
|
28
|
+
function safeJsonParse(json) {
|
|
29
|
+
try {
|
|
30
|
+
const data = JSON.parse(json);
|
|
31
|
+
return chunkOPVES6W2_js.ok(data);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return chunkOPVES6W2_js.err(error instanceof Error ? error : new Error(String(error)));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/input/safeJsonStringify.ts
|
|
38
|
+
function safeJsonStringify(value, replacer, space) {
|
|
39
|
+
try {
|
|
40
|
+
const data = JSON.stringify(value, replacer, space);
|
|
41
|
+
return chunkOPVES6W2_js.ok(data);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return chunkOPVES6W2_js.err(error instanceof Error ? error : new Error(String(error)));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/input/parseNumber.ts
|
|
48
|
+
function parseNumber(value) {
|
|
49
|
+
if (value === null || value === void 0) {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === "number") {
|
|
53
|
+
return Number.isNaN(value) ? void 0 : value;
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === "string") {
|
|
56
|
+
const trimmed = value.trim();
|
|
57
|
+
if (trimmed === "") {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
const parsed = Number(trimmed);
|
|
61
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
62
|
+
}
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/input/parseInteger.ts
|
|
67
|
+
function parseInteger(value) {
|
|
68
|
+
if (value === null || value === void 0) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
if (typeof value === "number") {
|
|
72
|
+
return Number.isNaN(value) ? void 0 : Math.trunc(value);
|
|
73
|
+
}
|
|
74
|
+
if (typeof value === "string") {
|
|
75
|
+
const trimmed = value.trim();
|
|
76
|
+
if (trimmed === "") {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
const parsed = parseInt(trimmed, 10);
|
|
80
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
81
|
+
}
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/input/parseBoolean.ts
|
|
86
|
+
function parseBoolean(value) {
|
|
87
|
+
if (value === null || value === void 0) {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
if (typeof value === "boolean") {
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
if (typeof value === "number") {
|
|
94
|
+
if (value === 1) return true;
|
|
95
|
+
if (value === 0) return false;
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
if (typeof value === "string") {
|
|
99
|
+
const lower = value.toLowerCase().trim();
|
|
100
|
+
if (["true", "1", "yes", "on"].includes(lower)) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
if (["false", "0", "no", "off"].includes(lower)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/input/parseDate.ts
|
|
111
|
+
function parseDate(value) {
|
|
112
|
+
if (value === null || value === void 0) {
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
if (value instanceof Date) {
|
|
116
|
+
return Number.isNaN(value.getTime()) ? void 0 : value;
|
|
117
|
+
}
|
|
118
|
+
if (typeof value === "number") {
|
|
119
|
+
const date = new Date(value);
|
|
120
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
121
|
+
}
|
|
122
|
+
if (typeof value === "string") {
|
|
123
|
+
const trimmed = value.trim();
|
|
124
|
+
if (trimmed === "") {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
const date = new Date(trimmed);
|
|
128
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
129
|
+
}
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/input/coerceString.ts
|
|
134
|
+
function coerceString(value) {
|
|
135
|
+
if (value === null || value === void 0) {
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
if (typeof value === "string") {
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
return String(value);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/input/coerceArray.ts
|
|
145
|
+
function coerceArray(value) {
|
|
146
|
+
if (value === null || value === void 0) {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
return [...value];
|
|
151
|
+
}
|
|
152
|
+
return [value];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/input/trimAll.ts
|
|
156
|
+
function trimAll(obj) {
|
|
157
|
+
const result = { ...obj };
|
|
158
|
+
for (const key of Object.keys(result)) {
|
|
159
|
+
const value = result[key];
|
|
160
|
+
if (typeof value === "string") {
|
|
161
|
+
result[key] = value.trim();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/input/defaults.ts
|
|
168
|
+
function defaults(value, defaultValue, options = {}) {
|
|
169
|
+
const { treatEmptyStringAsNull = true } = options;
|
|
170
|
+
if (value === null || value === void 0) {
|
|
171
|
+
return defaultValue;
|
|
172
|
+
}
|
|
173
|
+
if (treatEmptyStringAsNull && value === "") {
|
|
174
|
+
return defaultValue;
|
|
175
|
+
}
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/input/clamp.ts
|
|
180
|
+
function clamp(value, min, max) {
|
|
181
|
+
if (min > max) {
|
|
182
|
+
throw new Error("min must be less than or equal to max");
|
|
183
|
+
}
|
|
184
|
+
return Math.min(Math.max(value, min), max);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/input/isEmail.ts
|
|
188
|
+
function isEmail(str) {
|
|
189
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
190
|
+
return emailRegex.test(str);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/input/isUrl.ts
|
|
194
|
+
function isUrl(str) {
|
|
195
|
+
try {
|
|
196
|
+
new URL(str);
|
|
197
|
+
return true;
|
|
198
|
+
} catch {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/input/isUuid.ts
|
|
204
|
+
function isUuid(str) {
|
|
205
|
+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
206
|
+
return uuidRegex.test(str);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/input/isIpAddress.ts
|
|
210
|
+
function isIpAddress(str) {
|
|
211
|
+
return isIpv4(str) || isIpv6(str);
|
|
212
|
+
}
|
|
213
|
+
function isIpv4(str) {
|
|
214
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
215
|
+
return ipv4Regex.test(str);
|
|
216
|
+
}
|
|
217
|
+
function isIpv6(str) {
|
|
218
|
+
const ipv6Regex = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:){1,7}:$|^(?:[0-9a-fA-F]{1,4}:){0,6}::(?:[0-9a-fA-F]{1,4}:){0,5}[0-9a-fA-F]{1,4}$/;
|
|
219
|
+
return ipv6Regex.test(str);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/input/parseUrl.ts
|
|
223
|
+
function parseUrl(str) {
|
|
224
|
+
try {
|
|
225
|
+
return new URL(str);
|
|
226
|
+
} catch {
|
|
227
|
+
return void 0;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
exports.clamp = clamp;
|
|
232
|
+
exports.coerceArray = coerceArray;
|
|
233
|
+
exports.coerceString = coerceString;
|
|
234
|
+
exports.defaults = defaults;
|
|
235
|
+
exports.input_exports = input_exports;
|
|
236
|
+
exports.isEmail = isEmail;
|
|
237
|
+
exports.isIpAddress = isIpAddress;
|
|
238
|
+
exports.isUrl = isUrl;
|
|
239
|
+
exports.isUuid = isUuid;
|
|
240
|
+
exports.parseBoolean = parseBoolean;
|
|
241
|
+
exports.parseDate = parseDate;
|
|
242
|
+
exports.parseInteger = parseInteger;
|
|
243
|
+
exports.parseNumber = parseNumber;
|
|
244
|
+
exports.parseUrl = parseUrl;
|
|
245
|
+
exports.safeJsonParse = safeJsonParse;
|
|
246
|
+
exports.safeJsonStringify = safeJsonStringify;
|
|
247
|
+
exports.trimAll = trimAll;
|
|
248
|
+
//# sourceMappingURL=chunk-TXU7NTT4.js.map
|
|
249
|
+
//# sourceMappingURL=chunk-TXU7NTT4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/input/index.ts","../src/input/safeJsonParse.ts","../src/input/safeJsonStringify.ts","../src/input/parseNumber.ts","../src/input/parseInteger.ts","../src/input/parseBoolean.ts","../src/input/parseDate.ts","../src/input/coerceString.ts","../src/input/coerceArray.ts","../src/input/trimAll.ts","../src/input/defaults.ts","../src/input/clamp.ts","../src/input/isEmail.ts","../src/input/isUrl.ts","../src/input/isUuid.ts","../src/input/isIpAddress.ts","../src/input/parseUrl.ts"],"names":["__export","ok","err"],"mappings":";;;;;;AAAA,IAAA,aAAA,GAAA;AAAAA,yBAAA,CAAA,aAAA,EAAA;AAAA,EAAA,KAAA,EAAA,MAAA,KAAA;AAAA,EAAA,WAAA,EAAA,MAAA,WAAA;AAAA,EAAA,YAAA,EAAA,MAAA,YAAA;AAAA,EAAA,QAAA,EAAA,MAAA,QAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,WAAA,EAAA,MAAA,WAAA;AAAA,EAAA,KAAA,EAAA,MAAA,KAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,YAAA,EAAA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SAAA,CAAU,KAAK,GAAG,CAAA;AAC3B;;;ACbO,SAAS,SAAS,GAAA,EAA8B;AACrD,EAAA,IAAI;AACF,IAAA,OAAO,IAAI,IAAI,GAAG,CAAA;AAAA,EACpB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF","file":"chunk-TXU7NTT4.js","sourcesContent":["export { safeJsonParse } from './safeJsonParse'\nexport type { JsonParseResult } from './safeJsonParse'\nexport { safeJsonStringify } from './safeJsonStringify'\nexport type { JsonStringifyResult } from './safeJsonStringify'\nexport { parseNumber } from './parseNumber'\nexport { parseInteger } from './parseInteger'\nexport { parseBoolean } from './parseBoolean'\nexport { parseDate } from './parseDate'\nexport { coerceString } from './coerceString'\nexport { coerceArray } from './coerceArray'\nexport { trimAll } from './trimAll'\nexport { defaults } from './defaults'\nexport { clamp } from './clamp'\nexport { isEmail } from './isEmail'\nexport { isUrl } from './isUrl'\nexport { isUuid } from './isUuid'\nexport { isIpAddress } from './isIpAddress'\nexport { parseUrl } from './parseUrl'\n","import type { Result } from '../result/types'\nimport { ok } from '../result/ok'\nimport { err } from '../result/err'\n\n/**\n * @deprecated Use Result<T> instead\n */\nexport type JsonParseResult<T> = Result<T, Error>\n\n/**\n * Safely parses a JSON string. Returns a Result instead of throwing.\n *\n * @example\n * const result = safeJsonParse<User>('{\"name\": \"John\"}')\n * if (result.ok) {\n * console.log(result.value.name)\n * } else {\n * console.error(result.error)\n * }\n */\nexport function safeJsonParse<T = unknown>(json: string): Result<T, Error> {\n try {\n const data = JSON.parse(json) as T\n return ok(data)\n } catch (error) {\n return err(error instanceof Error ? error : new Error(String(error)))\n }\n}\n","import type { Result } from '../result/types'\nimport { ok } from '../result/ok'\nimport { err } from '../result/err'\n\n/**\n * @deprecated Use Result<string> instead\n */\nexport type JsonStringifyResult = Result<string, Error>\n\n/**\n * Safely stringifies a value to JSON. Returns a Result instead of throwing.\n * Handles circular references gracefully.\n *\n * @example\n * const result = safeJsonStringify({ name: 'John' })\n * if (result.ok) {\n * console.log(result.value)\n * }\n */\nexport function safeJsonStringify(\n value: unknown,\n replacer?: (key: string, value: unknown) => unknown,\n space?: string | number\n): Result<string, Error> {\n try {\n const data = JSON.stringify(value, replacer, space)\n return ok(data)\n } catch (error) {\n return err(error instanceof Error ? error : new Error(String(error)))\n }\n}\n","/**\n * Parses a value to a number. Returns undefined if parsing fails.\n * Handles strings, numbers, and null/undefined.\n *\n * @example\n * parseNumber('42') // 42\n * parseNumber('3.14') // 3.14\n * parseNumber('abc') // undefined\n * parseNumber(null) // undefined\n */\nexport function parseNumber(value: unknown): number | undefined {\n if (value === null || value === undefined) {\n return undefined\n }\n\n if (typeof value === 'number') {\n return Number.isNaN(value) ? undefined : value\n }\n\n if (typeof value === 'string') {\n const trimmed = value.trim()\n if (trimmed === '') {\n return undefined\n }\n\n const parsed = Number(trimmed)\n return Number.isNaN(parsed) ? undefined : parsed\n }\n\n return undefined\n}\n","/**\n * Parses a value to an integer. Returns undefined if parsing fails.\n *\n * @example\n * parseInteger('42') // 42\n * parseInteger('3.14') // 3\n * parseInteger('abc') // undefined\n */\nexport function parseInteger(value: unknown): number | undefined {\n if (value === null || value === undefined) {\n return undefined\n }\n\n if (typeof value === 'number') {\n return Number.isNaN(value) ? undefined : Math.trunc(value)\n }\n\n if (typeof value === 'string') {\n const trimmed = value.trim()\n if (trimmed === '') {\n return undefined\n }\n\n const parsed = parseInt(trimmed, 10)\n return Number.isNaN(parsed) ? undefined : parsed\n }\n\n return undefined\n}\n","/**\n * Parses a value to a boolean. Returns undefined if parsing fails.\n * Recognizes: true/false, 'true'/'false', '1'/'0', 1/0, 'yes'/'no', 'on'/'off'\n *\n * @example\n * parseBoolean('true') // true\n * parseBoolean('false') // false\n * parseBoolean(1) // true\n * parseBoolean('yes') // true\n * parseBoolean('maybe') // undefined\n */\nexport function parseBoolean(value: unknown): boolean | undefined {\n if (value === null || value === undefined) {\n return undefined\n }\n\n if (typeof value === 'boolean') {\n return value\n }\n\n if (typeof value === 'number') {\n if (value === 1) return true\n if (value === 0) return false\n return undefined\n }\n\n if (typeof value === 'string') {\n const lower = value.toLowerCase().trim()\n\n if (['true', '1', 'yes', 'on'].includes(lower)) {\n return true\n }\n\n if (['false', '0', 'no', 'off'].includes(lower)) {\n return false\n }\n }\n\n return undefined\n}\n","/**\n * Parses a value to a Date. Returns undefined if parsing fails or date is invalid.\n *\n * @example\n * parseDate('2024-01-15') // Date object\n * parseDate(1705276800000) // Date object\n * parseDate('invalid') // undefined\n */\nexport function parseDate(value: unknown): Date | undefined {\n if (value === null || value === undefined) {\n return undefined\n }\n\n if (value instanceof Date) {\n return Number.isNaN(value.getTime()) ? undefined : value\n }\n\n if (typeof value === 'number') {\n const date = new Date(value)\n return Number.isNaN(date.getTime()) ? undefined : date\n }\n\n if (typeof value === 'string') {\n const trimmed = value.trim()\n if (trimmed === '') {\n return undefined\n }\n\n const date = new Date(trimmed)\n return Number.isNaN(date.getTime()) ? undefined : date\n }\n\n return undefined\n}\n","/**\n * Coerces a value to a string. Returns empty string for null/undefined.\n *\n * @example\n * coerceString('hello') // 'hello'\n * coerceString(42) // '42'\n * coerceString(null) // ''\n * coerceString(undefined) // ''\n */\nexport function coerceString(value: unknown): string {\n if (value === null || value === undefined) {\n return ''\n }\n\n if (typeof value === 'string') {\n return value\n }\n\n return String(value)\n}\n","/**\n * Coerces a value to an array.\n * - Arrays are returned as-is\n * - null/undefined returns empty array\n * - Other values are wrapped in an array\n *\n * @example\n * coerceArray([1, 2, 3]) // [1, 2, 3]\n * coerceArray('hello') // ['hello']\n * coerceArray(null) // []\n */\nexport function coerceArray<T>(value: T | readonly T[] | null | undefined): T[] {\n if (value === null || value === undefined) {\n return []\n }\n\n if (Array.isArray(value)) {\n return [...value]\n }\n\n return [value as T]\n}\n","/**\n * Trims all string values in an object (shallow).\n *\n * @example\n * trimAll({ name: ' John ', age: 30 })\n * // { name: 'John', age: 30 }\n */\nexport function trimAll<T extends Record<string, unknown>>(obj: T): T {\n const result = { ...obj }\n\n for (const key of Object.keys(result)) {\n const value = result[key]\n if (typeof value === 'string') {\n ;(result as Record<string, unknown>)[key] = value.trim()\n }\n }\n\n return result\n}\n","/**\n * Returns the value if defined, otherwise returns the default value.\n * Unlike the ?? operator, this also handles empty strings.\n *\n * @example\n * defaults(null, 'default') // 'default'\n * defaults(undefined, 'default') // 'default'\n * defaults('', 'default') // 'default'\n * defaults('value', 'default') // 'value'\n * defaults(0, 10) // 0 (0 is a valid value)\n */\nexport function defaults<T>(\n value: T | null | undefined,\n defaultValue: T,\n options: { treatEmptyStringAsNull?: boolean } = {}\n): T {\n const { treatEmptyStringAsNull = true } = options\n\n if (value === null || value === undefined) {\n return defaultValue\n }\n\n if (treatEmptyStringAsNull && value === '') {\n return defaultValue\n }\n\n return value\n}\n","/**\n * Clamps a number between a minimum and maximum value.\n *\n * @example\n * clamp(5, 0, 10) // 5\n * clamp(-5, 0, 10) // 0\n * clamp(15, 0, 10) // 10\n */\nexport function clamp(value: number, min: number, max: number): number {\n if (min > max) {\n throw new Error('min must be less than or equal to max')\n }\n\n return Math.min(Math.max(value, min), max)\n}\n","/**\n * Checks if a string is a valid email address.\n *\n * @example\n * isEmail('user@example.com') // true\n * isEmail('invalid-email') // false\n */\nexport function isEmail(str: string): boolean {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n return emailRegex.test(str)\n}\n","/**\n * Checks if a string is a valid URL.\n *\n * @example\n * isUrl('https://example.com') // true\n * isUrl('not-a-url') // false\n */\nexport function isUrl(str: string): boolean {\n try {\n new URL(str)\n return true\n } catch {\n return false\n }\n}\n","/**\n * Checks if a string is a valid UUID (v1-v5).\n *\n * @example\n * isUuid('550e8400-e29b-41d4-a716-446655440000') // true\n * isUuid('not-a-uuid') // false\n */\nexport function isUuid(str: string): boolean {\n const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i\n return uuidRegex.test(str)\n}\n","/**\n * Checks if a string is a valid IPv4 or IPv6 address.\n *\n * @example\n * isIpAddress('192.168.1.1') // true\n * isIpAddress('::1') // true\n * isIpAddress('not-an-ip') // false\n */\nexport function isIpAddress(str: string): boolean {\n return isIpv4(str) || isIpv6(str)\n}\n\nfunction isIpv4(str: string): boolean {\n const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/\n return ipv4Regex.test(str)\n}\n\nfunction isIpv6(str: string): boolean {\n const ipv6Regex = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:){1,7}:$|^(?:[0-9a-fA-F]{1,4}:){0,6}::(?:[0-9a-fA-F]{1,4}:){0,5}[0-9a-fA-F]{1,4}$/\n return ipv6Regex.test(str)\n}\n","/**\n * Parses a URL string and returns a URL object, or undefined if invalid.\n *\n * @example\n * parseUrl('https://example.com/path') // URL object\n * parseUrl('not-a-url') // undefined\n */\nexport function parseUrl(str: string): URL | undefined {\n try {\n return new URL(str)\n } catch {\n return undefined\n }\n}\n"]}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { __export } from './chunk-J5LGTIGS.mjs';
|
|
2
|
+
|
|
3
|
+
// src/decorator/index.ts
|
|
4
|
+
var decorator_exports = {};
|
|
5
|
+
__export(decorator_exports, {
|
|
6
|
+
Bind: () => Bind,
|
|
7
|
+
Debounce: () => Debounce,
|
|
8
|
+
Deprecated: () => Deprecated,
|
|
9
|
+
Frozen: () => Frozen,
|
|
10
|
+
Lazy: () => Lazy,
|
|
11
|
+
Log: () => Log,
|
|
12
|
+
Measure: () => Measure,
|
|
13
|
+
Memoize: () => Memoize,
|
|
14
|
+
Retry: () => Retry,
|
|
15
|
+
Sealed: () => Sealed,
|
|
16
|
+
Throttle: () => Throttle,
|
|
17
|
+
Validate: () => Validate
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// src/decorator/Memoize.ts
|
|
21
|
+
function Memoize(resolver) {
|
|
22
|
+
return function(_target, _propertyKey, descriptor) {
|
|
23
|
+
const originalMethod = descriptor.value;
|
|
24
|
+
if (typeof originalMethod !== "function") {
|
|
25
|
+
throw new Error("@Memoize can only be applied to methods");
|
|
26
|
+
}
|
|
27
|
+
const cache = /* @__PURE__ */ new Map();
|
|
28
|
+
descriptor.value = function(...args) {
|
|
29
|
+
const key = resolver ? resolver(...args) : args[0];
|
|
30
|
+
if (cache.has(key)) {
|
|
31
|
+
return cache.get(key);
|
|
32
|
+
}
|
|
33
|
+
const result = originalMethod.apply(this, args);
|
|
34
|
+
cache.set(key, result);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
return descriptor;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/decorator/Debounce.ts
|
|
42
|
+
function Debounce(wait) {
|
|
43
|
+
return function(_target, _propertyKey, descriptor) {
|
|
44
|
+
const originalMethod = descriptor.value;
|
|
45
|
+
if (typeof originalMethod !== "function") {
|
|
46
|
+
throw new Error("@Debounce can only be applied to methods");
|
|
47
|
+
}
|
|
48
|
+
let timeoutId;
|
|
49
|
+
descriptor.value = function(...args) {
|
|
50
|
+
if (timeoutId !== void 0) {
|
|
51
|
+
clearTimeout(timeoutId);
|
|
52
|
+
}
|
|
53
|
+
timeoutId = setTimeout(() => {
|
|
54
|
+
originalMethod.apply(this, args);
|
|
55
|
+
}, wait);
|
|
56
|
+
};
|
|
57
|
+
return descriptor;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/decorator/Throttle.ts
|
|
62
|
+
function Throttle(wait) {
|
|
63
|
+
return function(_target, _propertyKey, descriptor) {
|
|
64
|
+
const originalMethod = descriptor.value;
|
|
65
|
+
if (typeof originalMethod !== "function") {
|
|
66
|
+
throw new Error("@Throttle can only be applied to methods");
|
|
67
|
+
}
|
|
68
|
+
let lastCall = 0;
|
|
69
|
+
let timeoutId;
|
|
70
|
+
descriptor.value = function(...args) {
|
|
71
|
+
const now = Date.now();
|
|
72
|
+
const remaining = wait - (now - lastCall);
|
|
73
|
+
if (remaining <= 0) {
|
|
74
|
+
if (timeoutId !== void 0) {
|
|
75
|
+
clearTimeout(timeoutId);
|
|
76
|
+
timeoutId = void 0;
|
|
77
|
+
}
|
|
78
|
+
lastCall = now;
|
|
79
|
+
originalMethod.apply(this, args);
|
|
80
|
+
} else if (timeoutId === void 0) {
|
|
81
|
+
timeoutId = setTimeout(() => {
|
|
82
|
+
lastCall = Date.now();
|
|
83
|
+
timeoutId = void 0;
|
|
84
|
+
originalMethod.apply(this, args);
|
|
85
|
+
}, remaining);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return descriptor;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/decorator/Bind.ts
|
|
93
|
+
function Bind() {
|
|
94
|
+
return function(_target, propertyKey, descriptor) {
|
|
95
|
+
const originalMethod = descriptor.value;
|
|
96
|
+
if (typeof originalMethod !== "function") {
|
|
97
|
+
throw new Error("@Bind can only be applied to methods");
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
configurable: true,
|
|
101
|
+
enumerable: false,
|
|
102
|
+
get() {
|
|
103
|
+
const bound = originalMethod.bind(this);
|
|
104
|
+
Object.defineProperty(this, propertyKey, {
|
|
105
|
+
value: bound,
|
|
106
|
+
configurable: true,
|
|
107
|
+
writable: true
|
|
108
|
+
});
|
|
109
|
+
return bound;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/decorator/Log.ts
|
|
116
|
+
function Log(options) {
|
|
117
|
+
const prefix = options?.prefix ?? "";
|
|
118
|
+
return function(_target, propertyKey, descriptor) {
|
|
119
|
+
const originalMethod = descriptor.value;
|
|
120
|
+
if (typeof originalMethod !== "function") {
|
|
121
|
+
throw new Error("@Log can only be applied to methods");
|
|
122
|
+
}
|
|
123
|
+
descriptor.value = function(...args) {
|
|
124
|
+
const methodName = String(propertyKey);
|
|
125
|
+
const argsStr = args.map((a) => JSON.stringify(a)).join(", ");
|
|
126
|
+
const result = originalMethod.apply(this, args);
|
|
127
|
+
if (result instanceof Promise) {
|
|
128
|
+
return result.then((res) => {
|
|
129
|
+
console.log(`${prefix}${methodName}(${argsStr}) => ${JSON.stringify(res)}`);
|
|
130
|
+
return res;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
console.log(`${prefix}${methodName}(${argsStr}) => ${JSON.stringify(result)}`);
|
|
134
|
+
return result;
|
|
135
|
+
};
|
|
136
|
+
return descriptor;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/decorator/Measure.ts
|
|
141
|
+
function Measure(options) {
|
|
142
|
+
return function(_target, propertyKey, descriptor) {
|
|
143
|
+
const originalMethod = descriptor.value;
|
|
144
|
+
if (typeof originalMethod !== "function") {
|
|
145
|
+
throw new Error("@Measure can only be applied to methods");
|
|
146
|
+
}
|
|
147
|
+
const label = options?.label ?? String(propertyKey);
|
|
148
|
+
descriptor.value = function(...args) {
|
|
149
|
+
const start = performance.now();
|
|
150
|
+
const result = originalMethod.apply(this, args);
|
|
151
|
+
if (result instanceof Promise) {
|
|
152
|
+
return result.finally(() => {
|
|
153
|
+
const duration2 = performance.now() - start;
|
|
154
|
+
console.log(`${label} took ${duration2.toFixed(2)}ms`);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const duration = performance.now() - start;
|
|
158
|
+
console.log(`${label} took ${duration.toFixed(2)}ms`);
|
|
159
|
+
return result;
|
|
160
|
+
};
|
|
161
|
+
return descriptor;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/decorator/Retry.ts
|
|
166
|
+
function Retry(options) {
|
|
167
|
+
const attempts = options?.attempts ?? 3;
|
|
168
|
+
const delay = options?.delay ?? 0;
|
|
169
|
+
const onRetry = options?.onRetry;
|
|
170
|
+
return function(_target, _propertyKey, descriptor) {
|
|
171
|
+
const originalMethod = descriptor.value;
|
|
172
|
+
if (typeof originalMethod !== "function") {
|
|
173
|
+
throw new Error("@Retry can only be applied to methods");
|
|
174
|
+
}
|
|
175
|
+
descriptor.value = async function(...args) {
|
|
176
|
+
let lastError;
|
|
177
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
178
|
+
try {
|
|
179
|
+
const result = originalMethod.apply(this, args);
|
|
180
|
+
if (result instanceof Promise) {
|
|
181
|
+
return await result;
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
} catch (error) {
|
|
185
|
+
lastError = error;
|
|
186
|
+
if (attempt < attempts) {
|
|
187
|
+
onRetry?.(error, attempt);
|
|
188
|
+
if (delay > 0) {
|
|
189
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
throw lastError;
|
|
195
|
+
};
|
|
196
|
+
return descriptor;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/decorator/Deprecated.ts
|
|
201
|
+
function Deprecated(message) {
|
|
202
|
+
return function(_target, propertyKey, descriptor) {
|
|
203
|
+
const originalMethod = descriptor.value;
|
|
204
|
+
if (typeof originalMethod !== "function") {
|
|
205
|
+
throw new Error("@Deprecated can only be applied to methods");
|
|
206
|
+
}
|
|
207
|
+
const methodName = String(propertyKey);
|
|
208
|
+
const warning = message ? `${methodName} is deprecated: ${message}` : `${methodName} is deprecated`;
|
|
209
|
+
descriptor.value = function(...args) {
|
|
210
|
+
console.warn(warning);
|
|
211
|
+
return originalMethod.apply(this, args);
|
|
212
|
+
};
|
|
213
|
+
return descriptor;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/decorator/Sealed.ts
|
|
218
|
+
function Sealed() {
|
|
219
|
+
return function(constructor) {
|
|
220
|
+
Object.seal(constructor);
|
|
221
|
+
Object.seal(constructor.prototype);
|
|
222
|
+
return constructor;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/decorator/Frozen.ts
|
|
227
|
+
function Frozen() {
|
|
228
|
+
return function(constructor) {
|
|
229
|
+
Object.freeze(constructor);
|
|
230
|
+
Object.freeze(constructor.prototype);
|
|
231
|
+
return constructor;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/decorator/Validate.ts
|
|
236
|
+
function Validate(predicate, errorMessage) {
|
|
237
|
+
return function(_target, propertyKey, descriptor) {
|
|
238
|
+
const originalMethod = descriptor.value;
|
|
239
|
+
if (typeof originalMethod !== "function") {
|
|
240
|
+
throw new Error("@Validate can only be applied to methods");
|
|
241
|
+
}
|
|
242
|
+
const methodName = String(propertyKey);
|
|
243
|
+
descriptor.value = function(...args) {
|
|
244
|
+
if (!predicate(...args)) {
|
|
245
|
+
throw new Error(
|
|
246
|
+
errorMessage ?? `Validation failed for ${methodName}`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
return originalMethod.apply(this, args);
|
|
250
|
+
};
|
|
251
|
+
return descriptor;
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/decorator/Lazy.ts
|
|
256
|
+
function Lazy() {
|
|
257
|
+
return function(_target, propertyKey, descriptor) {
|
|
258
|
+
const getter = descriptor.get;
|
|
259
|
+
if (typeof getter !== "function") {
|
|
260
|
+
throw new Error("@Lazy can only be applied to getters");
|
|
261
|
+
}
|
|
262
|
+
descriptor.get = function() {
|
|
263
|
+
const value = getter.call(this);
|
|
264
|
+
Object.defineProperty(this, propertyKey, {
|
|
265
|
+
value,
|
|
266
|
+
configurable: false,
|
|
267
|
+
writable: false
|
|
268
|
+
});
|
|
269
|
+
return value;
|
|
270
|
+
};
|
|
271
|
+
return descriptor;
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export { Bind, Debounce, Deprecated, Frozen, Lazy, Log, Measure, Memoize, Retry, Sealed, Throttle, Validate, decorator_exports };
|
|
276
|
+
//# sourceMappingURL=chunk-TZEWREAC.mjs.map
|
|
277
|
+
//# sourceMappingURL=chunk-TZEWREAC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/decorator/index.ts","../src/decorator/Memoize.ts","../src/decorator/Debounce.ts","../src/decorator/Throttle.ts","../src/decorator/Bind.ts","../src/decorator/Log.ts","../src/decorator/Measure.ts","../src/decorator/Retry.ts","../src/decorator/Deprecated.ts","../src/decorator/Sealed.ts","../src/decorator/Frozen.ts","../src/decorator/Validate.ts","../src/decorator/Lazy.ts"],"names":["duration"],"mappings":";;;AAAA,IAAA,iBAAA,GAAA;AAAA,QAAA,CAAA,iBAAA,EAAA;AAAA,EAAA,IAAA,EAAA,MAAA,IAAA;AAAA,EAAA,QAAA,EAAA,MAAA,QAAA;AAAA,EAAA,UAAA,EAAA,MAAA,UAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,IAAA,EAAA,MAAA,IAAA;AAAA,EAAA,GAAA,EAAA,MAAA,GAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,KAAA,EAAA,MAAA,KAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,QAAA,EAAA,MAAA,QAAA;AAAA,EAAA,QAAA,EAAA,MAAA;AAAA,CAAA,CAAA;;;ACYO,SAAS,QACd,QAAA,EACiB;AACjB,EAAA,OAAO,SACL,OAAA,EACA,YAAA,EACA,UAAA,EAC4B;AAC5B,IAAA,MAAM,iBAAiB,UAAA,CAAW,KAAA;AAElC,IAAA,IAAI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orators for common patterns.\n * These decorators work with the new TC39 decorator standard.\n */\n\nexport { Memoize } from './Memoize.js'\nexport { Debounce } from './Debounce.js'\nexport { Throttle } from './Throttle.js'\nexport { Bind } from './Bind.js'\nexport { Log } from './Log.js'\nexport { Measure } from './Measure.js'\nexport { Retry } from './Retry.js'\nexport { Deprecated } from './Deprecated.js'\nexport { Sealed } from './Sealed.js'\nexport { Frozen } from './Frozen.js'\nexport { Validate } from './Validate.js'\nexport { Lazy } from './Lazy.js'\n","/**\n * Memoizes a method, caching its results based on arguments.\n *\n * @example\n * class Calculator {\n * @Memoize()\n * fibonacci(n: number): number {\n * if (n <= 1) return n\n * return this.fibonacci(n - 1) + this.fibonacci(n - 2)\n * }\n * }\n */\nexport function Memoize(\n resolver?: (...args: unknown[]) => unknown\n): MethodDecorator {\n return function <T>(\n _target: object,\n _propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value as unknown as (...args: unknown[]) => unknown\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Memoize can only be applied to methods')\n }\n\n const cache = new Map<unknown, unknown>()\n\n descriptor.value = function (this: unknown, ...args: unknown[]): unknown {\n const key = resolver ? resolver(...args) : args[0]\n\n if (cache.has(key)) {\n return cache.get(key)\n }\n\n const result = originalMethod.apply(this, args)\n cache.set(key, result)\n return result\n } as unknown as T\n\n return descriptor\n }\n}\n","/**\n * Debounces a method, delaying execution until after wait milliseconds.\n *\n * @example\n * class SearchBox {\n * @Debounce(300)\n * search(query: string) {\n * console.log('Searching:', query)\n * }\n * }\n */\nexport function Debounce(wait: number): MethodDecorator {\n return function <T>(\n _target: object,\n _propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value as unknown as (...args: unknown[]) => unknown\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Debounce can only be applied to methods')\n }\n\n let timeoutId: ReturnType<typeof setTimeout> | undefined\n\n descriptor.value = function (this: unknown, ...args: unknown[]): void {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId)\n }\n\n timeoutId = setTimeout(() => {\n originalMethod.apply(this, args)\n }, wait)\n } as unknown as T\n\n return descriptor\n }\n}\n","/**\n * Throttles a method, limiting execution to once per wait milliseconds.\n *\n * @example\n * class ScrollHandler {\n * @Throttle(100)\n * onScroll(event: Event) {\n * console.log('Scroll event')\n * }\n * }\n */\nexport function Throttle(wait: number): MethodDecorator {\n return function <T>(\n _target: object,\n _propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value as unknown as (...args: unknown[]) => unknown\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Throttle can only be applied to methods')\n }\n\n let lastCall = 0\n let timeoutId: ReturnType<typeof setTimeout> | undefined\n\n descriptor.value = function (this: unknown, ...args: unknown[]): void {\n const now = Date.now()\n const remaining = wait - (now - lastCall)\n\n if (remaining <= 0) {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId)\n timeoutId = undefined\n }\n lastCall = now\n originalMethod.apply(this, args)\n } else if (timeoutId === undefined) {\n timeoutId = setTimeout(() => {\n lastCall = Date.now()\n timeoutId = undefined\n originalMethod.apply(this, args)\n }, remaining)\n }\n } as unknown as T\n\n return descriptor\n }\n}\n","/**\n * Binds a method to its class instance.\n * Useful for event handlers and callbacks.\n *\n * @example\n * class Button {\n * @Bind()\n * onClick() {\n * console.log(this) // Always the Button instance\n * }\n * }\n */\nexport function Bind(): MethodDecorator {\n return function <T>(\n _target: object,\n propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Bind can only be applied to methods')\n }\n\n return {\n configurable: true,\n enumerable: false,\n get(this: object): T {\n const bound = (originalMethod as (...args: unknown[]) => unknown).bind(this)\n Object.defineProperty(this, propertyKey, {\n value: bound,\n configurable: true,\n writable: true,\n })\n return bound as T\n },\n }\n }\n}\n","/**\n * Logs method calls with arguments and return values.\n *\n * @example\n * class Calculator {\n * @Log()\n * add(a: number, b: number): number {\n * return a + b\n * }\n * }\n * // Logs: \"add(1, 2) => 3\"\n */\nexport function Log(options?: { prefix?: string }): MethodDecorator {\n const prefix = options?.prefix ?? ''\n\n return function <T>(\n _target: object,\n propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value as unknown as (...args: unknown[]) => unknown\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Log can only be applied to methods')\n }\n\n descriptor.value = function (this: unknown, ...args: unknown[]): unknown {\n const methodName = String(propertyKey)\n const argsStr = args.map((a) => JSON.stringify(a)).join(', ')\n\n const result = originalMethod.apply(this, args)\n\n if (result instanceof Promise) {\n return result.then((res) => {\n console.log(`${prefix}${methodName}(${argsStr}) => ${JSON.stringify(res)}`)\n return res\n })\n }\n\n console.log(`${prefix}${methodName}(${argsStr}) => ${JSON.stringify(result)}`)\n return result\n } as unknown as T\n\n return descriptor\n }\n}\n","/**\n * Measures and logs the execution time of a method.\n *\n * @example\n * class DataProcessor {\n * @Measure()\n * processData(data: unknown[]) {\n * // Heavy processing\n * }\n * }\n * // Logs: \"processData took 123.45ms\"\n */\nexport function Measure(options?: { label?: string }): MethodDecorator {\n return function <T>(\n _target: object,\n propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value as unknown as (...args: unknown[]) => unknown\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Measure can only be applied to methods')\n }\n\n const label = options?.label ?? String(propertyKey)\n\n descriptor.value = function (this: unknown, ...args: unknown[]): unknown {\n const start = performance.now()\n const result = originalMethod.apply(this, args)\n\n if (result instanceof Promise) {\n return result.finally(() => {\n const duration = performance.now() - start\n console.log(`${label} took ${duration.toFixed(2)}ms`)\n })\n }\n\n const duration = performance.now() - start\n console.log(`${label} took ${duration.toFixed(2)}ms`)\n return result\n } as unknown as T\n\n return descriptor\n }\n}\n","/**\n * Retries a method on failure.\n *\n * @example\n * class ApiClient {\n * @Retry({ attempts: 3, delay: 1000 })\n * async fetchData(): Promise<Data> {\n * return fetch('/api/data').then(r => r.json())\n * }\n * }\n */\nexport function Retry(options?: {\n attempts?: number\n delay?: number\n onRetry?: (error: unknown, attempt: number) => void\n}): MethodDecorator {\n const attempts = options?.attempts ?? 3\n const delay = options?.delay ?? 0\n const onRetry = options?.onRetry\n\n return function <T>(\n _target: object,\n _propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value as unknown as (...args: unknown[]) => unknown\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Retry can only be applied to methods')\n }\n\n descriptor.value = async function (this: unknown, ...args: unknown[]): Promise<unknown> {\n let lastError: unknown\n\n for (let attempt = 1; attempt <= attempts; attempt++) {\n try {\n const result = originalMethod.apply(this, args)\n if (result instanceof Promise) {\n return await result\n }\n return result\n } catch (error) {\n lastError = error\n if (attempt < attempts) {\n onRetry?.(error, attempt)\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay))\n }\n }\n }\n }\n\n throw lastError\n } as unknown as T\n\n return descriptor\n }\n}\n","/**\n * Marks a method as deprecated and logs a warning when called.\n *\n * @example\n * class Api {\n * @Deprecated('Use newMethod() instead')\n * oldMethod() {\n * // ...\n * }\n * }\n */\nexport function Deprecated(message?: string): MethodDecorator {\n return function <T>(\n _target: object,\n propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value as unknown as (...args: unknown[]) => unknown\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Deprecated can only be applied to methods')\n }\n\n const methodName = String(propertyKey)\n const warning = message\n ? `${methodName} is deprecated: ${message}`\n : `${methodName} is deprecated`\n\n descriptor.value = function (this: unknown, ...args: unknown[]): unknown {\n console.warn(warning)\n return originalMethod.apply(this, args)\n } as unknown as T\n\n return descriptor\n }\n}\n","/**\n * Seals a class, preventing new properties from being added.\n *\n * @example\n * @Sealed()\n * class Config {\n * readonly apiUrl = 'https://api.example.com'\n * }\n */\nexport function Sealed(): <T extends new (...args: any[]) => object>(constructor: T) => T {\n return function <T extends new (...args: any[]) => object>(\n constructor: T\n ): T {\n Object.seal(constructor)\n Object.seal(constructor.prototype)\n return constructor\n }\n}\n","/**\n * Freezes a class, making it completely immutable.\n *\n * @example\n * @Frozen()\n * class Constants {\n * static readonly PI = 3.14159\n * }\n */\nexport function Frozen(): <T extends new (...args: any[]) => object>(constructor: T) => T {\n return function <T extends new (...args: any[]) => object>(\n constructor: T\n ): T {\n Object.freeze(constructor)\n Object.freeze(constructor.prototype)\n return constructor\n }\n}\n","/**\n * Validates method arguments using a predicate.\n *\n * @example\n * class User {\n * @Validate((age: number) => age >= 0 && age <= 150, 'Invalid age')\n * setAge(age: number) {\n * this.age = age\n * }\n * }\n */\nexport function Validate(\n predicate: (...args: unknown[]) => boolean,\n errorMessage?: string\n): MethodDecorator {\n return function <T>(\n _target: object,\n propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const originalMethod = descriptor.value as unknown as (...args: unknown[]) => unknown\n\n if (typeof originalMethod !== 'function') {\n throw new Error('@Validate can only be applied to methods')\n }\n\n const methodName = String(propertyKey)\n\n descriptor.value = function (this: unknown, ...args: unknown[]): unknown {\n if (!predicate(...args)) {\n throw new Error(\n errorMessage ?? `Validation failed for ${methodName}`\n )\n }\n return originalMethod.apply(this, args)\n } as unknown as T\n\n return descriptor\n }\n}\n","/**\n * Lazily initializes a property on first access.\n *\n * @example\n * class Service {\n * @Lazy()\n * get expensiveData(): Data {\n * return computeExpensiveData()\n * }\n * }\n */\nexport function Lazy(): MethodDecorator {\n return function <T>(\n _target: object,\n propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<T>\n ): TypedPropertyDescriptor<T> {\n const getter = descriptor.get\n\n if (typeof getter !== 'function') {\n throw new Error('@Lazy can only be applied to getters')\n }\n\n descriptor.get = function (this: object): T {\n const value = getter.call(this)\n Object.defineProperty(this, propertyKey, {\n value,\n configurable: false,\n writable: false,\n })\n return value\n }\n\n return descriptor\n }\n}\n"]}
|