phecda-core 1.2.0 → 1.3.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/dist/index.d.ts +1 -21
- package/dist/index.global.js +434 -0
- package/dist/index.js +5 -118
- package/dist/index.mjs +5 -101
- package/dist/preset/index.d.ts +20 -0
- package/dist/preset/index.global.js +194 -0
- package/dist/preset/index.js +212 -0
- package/dist/preset/index.mjs +171 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ async function validate(p, v) {
|
|
|
15
15
|
}
|
|
16
16
|
__name(validate, "validate");
|
|
17
17
|
function getTag(Model) {
|
|
18
|
-
return Model.prototype?.
|
|
18
|
+
return Model.prototype?.__TAG__;
|
|
19
19
|
}
|
|
20
20
|
__name(getTag, "getTag");
|
|
21
21
|
function mergeOptions(obj1, obj2) {
|
|
@@ -48,7 +48,6 @@ __name(isPhecda, "isPhecda");
|
|
|
48
48
|
function init(target) {
|
|
49
49
|
if (!target._namespace) {
|
|
50
50
|
target._namespace = {
|
|
51
|
-
__TAG__: "",
|
|
52
51
|
__INIT_EVENT__: /* @__PURE__ */ new Set(),
|
|
53
52
|
__EXPOSE_VAR__: /* @__PURE__ */ new Set(),
|
|
54
53
|
__IGNORE_VAR__: /* @__PURE__ */ new Set(),
|
|
@@ -218,15 +217,14 @@ function Pipe(v) {
|
|
|
218
217
|
__name(Pipe, "Pipe");
|
|
219
218
|
function Tag(tag) {
|
|
220
219
|
return (target) => {
|
|
221
|
-
|
|
222
|
-
target.prototype._namespace.__TAG__ = tag;
|
|
220
|
+
target.prototype.__TAG__ = tag;
|
|
223
221
|
};
|
|
224
222
|
}
|
|
225
223
|
__name(Tag, "Tag");
|
|
226
224
|
function Global(target) {
|
|
227
225
|
if (!globalThis.__PHECDA__)
|
|
228
226
|
globalThis.__PHECDA__ = {};
|
|
229
|
-
const tag = target.prototype.
|
|
227
|
+
const tag = target.prototype.__TAG__;
|
|
230
228
|
if (tag)
|
|
231
229
|
globalThis.__PHECDA__[tag] = target;
|
|
232
230
|
}
|
|
@@ -307,83 +305,6 @@ function addDecoToClass(c, key, handler, type = "normal") {
|
|
|
307
305
|
}
|
|
308
306
|
__name(addDecoToClass, "addDecoToClass");
|
|
309
307
|
|
|
310
|
-
// src/preset/rule.ts
|
|
311
|
-
function isArray(info) {
|
|
312
|
-
return Rule((param) => Array.isArray(param), info || "it should be an array");
|
|
313
|
-
}
|
|
314
|
-
__name(isArray, "isArray");
|
|
315
|
-
function isBoolean(info) {
|
|
316
|
-
return Rule((param) => [
|
|
317
|
-
true,
|
|
318
|
-
false
|
|
319
|
-
].includes(param), info || "it should be true or false");
|
|
320
|
-
}
|
|
321
|
-
__name(isBoolean, "isBoolean");
|
|
322
|
-
function isNumber(info) {
|
|
323
|
-
return Rule((param) => typeof param === "number", info || "it should be true or false");
|
|
324
|
-
}
|
|
325
|
-
__name(isNumber, "isNumber");
|
|
326
|
-
function isString(info) {
|
|
327
|
-
return Rule((param) => typeof param === "string", info || "it should be a string");
|
|
328
|
-
}
|
|
329
|
-
__name(isString, "isString");
|
|
330
|
-
function isObject2(info) {
|
|
331
|
-
return Rule((param) => {
|
|
332
|
-
return Object.prototype.toString.call(param) === "[object Object]";
|
|
333
|
-
}, info || "it should be an object");
|
|
334
|
-
}
|
|
335
|
-
__name(isObject2, "isObject");
|
|
336
|
-
function isMobile(info) {
|
|
337
|
-
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || "it should be a mobile phone number");
|
|
338
|
-
}
|
|
339
|
-
__name(isMobile, "isMobile");
|
|
340
|
-
function isLandline(info) {
|
|
341
|
-
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || "it should be a mobile phone number");
|
|
342
|
-
}
|
|
343
|
-
__name(isLandline, "isLandline");
|
|
344
|
-
function isMailBox(info) {
|
|
345
|
-
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || "it should be a mailbox number");
|
|
346
|
-
}
|
|
347
|
-
__name(isMailBox, "isMailBox");
|
|
348
|
-
function isIdCard(info) {
|
|
349
|
-
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || "it should be an identity card number");
|
|
350
|
-
}
|
|
351
|
-
__name(isIdCard, "isIdCard");
|
|
352
|
-
function isCnName(info) {
|
|
353
|
-
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57");
|
|
354
|
-
}
|
|
355
|
-
__name(isCnName, "isCnName");
|
|
356
|
-
function isEnName(info) {
|
|
357
|
-
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || "it should be a valid en-name");
|
|
358
|
-
}
|
|
359
|
-
__name(isEnName, "isEnName");
|
|
360
|
-
function isDate(info) {
|
|
361
|
-
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || "it should be a valid date");
|
|
362
|
-
}
|
|
363
|
-
__name(isDate, "isDate");
|
|
364
|
-
function isWechat(info) {
|
|
365
|
-
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || "it should be a valid date");
|
|
366
|
-
}
|
|
367
|
-
__name(isWechat, "isWechat");
|
|
368
|
-
function isHexColor(info) {
|
|
369
|
-
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || "it should be a valid hex-color");
|
|
370
|
-
}
|
|
371
|
-
__name(isHexColor, "isHexColor");
|
|
372
|
-
function isPostalCode(info) {
|
|
373
|
-
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || "it should be a valid postal code");
|
|
374
|
-
}
|
|
375
|
-
__name(isPostalCode, "isPostalCode");
|
|
376
|
-
|
|
377
|
-
// src/preset/pipe.ts
|
|
378
|
-
function toNumber() {
|
|
379
|
-
return Pipe(to((param) => Number(param)));
|
|
380
|
-
}
|
|
381
|
-
__name(toNumber, "toNumber");
|
|
382
|
-
function toString() {
|
|
383
|
-
return Pipe(to((param) => String(param)));
|
|
384
|
-
}
|
|
385
|
-
__name(toString, "toString");
|
|
386
|
-
|
|
387
308
|
// src/namespace.ts
|
|
388
309
|
var activeInstance = {};
|
|
389
310
|
function injectProperty(key, value) {
|
|
@@ -418,7 +339,7 @@ function Storage(storeKey) {
|
|
|
418
339
|
let tag;
|
|
419
340
|
if (key) {
|
|
420
341
|
init(target);
|
|
421
|
-
tag = storeKey || target.
|
|
342
|
+
tag = storeKey || target.__TAG__;
|
|
422
343
|
const uniTag = Symbol(tag);
|
|
423
344
|
setModalVar(target, uniTag);
|
|
424
345
|
regisHandler(target, uniTag, {
|
|
@@ -432,7 +353,7 @@ function Storage(storeKey) {
|
|
|
432
353
|
});
|
|
433
354
|
} else {
|
|
434
355
|
init(target.prototype);
|
|
435
|
-
tag = storeKey || `${target.prototype.
|
|
356
|
+
tag = storeKey || `${target.prototype.__TAG__}_${key}`;
|
|
436
357
|
const uniTag = Symbol(tag);
|
|
437
358
|
setModalVar(target.prototype, uniTag);
|
|
438
359
|
regisHandler(target.prototype, uniTag, {
|
|
@@ -473,22 +394,7 @@ export {
|
|
|
473
394
|
getTag,
|
|
474
395
|
init,
|
|
475
396
|
injectProperty,
|
|
476
|
-
isArray,
|
|
477
|
-
isBoolean,
|
|
478
|
-
isCnName,
|
|
479
|
-
isDate,
|
|
480
|
-
isEnName,
|
|
481
|
-
isHexColor,
|
|
482
|
-
isIdCard,
|
|
483
|
-
isLandline,
|
|
484
|
-
isMailBox,
|
|
485
|
-
isMobile,
|
|
486
|
-
isNumber,
|
|
487
|
-
isObject2 as isObject,
|
|
488
397
|
isPhecda,
|
|
489
|
-
isPostalCode,
|
|
490
|
-
isString,
|
|
491
|
-
isWechat,
|
|
492
398
|
mergeOptions,
|
|
493
399
|
mergeState,
|
|
494
400
|
plainToClass,
|
|
@@ -501,7 +407,5 @@ export {
|
|
|
501
407
|
setModalVar,
|
|
502
408
|
snapShot,
|
|
503
409
|
to,
|
|
504
|
-
toNumber,
|
|
505
|
-
toString,
|
|
506
410
|
validate
|
|
507
411
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
|
|
2
|
+
declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
|
|
3
|
+
declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
|
|
4
|
+
declare function isString(info?: string): (obj: any, key: PropertyKey) => void;
|
|
5
|
+
declare function isObject(info?: string): (obj: any, key: PropertyKey) => void;
|
|
6
|
+
declare function isMobile(info?: string): (obj: any, key: PropertyKey) => void;
|
|
7
|
+
declare function isLandline(info?: string): (obj: any, key: PropertyKey) => void;
|
|
8
|
+
declare function isMailBox(info?: string): (obj: any, key: PropertyKey) => void;
|
|
9
|
+
declare function isIdCard(info?: string): (obj: any, key: PropertyKey) => void;
|
|
10
|
+
declare function isCnName(info?: string): (obj: any, key: PropertyKey) => void;
|
|
11
|
+
declare function isEnName(info?: string): (obj: any, key: PropertyKey) => void;
|
|
12
|
+
declare function isDate(info?: string): (obj: any, key: PropertyKey) => void;
|
|
13
|
+
declare function isWechat(info?: string): (obj: any, key: PropertyKey) => void;
|
|
14
|
+
declare function isHexColor(info?: string): (obj: any, key: PropertyKey) => void;
|
|
15
|
+
declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => void;
|
|
16
|
+
|
|
17
|
+
declare function toNumber(): (obj: any, key: PropertyKey) => void;
|
|
18
|
+
declare function toString(): (obj: any, key: PropertyKey) => void;
|
|
19
|
+
|
|
20
|
+
export { isArray, isBoolean, isCnName, isDate, isEnName, isHexColor, isIdCard, isLandline, isMailBox, isMobile, isNumber, isObject, isPostalCode, isString, isWechat, toNumber, toString };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var Phecda = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to2, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to2, key) && key !== except)
|
|
16
|
+
__defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to2;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/preset/index.ts
|
|
23
|
+
var preset_exports = {};
|
|
24
|
+
__export(preset_exports, {
|
|
25
|
+
isArray: () => isArray,
|
|
26
|
+
isBoolean: () => isBoolean,
|
|
27
|
+
isCnName: () => isCnName,
|
|
28
|
+
isDate: () => isDate,
|
|
29
|
+
isEnName: () => isEnName,
|
|
30
|
+
isHexColor: () => isHexColor,
|
|
31
|
+
isIdCard: () => isIdCard,
|
|
32
|
+
isLandline: () => isLandline,
|
|
33
|
+
isMailBox: () => isMailBox,
|
|
34
|
+
isMobile: () => isMobile,
|
|
35
|
+
isNumber: () => isNumber,
|
|
36
|
+
isObject: () => isObject,
|
|
37
|
+
isPostalCode: () => isPostalCode,
|
|
38
|
+
isString: () => isString,
|
|
39
|
+
isWechat: () => isWechat,
|
|
40
|
+
toNumber: () => toNumber,
|
|
41
|
+
toString: () => toString
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// src/core.ts
|
|
45
|
+
function init(target) {
|
|
46
|
+
if (!target._namespace) {
|
|
47
|
+
target._namespace = {
|
|
48
|
+
__INIT_EVENT__: /* @__PURE__ */ new Set(),
|
|
49
|
+
__EXPOSE_VAR__: /* @__PURE__ */ new Set(),
|
|
50
|
+
__IGNORE_VAR__: /* @__PURE__ */ new Set(),
|
|
51
|
+
__STATE_VAR__: /* @__PURE__ */ new Set(),
|
|
52
|
+
__STATE_HANDLER__: /* @__PURE__ */ new Map(),
|
|
53
|
+
__STATE_NAMESPACE__: /* @__PURE__ */ new Map()
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__name(init, "init");
|
|
58
|
+
function setModalVar(target, key) {
|
|
59
|
+
init(target);
|
|
60
|
+
target._namespace.__STATE_VAR__.add(key);
|
|
61
|
+
setExposeKey(target, key);
|
|
62
|
+
}
|
|
63
|
+
__name(setModalVar, "setModalVar");
|
|
64
|
+
function setExposeKey(target, key) {
|
|
65
|
+
init(target);
|
|
66
|
+
target._namespace.__EXPOSE_VAR__.add(key);
|
|
67
|
+
}
|
|
68
|
+
__name(setExposeKey, "setExposeKey");
|
|
69
|
+
function regisHandler(target, key, handler) {
|
|
70
|
+
init(target);
|
|
71
|
+
if (!target._namespace.__STATE_HANDLER__.has(key))
|
|
72
|
+
target._namespace.__STATE_HANDLER__.set(key, [
|
|
73
|
+
handler
|
|
74
|
+
]);
|
|
75
|
+
else
|
|
76
|
+
target._namespace.__STATE_HANDLER__.get(key).push(handler);
|
|
77
|
+
}
|
|
78
|
+
__name(regisHandler, "regisHandler");
|
|
79
|
+
|
|
80
|
+
// src/decorators.ts
|
|
81
|
+
function Rule(rule, info, meta) {
|
|
82
|
+
return (obj, key) => {
|
|
83
|
+
setModalVar(obj, key);
|
|
84
|
+
regisHandler(obj, key, {
|
|
85
|
+
rule,
|
|
86
|
+
info,
|
|
87
|
+
meta
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
__name(Rule, "Rule");
|
|
92
|
+
function Pipe(v) {
|
|
93
|
+
return (obj, key) => {
|
|
94
|
+
setModalVar(obj, key);
|
|
95
|
+
regisHandler(obj, key, {
|
|
96
|
+
async pipe(instance) {
|
|
97
|
+
const tasks = v.value;
|
|
98
|
+
for (const task of tasks)
|
|
99
|
+
instance[key] = await task(instance[key]);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
__name(Pipe, "Pipe");
|
|
105
|
+
|
|
106
|
+
// src/preset/rule.ts
|
|
107
|
+
function isArray(info) {
|
|
108
|
+
return Rule((param) => Array.isArray(param), info || "it should be an array");
|
|
109
|
+
}
|
|
110
|
+
__name(isArray, "isArray");
|
|
111
|
+
function isBoolean(info) {
|
|
112
|
+
return Rule((param) => [
|
|
113
|
+
true,
|
|
114
|
+
false
|
|
115
|
+
].includes(param), info || "it should be true or false");
|
|
116
|
+
}
|
|
117
|
+
__name(isBoolean, "isBoolean");
|
|
118
|
+
function isNumber(info) {
|
|
119
|
+
return Rule((param) => typeof param === "number", info || "it should be true or false");
|
|
120
|
+
}
|
|
121
|
+
__name(isNumber, "isNumber");
|
|
122
|
+
function isString(info) {
|
|
123
|
+
return Rule((param) => typeof param === "string", info || "it should be a string");
|
|
124
|
+
}
|
|
125
|
+
__name(isString, "isString");
|
|
126
|
+
function isObject(info) {
|
|
127
|
+
return Rule((param) => {
|
|
128
|
+
return Object.prototype.toString.call(param) === "[object Object]";
|
|
129
|
+
}, info || "it should be an object");
|
|
130
|
+
}
|
|
131
|
+
__name(isObject, "isObject");
|
|
132
|
+
function isMobile(info) {
|
|
133
|
+
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || "it should be a mobile phone number");
|
|
134
|
+
}
|
|
135
|
+
__name(isMobile, "isMobile");
|
|
136
|
+
function isLandline(info) {
|
|
137
|
+
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || "it should be a mobile phone number");
|
|
138
|
+
}
|
|
139
|
+
__name(isLandline, "isLandline");
|
|
140
|
+
function isMailBox(info) {
|
|
141
|
+
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || "it should be a mailbox number");
|
|
142
|
+
}
|
|
143
|
+
__name(isMailBox, "isMailBox");
|
|
144
|
+
function isIdCard(info) {
|
|
145
|
+
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || "it should be an identity card number");
|
|
146
|
+
}
|
|
147
|
+
__name(isIdCard, "isIdCard");
|
|
148
|
+
function isCnName(info) {
|
|
149
|
+
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57");
|
|
150
|
+
}
|
|
151
|
+
__name(isCnName, "isCnName");
|
|
152
|
+
function isEnName(info) {
|
|
153
|
+
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || "it should be a valid en-name");
|
|
154
|
+
}
|
|
155
|
+
__name(isEnName, "isEnName");
|
|
156
|
+
function isDate(info) {
|
|
157
|
+
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || "it should be a valid date");
|
|
158
|
+
}
|
|
159
|
+
__name(isDate, "isDate");
|
|
160
|
+
function isWechat(info) {
|
|
161
|
+
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || "it should be a valid date");
|
|
162
|
+
}
|
|
163
|
+
__name(isWechat, "isWechat");
|
|
164
|
+
function isHexColor(info) {
|
|
165
|
+
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || "it should be a valid hex-color");
|
|
166
|
+
}
|
|
167
|
+
__name(isHexColor, "isHexColor");
|
|
168
|
+
function isPostalCode(info) {
|
|
169
|
+
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || "it should be a valid postal code");
|
|
170
|
+
}
|
|
171
|
+
__name(isPostalCode, "isPostalCode");
|
|
172
|
+
|
|
173
|
+
// src/helper.ts
|
|
174
|
+
function to(task, oldTasks) {
|
|
175
|
+
const tasks = oldTasks || [];
|
|
176
|
+
tasks.push(task);
|
|
177
|
+
return {
|
|
178
|
+
to: (task2) => to(task2, tasks),
|
|
179
|
+
value: tasks
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
__name(to, "to");
|
|
183
|
+
|
|
184
|
+
// src/preset/pipe.ts
|
|
185
|
+
function toNumber() {
|
|
186
|
+
return Pipe(to((param) => Number(param)));
|
|
187
|
+
}
|
|
188
|
+
__name(toNumber, "toNumber");
|
|
189
|
+
function toString() {
|
|
190
|
+
return Pipe(to((param) => String(param)));
|
|
191
|
+
}
|
|
192
|
+
__name(toString, "toString");
|
|
193
|
+
return __toCommonJS(preset_exports);
|
|
194
|
+
})();
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to2, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to2, key) && key !== except)
|
|
15
|
+
__defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to2;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/preset/index.ts
|
|
22
|
+
var preset_exports = {};
|
|
23
|
+
__export(preset_exports, {
|
|
24
|
+
isArray: () => isArray,
|
|
25
|
+
isBoolean: () => isBoolean,
|
|
26
|
+
isCnName: () => isCnName,
|
|
27
|
+
isDate: () => isDate,
|
|
28
|
+
isEnName: () => isEnName,
|
|
29
|
+
isHexColor: () => isHexColor,
|
|
30
|
+
isIdCard: () => isIdCard,
|
|
31
|
+
isLandline: () => isLandline,
|
|
32
|
+
isMailBox: () => isMailBox,
|
|
33
|
+
isMobile: () => isMobile,
|
|
34
|
+
isNumber: () => isNumber,
|
|
35
|
+
isObject: () => isObject,
|
|
36
|
+
isPostalCode: () => isPostalCode,
|
|
37
|
+
isString: () => isString,
|
|
38
|
+
isWechat: () => isWechat,
|
|
39
|
+
toNumber: () => toNumber,
|
|
40
|
+
toString: () => toString
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(preset_exports);
|
|
43
|
+
|
|
44
|
+
// src/core.ts
|
|
45
|
+
function init(target) {
|
|
46
|
+
if (!target._namespace) {
|
|
47
|
+
target._namespace = {
|
|
48
|
+
__INIT_EVENT__: /* @__PURE__ */ new Set(),
|
|
49
|
+
__EXPOSE_VAR__: /* @__PURE__ */ new Set(),
|
|
50
|
+
__IGNORE_VAR__: /* @__PURE__ */ new Set(),
|
|
51
|
+
__STATE_VAR__: /* @__PURE__ */ new Set(),
|
|
52
|
+
__STATE_HANDLER__: /* @__PURE__ */ new Map(),
|
|
53
|
+
__STATE_NAMESPACE__: /* @__PURE__ */ new Map()
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__name(init, "init");
|
|
58
|
+
function setModalVar(target, key) {
|
|
59
|
+
init(target);
|
|
60
|
+
target._namespace.__STATE_VAR__.add(key);
|
|
61
|
+
setExposeKey(target, key);
|
|
62
|
+
}
|
|
63
|
+
__name(setModalVar, "setModalVar");
|
|
64
|
+
function setExposeKey(target, key) {
|
|
65
|
+
init(target);
|
|
66
|
+
target._namespace.__EXPOSE_VAR__.add(key);
|
|
67
|
+
}
|
|
68
|
+
__name(setExposeKey, "setExposeKey");
|
|
69
|
+
function regisHandler(target, key, handler) {
|
|
70
|
+
init(target);
|
|
71
|
+
if (!target._namespace.__STATE_HANDLER__.has(key))
|
|
72
|
+
target._namespace.__STATE_HANDLER__.set(key, [
|
|
73
|
+
handler
|
|
74
|
+
]);
|
|
75
|
+
else
|
|
76
|
+
target._namespace.__STATE_HANDLER__.get(key).push(handler);
|
|
77
|
+
}
|
|
78
|
+
__name(regisHandler, "regisHandler");
|
|
79
|
+
|
|
80
|
+
// src/decorators.ts
|
|
81
|
+
function Rule(rule, info, meta) {
|
|
82
|
+
return (obj, key) => {
|
|
83
|
+
setModalVar(obj, key);
|
|
84
|
+
regisHandler(obj, key, {
|
|
85
|
+
rule,
|
|
86
|
+
info,
|
|
87
|
+
meta
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
__name(Rule, "Rule");
|
|
92
|
+
function Pipe(v) {
|
|
93
|
+
return (obj, key) => {
|
|
94
|
+
setModalVar(obj, key);
|
|
95
|
+
regisHandler(obj, key, {
|
|
96
|
+
async pipe(instance) {
|
|
97
|
+
const tasks = v.value;
|
|
98
|
+
for (const task of tasks)
|
|
99
|
+
instance[key] = await task(instance[key]);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
__name(Pipe, "Pipe");
|
|
105
|
+
|
|
106
|
+
// src/preset/rule.ts
|
|
107
|
+
function isArray(info) {
|
|
108
|
+
return Rule((param) => Array.isArray(param), info || "it should be an array");
|
|
109
|
+
}
|
|
110
|
+
__name(isArray, "isArray");
|
|
111
|
+
function isBoolean(info) {
|
|
112
|
+
return Rule((param) => [
|
|
113
|
+
true,
|
|
114
|
+
false
|
|
115
|
+
].includes(param), info || "it should be true or false");
|
|
116
|
+
}
|
|
117
|
+
__name(isBoolean, "isBoolean");
|
|
118
|
+
function isNumber(info) {
|
|
119
|
+
return Rule((param) => typeof param === "number", info || "it should be true or false");
|
|
120
|
+
}
|
|
121
|
+
__name(isNumber, "isNumber");
|
|
122
|
+
function isString(info) {
|
|
123
|
+
return Rule((param) => typeof param === "string", info || "it should be a string");
|
|
124
|
+
}
|
|
125
|
+
__name(isString, "isString");
|
|
126
|
+
function isObject(info) {
|
|
127
|
+
return Rule((param) => {
|
|
128
|
+
return Object.prototype.toString.call(param) === "[object Object]";
|
|
129
|
+
}, info || "it should be an object");
|
|
130
|
+
}
|
|
131
|
+
__name(isObject, "isObject");
|
|
132
|
+
function isMobile(info) {
|
|
133
|
+
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || "it should be a mobile phone number");
|
|
134
|
+
}
|
|
135
|
+
__name(isMobile, "isMobile");
|
|
136
|
+
function isLandline(info) {
|
|
137
|
+
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || "it should be a mobile phone number");
|
|
138
|
+
}
|
|
139
|
+
__name(isLandline, "isLandline");
|
|
140
|
+
function isMailBox(info) {
|
|
141
|
+
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || "it should be a mailbox number");
|
|
142
|
+
}
|
|
143
|
+
__name(isMailBox, "isMailBox");
|
|
144
|
+
function isIdCard(info) {
|
|
145
|
+
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || "it should be an identity card number");
|
|
146
|
+
}
|
|
147
|
+
__name(isIdCard, "isIdCard");
|
|
148
|
+
function isCnName(info) {
|
|
149
|
+
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57");
|
|
150
|
+
}
|
|
151
|
+
__name(isCnName, "isCnName");
|
|
152
|
+
function isEnName(info) {
|
|
153
|
+
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || "it should be a valid en-name");
|
|
154
|
+
}
|
|
155
|
+
__name(isEnName, "isEnName");
|
|
156
|
+
function isDate(info) {
|
|
157
|
+
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || "it should be a valid date");
|
|
158
|
+
}
|
|
159
|
+
__name(isDate, "isDate");
|
|
160
|
+
function isWechat(info) {
|
|
161
|
+
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || "it should be a valid date");
|
|
162
|
+
}
|
|
163
|
+
__name(isWechat, "isWechat");
|
|
164
|
+
function isHexColor(info) {
|
|
165
|
+
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || "it should be a valid hex-color");
|
|
166
|
+
}
|
|
167
|
+
__name(isHexColor, "isHexColor");
|
|
168
|
+
function isPostalCode(info) {
|
|
169
|
+
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || "it should be a valid postal code");
|
|
170
|
+
}
|
|
171
|
+
__name(isPostalCode, "isPostalCode");
|
|
172
|
+
|
|
173
|
+
// src/helper.ts
|
|
174
|
+
function to(task, oldTasks) {
|
|
175
|
+
const tasks = oldTasks || [];
|
|
176
|
+
tasks.push(task);
|
|
177
|
+
return {
|
|
178
|
+
to: (task2) => to(task2, tasks),
|
|
179
|
+
value: tasks
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
__name(to, "to");
|
|
183
|
+
|
|
184
|
+
// src/preset/pipe.ts
|
|
185
|
+
function toNumber() {
|
|
186
|
+
return Pipe(to((param) => Number(param)));
|
|
187
|
+
}
|
|
188
|
+
__name(toNumber, "toNumber");
|
|
189
|
+
function toString() {
|
|
190
|
+
return Pipe(to((param) => String(param)));
|
|
191
|
+
}
|
|
192
|
+
__name(toString, "toString");
|
|
193
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
194
|
+
0 && (module.exports = {
|
|
195
|
+
isArray,
|
|
196
|
+
isBoolean,
|
|
197
|
+
isCnName,
|
|
198
|
+
isDate,
|
|
199
|
+
isEnName,
|
|
200
|
+
isHexColor,
|
|
201
|
+
isIdCard,
|
|
202
|
+
isLandline,
|
|
203
|
+
isMailBox,
|
|
204
|
+
isMobile,
|
|
205
|
+
isNumber,
|
|
206
|
+
isObject,
|
|
207
|
+
isPostalCode,
|
|
208
|
+
isString,
|
|
209
|
+
isWechat,
|
|
210
|
+
toNumber,
|
|
211
|
+
toString
|
|
212
|
+
});
|