phecda-core 1.1.1 → 1.2.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.
@@ -0,0 +1,172 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/core.ts
5
+ function init(target) {
6
+ if (!target._namespace) {
7
+ target._namespace = {
8
+ __TAG__: "",
9
+ __INIT_EVENT__: /* @__PURE__ */ new Set(),
10
+ __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
11
+ __IGNORE_VAR__: /* @__PURE__ */ new Set(),
12
+ __STATE_VAR__: /* @__PURE__ */ new Set(),
13
+ __STATE_HANDLER__: /* @__PURE__ */ new Map(),
14
+ __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
15
+ };
16
+ }
17
+ }
18
+ __name(init, "init");
19
+ function setModalVar(target, key) {
20
+ init(target);
21
+ target._namespace.__STATE_VAR__.add(key);
22
+ setExposeKey(target, key);
23
+ }
24
+ __name(setModalVar, "setModalVar");
25
+ function setExposeKey(target, key) {
26
+ init(target);
27
+ target._namespace.__EXPOSE_VAR__.add(key);
28
+ }
29
+ __name(setExposeKey, "setExposeKey");
30
+ function regisHandler(target, key, handler) {
31
+ init(target);
32
+ if (!target._namespace.__STATE_HANDLER__.has(key))
33
+ target._namespace.__STATE_HANDLER__.set(key, [
34
+ handler
35
+ ]);
36
+ else
37
+ target._namespace.__STATE_HANDLER__.get(key).push(handler);
38
+ }
39
+ __name(regisHandler, "regisHandler");
40
+
41
+ // src/decorators.ts
42
+ function Rule(rule, info, meta) {
43
+ return (obj, key) => {
44
+ setModalVar(obj, key);
45
+ regisHandler(obj, key, {
46
+ rule,
47
+ info,
48
+ meta
49
+ });
50
+ };
51
+ }
52
+ __name(Rule, "Rule");
53
+ function Pipe(v) {
54
+ return (obj, key) => {
55
+ setModalVar(obj, key);
56
+ regisHandler(obj, key, {
57
+ async pipe(instance) {
58
+ const tasks = v.value;
59
+ for (const task of tasks)
60
+ instance[key] = await task(instance[key]);
61
+ }
62
+ });
63
+ };
64
+ }
65
+ __name(Pipe, "Pipe");
66
+
67
+ // src/preset/rule.ts
68
+ function isArray(info) {
69
+ return Rule((param) => Array.isArray(param), info || "it should be an array");
70
+ }
71
+ __name(isArray, "isArray");
72
+ function isBoolean(info) {
73
+ return Rule((param) => [
74
+ true,
75
+ false
76
+ ].includes(param), info || "it should be true or false");
77
+ }
78
+ __name(isBoolean, "isBoolean");
79
+ function isNumber(info) {
80
+ return Rule((param) => typeof param === "number", info || "it should be true or false");
81
+ }
82
+ __name(isNumber, "isNumber");
83
+ function isString(info) {
84
+ return Rule((param) => typeof param === "string", info || "it should be a string");
85
+ }
86
+ __name(isString, "isString");
87
+ function isObject(info) {
88
+ return Rule((param) => {
89
+ return Object.prototype.toString.call(param) === "[object Object]";
90
+ }, info || "it should be an object");
91
+ }
92
+ __name(isObject, "isObject");
93
+ function isMobile(info) {
94
+ 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");
95
+ }
96
+ __name(isMobile, "isMobile");
97
+ function isLandline(info) {
98
+ return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || "it should be a mobile phone number");
99
+ }
100
+ __name(isLandline, "isLandline");
101
+ function isMailBox(info) {
102
+ 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");
103
+ }
104
+ __name(isMailBox, "isMailBox");
105
+ function isIdCard(info) {
106
+ 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");
107
+ }
108
+ __name(isIdCard, "isIdCard");
109
+ function isCnName(info) {
110
+ return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57");
111
+ }
112
+ __name(isCnName, "isCnName");
113
+ function isEnName(info) {
114
+ return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || "it should be a valid en-name");
115
+ }
116
+ __name(isEnName, "isEnName");
117
+ function isDate(info) {
118
+ 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");
119
+ }
120
+ __name(isDate, "isDate");
121
+ function isWechat(info) {
122
+ return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || "it should be a valid date");
123
+ }
124
+ __name(isWechat, "isWechat");
125
+ function isHexColor(info) {
126
+ return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || "it should be a valid hex-color");
127
+ }
128
+ __name(isHexColor, "isHexColor");
129
+ function isPostalCode(info) {
130
+ 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");
131
+ }
132
+ __name(isPostalCode, "isPostalCode");
133
+
134
+ // src/helper.ts
135
+ function to(task, oldTasks) {
136
+ const tasks = oldTasks || [];
137
+ tasks.push(task);
138
+ return {
139
+ to: (task2) => to(task2, tasks),
140
+ value: tasks
141
+ };
142
+ }
143
+ __name(to, "to");
144
+
145
+ // src/preset/pipe.ts
146
+ function toNumber() {
147
+ return Pipe(to((param) => Number(param)));
148
+ }
149
+ __name(toNumber, "toNumber");
150
+ function toString() {
151
+ return Pipe(to((param) => String(param)));
152
+ }
153
+ __name(toString, "toString");
154
+ export {
155
+ isArray,
156
+ isBoolean,
157
+ isCnName,
158
+ isDate,
159
+ isEnName,
160
+ isHexColor,
161
+ isIdCard,
162
+ isLandline,
163
+ isMailBox,
164
+ isMobile,
165
+ isNumber,
166
+ isObject,
167
+ isPostalCode,
168
+ isString,
169
+ isWechat,
170
+ toNumber,
171
+ toString
172
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "1.1.1",
4
- "description": "",
3
+ "version": "1.2.1",
4
+ "description": "provide base function and abstract limit to other phecda module ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",