phecda-core 1.2.0 → 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.
package/dist/index.d.ts CHANGED
@@ -102,25 +102,6 @@ declare function getState(target: Phecda, key: PropertyKey): Object | undefined;
102
102
  declare function register(instance: Phecda): void;
103
103
  declare function registerAsync(instance: Phecda): Promise<void>;
104
104
 
105
- declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
106
- declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
107
- declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
108
- declare function isString(info?: string): (obj: any, key: PropertyKey) => void;
109
- declare function isObject(info?: string): (obj: any, key: PropertyKey) => void;
110
- declare function isMobile(info?: string): (obj: any, key: PropertyKey) => void;
111
- declare function isLandline(info?: string): (obj: any, key: PropertyKey) => void;
112
- declare function isMailBox(info?: string): (obj: any, key: PropertyKey) => void;
113
- declare function isIdCard(info?: string): (obj: any, key: PropertyKey) => void;
114
- declare function isCnName(info?: string): (obj: any, key: PropertyKey) => void;
115
- declare function isEnName(info?: string): (obj: any, key: PropertyKey) => void;
116
- declare function isDate(info?: string): (obj: any, key: PropertyKey) => void;
117
- declare function isWechat(info?: string): (obj: any, key: PropertyKey) => void;
118
- declare function isHexColor(info?: string): (obj: any, key: PropertyKey) => void;
119
- declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => void;
120
-
121
- declare function toNumber(): (obj: any, key: PropertyKey) => void;
122
- declare function toString(): (obj: any, key: PropertyKey) => void;
123
-
124
105
  declare const activeInstance: Record<string, any>;
125
106
  declare function injectProperty(key: string, value: any): Record<string, any>;
126
107
  declare function getProperty(key: string): any;
@@ -130,4 +111,4 @@ declare function Watcher(eventName: keyof PhecdaEvents, options?: {
130
111
  }): (obj: any, key: string) => void;
131
112
  declare function Storage(storeKey?: string): (target: any, key?: PropertyKey) => void;
132
113
 
133
- export { ClassValue, Clear, Err, Global, Ignore, Init, P, Phecda, PhecdaEvents, PhecdaHandler, PhecdaNameSpace, Pipe, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getExposeKey, getHandler, getIgnoreKey, getInitEvent, getModelState, getProperty, getState, getTag, init, injectProperty, isArray, isBoolean, isCnName, isDate, isEnName, isHexColor, isIdCard, isLandline, isMailBox, isMobile, isNumber, isObject, isPhecda, isPostalCode, isString, isWechat, mergeOptions, mergeState, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModalVar, snapShot, to, toNumber, toString, validate };
114
+ export { ClassValue, Clear, Err, Global, Ignore, Init, P, Phecda, PhecdaEvents, PhecdaHandler, PhecdaNameSpace, Pipe, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getExposeKey, getHandler, getIgnoreKey, getInitEvent, getModelState, getProperty, getState, getTag, init, injectProperty, isPhecda, mergeOptions, mergeState, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModalVar, snapShot, to, validate };
@@ -0,0 +1,436 @@
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/index.ts
23
+ var src_exports = {};
24
+ __export(src_exports, {
25
+ Clear: () => Clear,
26
+ Err: () => Err,
27
+ Global: () => Global,
28
+ Ignore: () => Ignore,
29
+ Init: () => Init,
30
+ P: () => P,
31
+ Pipe: () => Pipe,
32
+ Rule: () => Rule,
33
+ Storage: () => Storage,
34
+ Tag: () => Tag,
35
+ Watcher: () => Watcher,
36
+ activeInstance: () => activeInstance,
37
+ addDecoToClass: () => addDecoToClass,
38
+ classToValue: () => classToValue,
39
+ getExposeKey: () => getExposeKey,
40
+ getHandler: () => getHandler,
41
+ getIgnoreKey: () => getIgnoreKey,
42
+ getInitEvent: () => getInitEvent,
43
+ getModelState: () => getModelState,
44
+ getProperty: () => getProperty,
45
+ getState: () => getState,
46
+ getTag: () => getTag,
47
+ init: () => init,
48
+ injectProperty: () => injectProperty,
49
+ isPhecda: () => isPhecda,
50
+ mergeOptions: () => mergeOptions,
51
+ mergeState: () => mergeState,
52
+ plainToClass: () => plainToClass,
53
+ regisHandler: () => regisHandler,
54
+ regisInitEvent: () => regisInitEvent,
55
+ register: () => register,
56
+ registerAsync: () => registerAsync,
57
+ setExposeKey: () => setExposeKey,
58
+ setIgnoreKey: () => setIgnoreKey,
59
+ setModalVar: () => setModalVar,
60
+ snapShot: () => snapShot,
61
+ to: () => to,
62
+ validate: () => validate
63
+ });
64
+
65
+ // src/utils.ts
66
+ async function validate(p, v) {
67
+ if (typeof p === "string" || typeof p === "number") {
68
+ if (v === p)
69
+ return true;
70
+ }
71
+ if (typeof p === "function")
72
+ return p(v);
73
+ if (p instanceof RegExp)
74
+ return p.test(v);
75
+ return false;
76
+ }
77
+ __name(validate, "validate");
78
+ function getTag(Model) {
79
+ return Model.prototype?._namespace?.__TAG__;
80
+ }
81
+ __name(getTag, "getTag");
82
+ function mergeOptions(obj1, obj2) {
83
+ if (!obj2)
84
+ return obj1;
85
+ for (const i in obj2) {
86
+ if (isObject(obj1[i]) && isObject(obj2[i])) {
87
+ mergeOptions(obj1[i], obj2[i]);
88
+ continue;
89
+ }
90
+ if (Array.isArray(obj1[i]) && Array.isArray(obj2[i])) {
91
+ obj1[i].push(...obj2[i].filter((item) => !obj1[i].includes(item)));
92
+ continue;
93
+ }
94
+ obj1[i] = obj2[i];
95
+ }
96
+ return obj1;
97
+ }
98
+ __name(mergeOptions, "mergeOptions");
99
+ function isObject(obj) {
100
+ return Object.prototype.toString.call(obj) === "[object Object]";
101
+ }
102
+ __name(isObject, "isObject");
103
+
104
+ // src/core.ts
105
+ function isPhecda(target) {
106
+ return target && !!target.prototype._namespace;
107
+ }
108
+ __name(isPhecda, "isPhecda");
109
+ function init(target) {
110
+ if (!target._namespace) {
111
+ target._namespace = {
112
+ __TAG__: "",
113
+ __INIT_EVENT__: /* @__PURE__ */ new Set(),
114
+ __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
115
+ __IGNORE_VAR__: /* @__PURE__ */ new Set(),
116
+ __STATE_VAR__: /* @__PURE__ */ new Set(),
117
+ __STATE_HANDLER__: /* @__PURE__ */ new Map(),
118
+ __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
119
+ };
120
+ }
121
+ }
122
+ __name(init, "init");
123
+ function regisInitEvent(target, key) {
124
+ init(target);
125
+ target._namespace.__INIT_EVENT__.add(key);
126
+ }
127
+ __name(regisInitEvent, "regisInitEvent");
128
+ function getInitEvent(target) {
129
+ init(target);
130
+ return [
131
+ ...target._namespace.__INIT_EVENT__
132
+ ];
133
+ }
134
+ __name(getInitEvent, "getInitEvent");
135
+ function setModalVar(target, key) {
136
+ init(target);
137
+ target._namespace.__STATE_VAR__.add(key);
138
+ setExposeKey(target, key);
139
+ }
140
+ __name(setModalVar, "setModalVar");
141
+ function setExposeKey(target, key) {
142
+ init(target);
143
+ target._namespace.__EXPOSE_VAR__.add(key);
144
+ }
145
+ __name(setExposeKey, "setExposeKey");
146
+ function setIgnoreKey(target, key) {
147
+ init(target);
148
+ target._namespace.__IGNORE_VAR__.add(key);
149
+ }
150
+ __name(setIgnoreKey, "setIgnoreKey");
151
+ function getModelState(target) {
152
+ init(target);
153
+ return [
154
+ ...target._namespace.__STATE_VAR__
155
+ ];
156
+ }
157
+ __name(getModelState, "getModelState");
158
+ function getExposeKey(target) {
159
+ init(target);
160
+ return [
161
+ ...target._namespace.__EXPOSE_VAR__
162
+ ].filter((item) => !target._namespace.__IGNORE_VAR__.has(item));
163
+ }
164
+ __name(getExposeKey, "getExposeKey");
165
+ function getIgnoreKey(target) {
166
+ init(target);
167
+ return [
168
+ ...target._namespace.__IGNORE_VAR__
169
+ ];
170
+ }
171
+ __name(getIgnoreKey, "getIgnoreKey");
172
+ function regisHandler(target, key, handler) {
173
+ init(target);
174
+ if (!target._namespace.__STATE_HANDLER__.has(key))
175
+ target._namespace.__STATE_HANDLER__.set(key, [
176
+ handler
177
+ ]);
178
+ else
179
+ target._namespace.__STATE_HANDLER__.get(key).push(handler);
180
+ }
181
+ __name(regisHandler, "regisHandler");
182
+ function getHandler(target, key) {
183
+ return target._namespace.__STATE_HANDLER__.get(key) || [];
184
+ }
185
+ __name(getHandler, "getHandler");
186
+ function mergeState(target, key, state) {
187
+ const namespace = target._namespace.__STATE_NAMESPACE__;
188
+ if (!namespace.has(key))
189
+ namespace.set(key, state);
190
+ else
191
+ mergeOptions(namespace.get(key), state);
192
+ }
193
+ __name(mergeState, "mergeState");
194
+ function getState(target, key) {
195
+ const namespace = target._namespace.__STATE_NAMESPACE__;
196
+ if (namespace)
197
+ return namespace.get(key);
198
+ }
199
+ __name(getState, "getState");
200
+ function register(instance) {
201
+ const stateVars = getExposeKey(instance);
202
+ for (const item of stateVars) {
203
+ const handlers = getHandler(instance, item);
204
+ for (const hanlder of handlers)
205
+ hanlder.init?.(instance);
206
+ }
207
+ }
208
+ __name(register, "register");
209
+ async function registerAsync(instance) {
210
+ const stateVars = getExposeKey(instance);
211
+ for (const item of stateVars) {
212
+ const handlers = getHandler(instance, item);
213
+ for (const hanlder of handlers)
214
+ await hanlder.init?.(instance);
215
+ }
216
+ }
217
+ __name(registerAsync, "registerAsync");
218
+
219
+ // src/decorators.ts
220
+ function Init(target, key) {
221
+ setModalVar(target, key);
222
+ regisHandler(target, key, {
223
+ async init(instance) {
224
+ instance[key]();
225
+ }
226
+ });
227
+ }
228
+ __name(Init, "Init");
229
+ function Rule(rule, info, meta) {
230
+ return (obj, key) => {
231
+ setModalVar(obj, key);
232
+ regisHandler(obj, key, {
233
+ rule,
234
+ info,
235
+ meta
236
+ });
237
+ };
238
+ }
239
+ __name(Rule, "Rule");
240
+ function Ignore(target, key) {
241
+ setIgnoreKey(target, key);
242
+ }
243
+ __name(Ignore, "Ignore");
244
+ function Clear(target, key) {
245
+ init(target);
246
+ target._namespace.__INIT_EVENT__.delete(key);
247
+ target._namespace.__EXPOSE_VAR__.delete(key);
248
+ target._namespace.__IGNORE_VAR__.delete(key);
249
+ target._namespace.__STATE_VAR__.delete(key);
250
+ target._namespace.__STATE_HANDLER__.delete(key);
251
+ target._namespace.__STATE_NAMESPACE__.delete(key);
252
+ }
253
+ __name(Clear, "Clear");
254
+ function Err(cb) {
255
+ return (target, key) => {
256
+ setModalVar(target, key);
257
+ regisHandler(target, key, {
258
+ error: cb
259
+ });
260
+ };
261
+ }
262
+ __name(Err, "Err");
263
+ function P(target, key) {
264
+ setExposeKey(target, key);
265
+ }
266
+ __name(P, "P");
267
+ function Pipe(v) {
268
+ return (obj, key) => {
269
+ setModalVar(obj, key);
270
+ regisHandler(obj, key, {
271
+ async pipe(instance) {
272
+ const tasks = v.value;
273
+ for (const task of tasks)
274
+ instance[key] = await task(instance[key]);
275
+ }
276
+ });
277
+ };
278
+ }
279
+ __name(Pipe, "Pipe");
280
+ function Tag(tag) {
281
+ return (target) => {
282
+ init(target.prototype);
283
+ target.prototype._namespace.__TAG__ = tag;
284
+ };
285
+ }
286
+ __name(Tag, "Tag");
287
+ function Global(target) {
288
+ if (!globalThis.__PHECDA__)
289
+ globalThis.__PHECDA__ = {};
290
+ const tag = target.prototype._namespace.__TAG__;
291
+ if (tag)
292
+ globalThis.__PHECDA__[tag] = target;
293
+ }
294
+ __name(Global, "Global");
295
+
296
+ // src/helper.ts
297
+ async function plainToClass(Model, input, options = {}) {
298
+ const data = new Model();
299
+ const err = [];
300
+ const stateVars = getModelState(data);
301
+ for (const item of stateVars) {
302
+ data[item] = input[item];
303
+ const handlers = getHandler(data, item);
304
+ if (handlers) {
305
+ if (options.collectError !== false) {
306
+ for (const handler of handlers) {
307
+ const rule = handler.rule;
308
+ if (rule && !await validate(rule, data[item])) {
309
+ err.push(handler.info || "");
310
+ if (!options.collectError)
311
+ break;
312
+ }
313
+ }
314
+ }
315
+ if (err.length > 0 && !options.transform)
316
+ return {
317
+ err,
318
+ data
319
+ };
320
+ if (options.transform !== false) {
321
+ for (const handler of handlers)
322
+ await handler.pipe?.(data);
323
+ }
324
+ }
325
+ }
326
+ return {
327
+ data,
328
+ err
329
+ };
330
+ }
331
+ __name(plainToClass, "plainToClass");
332
+ function classToValue(instance) {
333
+ const data = {};
334
+ const exposeVar = getExposeKey(instance);
335
+ for (const item of exposeVar)
336
+ data[item] = instance[item];
337
+ return data;
338
+ }
339
+ __name(classToValue, "classToValue");
340
+ function to(task, oldTasks) {
341
+ const tasks = oldTasks || [];
342
+ tasks.push(task);
343
+ return {
344
+ to: (task2) => to(task2, tasks),
345
+ value: tasks
346
+ };
347
+ }
348
+ __name(to, "to");
349
+ function snapShot(data) {
350
+ const snap = {};
351
+ for (const i in data)
352
+ snap[i] = data[i];
353
+ return {
354
+ data,
355
+ clear() {
356
+ for (const i in snap)
357
+ delete data[i];
358
+ },
359
+ apply() {
360
+ for (const i in snap)
361
+ data[i] = snap[i];
362
+ }
363
+ };
364
+ }
365
+ __name(snapShot, "snapShot");
366
+ function addDecoToClass(c, key, handler, type = "normal") {
367
+ handler(type === "normal" ? c.prototype : c, key);
368
+ }
369
+ __name(addDecoToClass, "addDecoToClass");
370
+
371
+ // src/namespace.ts
372
+ var activeInstance = {};
373
+ function injectProperty(key, value) {
374
+ activeInstance[key] = value;
375
+ return activeInstance;
376
+ }
377
+ __name(injectProperty, "injectProperty");
378
+ function getProperty(key) {
379
+ return activeInstance[key];
380
+ }
381
+ __name(getProperty, "getProperty");
382
+
383
+ // src/custom/decorator.ts
384
+ function Watcher(eventName, options) {
385
+ return (obj, key) => {
386
+ setModalVar(obj, key);
387
+ regisHandler(obj, key, {
388
+ init(instance) {
389
+ getProperty("watcher")?.({
390
+ eventName,
391
+ instance,
392
+ key,
393
+ options
394
+ });
395
+ }
396
+ });
397
+ };
398
+ }
399
+ __name(Watcher, "Watcher");
400
+ function Storage(storeKey) {
401
+ return (target, key) => {
402
+ let tag;
403
+ if (key) {
404
+ init(target);
405
+ tag = storeKey || target._namespace.__TAG__;
406
+ const uniTag = Symbol(tag);
407
+ setModalVar(target, uniTag);
408
+ regisHandler(target, uniTag, {
409
+ init: (instance) => {
410
+ getProperty("storage")?.({
411
+ instance,
412
+ key,
413
+ tag
414
+ });
415
+ }
416
+ });
417
+ } else {
418
+ init(target.prototype);
419
+ tag = storeKey || `${target.prototype._namespace.__TAG__}_${key}`;
420
+ const uniTag = Symbol(tag);
421
+ setModalVar(target.prototype, uniTag);
422
+ regisHandler(target.prototype, uniTag, {
423
+ init: (instance) => {
424
+ getProperty("storage")?.({
425
+ instance,
426
+ key: "",
427
+ tag
428
+ });
429
+ }
430
+ });
431
+ }
432
+ };
433
+ }
434
+ __name(Storage, "Storage");
435
+ return __toCommonJS(src_exports);
436
+ })();
package/dist/index.js CHANGED
@@ -45,22 +45,7 @@ __export(src_exports, {
45
45
  getTag: () => getTag,
46
46
  init: () => init,
47
47
  injectProperty: () => injectProperty,
48
- isArray: () => isArray,
49
- isBoolean: () => isBoolean,
50
- isCnName: () => isCnName,
51
- isDate: () => isDate,
52
- isEnName: () => isEnName,
53
- isHexColor: () => isHexColor,
54
- isIdCard: () => isIdCard,
55
- isLandline: () => isLandline,
56
- isMailBox: () => isMailBox,
57
- isMobile: () => isMobile,
58
- isNumber: () => isNumber,
59
- isObject: () => isObject2,
60
48
  isPhecda: () => isPhecda,
61
- isPostalCode: () => isPostalCode,
62
- isString: () => isString,
63
- isWechat: () => isWechat,
64
49
  mergeOptions: () => mergeOptions,
65
50
  mergeState: () => mergeState,
66
51
  plainToClass: () => plainToClass,
@@ -73,8 +58,6 @@ __export(src_exports, {
73
58
  setModalVar: () => setModalVar,
74
59
  snapShot: () => snapShot,
75
60
  to: () => to,
76
- toNumber: () => toNumber,
77
- toString: () => toString,
78
61
  validate: () => validate
79
62
  });
80
63
  module.exports = __toCommonJS(src_exports);
@@ -385,83 +368,6 @@ function addDecoToClass(c, key, handler, type = "normal") {
385
368
  }
386
369
  __name(addDecoToClass, "addDecoToClass");
387
370
 
388
- // src/preset/rule.ts
389
- function isArray(info) {
390
- return Rule((param) => Array.isArray(param), info || "it should be an array");
391
- }
392
- __name(isArray, "isArray");
393
- function isBoolean(info) {
394
- return Rule((param) => [
395
- true,
396
- false
397
- ].includes(param), info || "it should be true or false");
398
- }
399
- __name(isBoolean, "isBoolean");
400
- function isNumber(info) {
401
- return Rule((param) => typeof param === "number", info || "it should be true or false");
402
- }
403
- __name(isNumber, "isNumber");
404
- function isString(info) {
405
- return Rule((param) => typeof param === "string", info || "it should be a string");
406
- }
407
- __name(isString, "isString");
408
- function isObject2(info) {
409
- return Rule((param) => {
410
- return Object.prototype.toString.call(param) === "[object Object]";
411
- }, info || "it should be an object");
412
- }
413
- __name(isObject2, "isObject");
414
- function isMobile(info) {
415
- 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");
416
- }
417
- __name(isMobile, "isMobile");
418
- function isLandline(info) {
419
- return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || "it should be a mobile phone number");
420
- }
421
- __name(isLandline, "isLandline");
422
- function isMailBox(info) {
423
- 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");
424
- }
425
- __name(isMailBox, "isMailBox");
426
- function isIdCard(info) {
427
- 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");
428
- }
429
- __name(isIdCard, "isIdCard");
430
- function isCnName(info) {
431
- return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57");
432
- }
433
- __name(isCnName, "isCnName");
434
- function isEnName(info) {
435
- return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || "it should be a valid en-name");
436
- }
437
- __name(isEnName, "isEnName");
438
- function isDate(info) {
439
- 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");
440
- }
441
- __name(isDate, "isDate");
442
- function isWechat(info) {
443
- return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || "it should be a valid date");
444
- }
445
- __name(isWechat, "isWechat");
446
- function isHexColor(info) {
447
- return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || "it should be a valid hex-color");
448
- }
449
- __name(isHexColor, "isHexColor");
450
- function isPostalCode(info) {
451
- 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");
452
- }
453
- __name(isPostalCode, "isPostalCode");
454
-
455
- // src/preset/pipe.ts
456
- function toNumber() {
457
- return Pipe(to((param) => Number(param)));
458
- }
459
- __name(toNumber, "toNumber");
460
- function toString() {
461
- return Pipe(to((param) => String(param)));
462
- }
463
- __name(toString, "toString");
464
-
465
371
  // src/namespace.ts
466
372
  var activeInstance = {};
467
373
  function injectProperty(key, value) {
@@ -552,22 +458,7 @@ __name(Storage, "Storage");
552
458
  getTag,
553
459
  init,
554
460
  injectProperty,
555
- isArray,
556
- isBoolean,
557
- isCnName,
558
- isDate,
559
- isEnName,
560
- isHexColor,
561
- isIdCard,
562
- isLandline,
563
- isMailBox,
564
- isMobile,
565
- isNumber,
566
- isObject,
567
461
  isPhecda,
568
- isPostalCode,
569
- isString,
570
- isWechat,
571
462
  mergeOptions,
572
463
  mergeState,
573
464
  plainToClass,
@@ -580,7 +471,5 @@ __name(Storage, "Storage");
580
471
  setModalVar,
581
472
  snapShot,
582
473
  to,
583
- toNumber,
584
- toString,
585
474
  validate
586
475
  });
package/dist/index.mjs CHANGED
@@ -307,83 +307,6 @@ function addDecoToClass(c, key, handler, type = "normal") {
307
307
  }
308
308
  __name(addDecoToClass, "addDecoToClass");
309
309
 
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
310
  // src/namespace.ts
388
311
  var activeInstance = {};
389
312
  function injectProperty(key, value) {
@@ -473,22 +396,7 @@ export {
473
396
  getTag,
474
397
  init,
475
398
  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
399
  isPhecda,
489
- isPostalCode,
490
- isString,
491
- isWechat,
492
400
  mergeOptions,
493
401
  mergeState,
494
402
  plainToClass,
@@ -501,7 +409,5 @@ export {
501
409
  setModalVar,
502
410
  snapShot,
503
411
  to,
504
- toNumber,
505
- toString,
506
412
  validate
507
413
  };
@@ -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,195 @@
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
+ __TAG__: "",
49
+ __INIT_EVENT__: /* @__PURE__ */ new Set(),
50
+ __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
51
+ __IGNORE_VAR__: /* @__PURE__ */ new Set(),
52
+ __STATE_VAR__: /* @__PURE__ */ new Set(),
53
+ __STATE_HANDLER__: /* @__PURE__ */ new Map(),
54
+ __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
55
+ };
56
+ }
57
+ }
58
+ __name(init, "init");
59
+ function setModalVar(target, key) {
60
+ init(target);
61
+ target._namespace.__STATE_VAR__.add(key);
62
+ setExposeKey(target, key);
63
+ }
64
+ __name(setModalVar, "setModalVar");
65
+ function setExposeKey(target, key) {
66
+ init(target);
67
+ target._namespace.__EXPOSE_VAR__.add(key);
68
+ }
69
+ __name(setExposeKey, "setExposeKey");
70
+ function regisHandler(target, key, handler) {
71
+ init(target);
72
+ if (!target._namespace.__STATE_HANDLER__.has(key))
73
+ target._namespace.__STATE_HANDLER__.set(key, [
74
+ handler
75
+ ]);
76
+ else
77
+ target._namespace.__STATE_HANDLER__.get(key).push(handler);
78
+ }
79
+ __name(regisHandler, "regisHandler");
80
+
81
+ // src/decorators.ts
82
+ function Rule(rule, info, meta) {
83
+ return (obj, key) => {
84
+ setModalVar(obj, key);
85
+ regisHandler(obj, key, {
86
+ rule,
87
+ info,
88
+ meta
89
+ });
90
+ };
91
+ }
92
+ __name(Rule, "Rule");
93
+ function Pipe(v) {
94
+ return (obj, key) => {
95
+ setModalVar(obj, key);
96
+ regisHandler(obj, key, {
97
+ async pipe(instance) {
98
+ const tasks = v.value;
99
+ for (const task of tasks)
100
+ instance[key] = await task(instance[key]);
101
+ }
102
+ });
103
+ };
104
+ }
105
+ __name(Pipe, "Pipe");
106
+
107
+ // src/preset/rule.ts
108
+ function isArray(info) {
109
+ return Rule((param) => Array.isArray(param), info || "it should be an array");
110
+ }
111
+ __name(isArray, "isArray");
112
+ function isBoolean(info) {
113
+ return Rule((param) => [
114
+ true,
115
+ false
116
+ ].includes(param), info || "it should be true or false");
117
+ }
118
+ __name(isBoolean, "isBoolean");
119
+ function isNumber(info) {
120
+ return Rule((param) => typeof param === "number", info || "it should be true or false");
121
+ }
122
+ __name(isNumber, "isNumber");
123
+ function isString(info) {
124
+ return Rule((param) => typeof param === "string", info || "it should be a string");
125
+ }
126
+ __name(isString, "isString");
127
+ function isObject(info) {
128
+ return Rule((param) => {
129
+ return Object.prototype.toString.call(param) === "[object Object]";
130
+ }, info || "it should be an object");
131
+ }
132
+ __name(isObject, "isObject");
133
+ function isMobile(info) {
134
+ 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");
135
+ }
136
+ __name(isMobile, "isMobile");
137
+ function isLandline(info) {
138
+ return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || "it should be a mobile phone number");
139
+ }
140
+ __name(isLandline, "isLandline");
141
+ function isMailBox(info) {
142
+ 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");
143
+ }
144
+ __name(isMailBox, "isMailBox");
145
+ function isIdCard(info) {
146
+ 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");
147
+ }
148
+ __name(isIdCard, "isIdCard");
149
+ function isCnName(info) {
150
+ return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57");
151
+ }
152
+ __name(isCnName, "isCnName");
153
+ function isEnName(info) {
154
+ return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || "it should be a valid en-name");
155
+ }
156
+ __name(isEnName, "isEnName");
157
+ function isDate(info) {
158
+ 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");
159
+ }
160
+ __name(isDate, "isDate");
161
+ function isWechat(info) {
162
+ return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || "it should be a valid date");
163
+ }
164
+ __name(isWechat, "isWechat");
165
+ function isHexColor(info) {
166
+ return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || "it should be a valid hex-color");
167
+ }
168
+ __name(isHexColor, "isHexColor");
169
+ function isPostalCode(info) {
170
+ 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");
171
+ }
172
+ __name(isPostalCode, "isPostalCode");
173
+
174
+ // src/helper.ts
175
+ function to(task, oldTasks) {
176
+ const tasks = oldTasks || [];
177
+ tasks.push(task);
178
+ return {
179
+ to: (task2) => to(task2, tasks),
180
+ value: tasks
181
+ };
182
+ }
183
+ __name(to, "to");
184
+
185
+ // src/preset/pipe.ts
186
+ function toNumber() {
187
+ return Pipe(to((param) => Number(param)));
188
+ }
189
+ __name(toNumber, "toNumber");
190
+ function toString() {
191
+ return Pipe(to((param) => String(param)));
192
+ }
193
+ __name(toString, "toString");
194
+ return __toCommonJS(preset_exports);
195
+ })();
@@ -0,0 +1,213 @@
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
+ __TAG__: "",
49
+ __INIT_EVENT__: /* @__PURE__ */ new Set(),
50
+ __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
51
+ __IGNORE_VAR__: /* @__PURE__ */ new Set(),
52
+ __STATE_VAR__: /* @__PURE__ */ new Set(),
53
+ __STATE_HANDLER__: /* @__PURE__ */ new Map(),
54
+ __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
55
+ };
56
+ }
57
+ }
58
+ __name(init, "init");
59
+ function setModalVar(target, key) {
60
+ init(target);
61
+ target._namespace.__STATE_VAR__.add(key);
62
+ setExposeKey(target, key);
63
+ }
64
+ __name(setModalVar, "setModalVar");
65
+ function setExposeKey(target, key) {
66
+ init(target);
67
+ target._namespace.__EXPOSE_VAR__.add(key);
68
+ }
69
+ __name(setExposeKey, "setExposeKey");
70
+ function regisHandler(target, key, handler) {
71
+ init(target);
72
+ if (!target._namespace.__STATE_HANDLER__.has(key))
73
+ target._namespace.__STATE_HANDLER__.set(key, [
74
+ handler
75
+ ]);
76
+ else
77
+ target._namespace.__STATE_HANDLER__.get(key).push(handler);
78
+ }
79
+ __name(regisHandler, "regisHandler");
80
+
81
+ // src/decorators.ts
82
+ function Rule(rule, info, meta) {
83
+ return (obj, key) => {
84
+ setModalVar(obj, key);
85
+ regisHandler(obj, key, {
86
+ rule,
87
+ info,
88
+ meta
89
+ });
90
+ };
91
+ }
92
+ __name(Rule, "Rule");
93
+ function Pipe(v) {
94
+ return (obj, key) => {
95
+ setModalVar(obj, key);
96
+ regisHandler(obj, key, {
97
+ async pipe(instance) {
98
+ const tasks = v.value;
99
+ for (const task of tasks)
100
+ instance[key] = await task(instance[key]);
101
+ }
102
+ });
103
+ };
104
+ }
105
+ __name(Pipe, "Pipe");
106
+
107
+ // src/preset/rule.ts
108
+ function isArray(info) {
109
+ return Rule((param) => Array.isArray(param), info || "it should be an array");
110
+ }
111
+ __name(isArray, "isArray");
112
+ function isBoolean(info) {
113
+ return Rule((param) => [
114
+ true,
115
+ false
116
+ ].includes(param), info || "it should be true or false");
117
+ }
118
+ __name(isBoolean, "isBoolean");
119
+ function isNumber(info) {
120
+ return Rule((param) => typeof param === "number", info || "it should be true or false");
121
+ }
122
+ __name(isNumber, "isNumber");
123
+ function isString(info) {
124
+ return Rule((param) => typeof param === "string", info || "it should be a string");
125
+ }
126
+ __name(isString, "isString");
127
+ function isObject(info) {
128
+ return Rule((param) => {
129
+ return Object.prototype.toString.call(param) === "[object Object]";
130
+ }, info || "it should be an object");
131
+ }
132
+ __name(isObject, "isObject");
133
+ function isMobile(info) {
134
+ 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");
135
+ }
136
+ __name(isMobile, "isMobile");
137
+ function isLandline(info) {
138
+ return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || "it should be a mobile phone number");
139
+ }
140
+ __name(isLandline, "isLandline");
141
+ function isMailBox(info) {
142
+ 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");
143
+ }
144
+ __name(isMailBox, "isMailBox");
145
+ function isIdCard(info) {
146
+ 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");
147
+ }
148
+ __name(isIdCard, "isIdCard");
149
+ function isCnName(info) {
150
+ return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57");
151
+ }
152
+ __name(isCnName, "isCnName");
153
+ function isEnName(info) {
154
+ return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || "it should be a valid en-name");
155
+ }
156
+ __name(isEnName, "isEnName");
157
+ function isDate(info) {
158
+ 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");
159
+ }
160
+ __name(isDate, "isDate");
161
+ function isWechat(info) {
162
+ return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || "it should be a valid date");
163
+ }
164
+ __name(isWechat, "isWechat");
165
+ function isHexColor(info) {
166
+ return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || "it should be a valid hex-color");
167
+ }
168
+ __name(isHexColor, "isHexColor");
169
+ function isPostalCode(info) {
170
+ 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");
171
+ }
172
+ __name(isPostalCode, "isPostalCode");
173
+
174
+ // src/helper.ts
175
+ function to(task, oldTasks) {
176
+ const tasks = oldTasks || [];
177
+ tasks.push(task);
178
+ return {
179
+ to: (task2) => to(task2, tasks),
180
+ value: tasks
181
+ };
182
+ }
183
+ __name(to, "to");
184
+
185
+ // src/preset/pipe.ts
186
+ function toNumber() {
187
+ return Pipe(to((param) => Number(param)));
188
+ }
189
+ __name(toNumber, "toNumber");
190
+ function toString() {
191
+ return Pipe(to((param) => String(param)));
192
+ }
193
+ __name(toString, "toString");
194
+ // Annotate the CommonJS export names for ESM import in node:
195
+ 0 && (module.exports = {
196
+ isArray,
197
+ isBoolean,
198
+ isCnName,
199
+ isDate,
200
+ isEnName,
201
+ isHexColor,
202
+ isIdCard,
203
+ isLandline,
204
+ isMailBox,
205
+ isMobile,
206
+ isNumber,
207
+ isObject,
208
+ isPostalCode,
209
+ isString,
210
+ isWechat,
211
+ toNumber,
212
+ toString
213
+ });
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "provide base function and abstract limit to other phecda module ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",