phecda-core 2.0.0-alpha.6 → 2.0.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 CHANGED
@@ -1,5 +1,3 @@
1
- export { a as isArray, b as isBoolean, k as isCnName, m as isDate, l as isEnName, o as isHexColor, j as isIdCard, g as isLandline, h as isMailBox, f as isMobile, c as isNumber, e as isObject, i as isOption, p as isPostalCode, d as isString, n as isWechat, t as toNumber, q as toString } from './pipe-5d060247.js';
2
-
3
1
  interface NameSpace {
4
2
  [name: string]: Phecda;
5
3
  }
@@ -128,4 +126,24 @@ declare function Watcher(eventName: keyof Events, options?: {
128
126
  declare function Effect(eventName: string, options?: any): (obj: any, key: string) => void;
129
127
  declare function Storage(storeKey?: string): (target: any, key?: PropertyKey) => void;
130
128
 
131
- export { Assign, Bind, ClassValue, Clear, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, NameSpace, Phecda, Pipe, Provide, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getInitEvent, getModelState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnInitEvent, getOwnModelState, getOwnState, getProperty, getState, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModelVar, setState, snapShot, to, validate };
129
+ declare function isOption(): (obj: any, key: PropertyKey) => void;
130
+ declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
131
+ declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
132
+ declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
133
+ declare function isString(info?: string): (obj: any, key: PropertyKey) => void;
134
+ declare function isObject(info?: string): (obj: any, key: PropertyKey) => void;
135
+ declare function isMobile(info?: string): (obj: any, key: PropertyKey) => void;
136
+ declare function isLandline(info?: string): (obj: any, key: PropertyKey) => void;
137
+ declare function isMailBox(info?: string): (obj: any, key: PropertyKey) => void;
138
+ declare function isIdCard(info?: string): (obj: any, key: PropertyKey) => void;
139
+ declare function isCnName(info?: string): (obj: any, key: PropertyKey) => void;
140
+ declare function isEnName(info?: string): (obj: any, key: PropertyKey) => void;
141
+ declare function isDate(info?: string): (obj: any, key: PropertyKey) => void;
142
+ declare function isWechat(info?: string): (obj: any, key: PropertyKey) => void;
143
+ declare function isHexColor(info?: string): (obj: any, key: PropertyKey) => void;
144
+ declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => void;
145
+
146
+ declare function toNumber(): (obj: any, key: PropertyKey) => void;
147
+ declare function toString(): (obj: any, key: PropertyKey) => void;
148
+
149
+ export { Assign, Bind, ClassValue, Clear, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, NameSpace, Phecda, Pipe, Provide, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getInitEvent, getModelState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnInitEvent, getOwnModelState, getOwnState, getProperty, getState, getTag, init, injectProperty, isArray, isBoolean, isCnName, isDate, isEnName, isHexColor, isIdCard, isLandline, isMailBox, isMobile, isNumber, isObject, isOption, isPhecda, isPostalCode, isString, isWechat, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModelVar, setState, snapShot, to, toNumber, toString, validate };
package/dist/index.js CHANGED
@@ -389,8 +389,13 @@ function Provide(key, value) {
389
389
  DataMap[key] = value;
390
390
  }
391
391
  __name(Provide, "Provide");
392
+ var EmptyProxy = new Proxy(Empty, {
393
+ apply() {
394
+ return EmptyProxy;
395
+ }
396
+ });
392
397
  function Inject(key) {
393
- return DataMap[key] || (() => Empty);
398
+ return DataMap[key] || EmptyProxy;
394
399
  }
395
400
  __name(Inject, "Inject");
396
401
 
package/dist/index.mjs CHANGED
@@ -298,8 +298,13 @@ function Provide(key, value) {
298
298
  DataMap[key] = value;
299
299
  }
300
300
  __name(Provide, "Provide");
301
+ var EmptyProxy = new Proxy(Empty, {
302
+ apply() {
303
+ return EmptyProxy;
304
+ }
305
+ });
301
306
  function Inject(key) {
302
- return DataMap[key] || (() => Empty);
307
+ return DataMap[key] || EmptyProxy;
303
308
  }
304
309
  __name(Inject, "Inject");
305
310
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0",
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",
@@ -1,677 +0,0 @@
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
- Assign: () => Assign,
26
- Bind: () => Bind,
27
- Clear: () => Clear,
28
- DataMap: () => DataMap,
29
- Effect: () => Effect,
30
- Empty: () => Empty,
31
- Err: () => Err,
32
- Expose: () => Expose,
33
- Global: () => Global,
34
- Ignore: () => Ignore,
35
- Init: () => Init,
36
- Inject: () => Inject,
37
- Pipe: () => Pipe,
38
- Provide: () => Provide,
39
- Rule: () => Rule,
40
- Storage: () => Storage,
41
- Tag: () => Tag,
42
- Watcher: () => Watcher,
43
- activeInstance: () => activeInstance,
44
- addDecoToClass: () => addDecoToClass,
45
- classToValue: () => classToValue,
46
- getBind: () => getBind,
47
- getExposeKey: () => getExposeKey,
48
- getHandler: () => getHandler,
49
- getInitEvent: () => getInitEvent,
50
- getModelState: () => getModelState,
51
- getOwnExposeKey: () => getOwnExposeKey,
52
- getOwnHandler: () => getOwnHandler,
53
- getOwnIgnoreKey: () => getOwnIgnoreKey,
54
- getOwnInitEvent: () => getOwnInitEvent,
55
- getOwnModelState: () => getOwnModelState,
56
- getOwnState: () => getOwnState,
57
- getProperty: () => getProperty,
58
- getState: () => getState,
59
- getTag: () => getTag,
60
- init: () => init,
61
- injectProperty: () => injectProperty,
62
- isArray: () => isArray,
63
- isBoolean: () => isBoolean,
64
- isCnName: () => isCnName,
65
- isDate: () => isDate,
66
- isEnName: () => isEnName,
67
- isHexColor: () => isHexColor,
68
- isIdCard: () => isIdCard,
69
- isLandline: () => isLandline,
70
- isMailBox: () => isMailBox,
71
- isMobile: () => isMobile,
72
- isNumber: () => isNumber,
73
- isObject: () => isObject,
74
- isOption: () => isOption,
75
- isPhecda: () => isPhecda,
76
- isPostalCode: () => isPostalCode,
77
- isString: () => isString,
78
- isWechat: () => isWechat,
79
- plainToClass: () => plainToClass,
80
- regisHandler: () => regisHandler,
81
- regisInitEvent: () => regisInitEvent,
82
- register: () => register,
83
- registerAsync: () => registerAsync,
84
- setExposeKey: () => setExposeKey,
85
- setIgnoreKey: () => setIgnoreKey,
86
- setModelVar: () => setModelVar,
87
- setState: () => setState,
88
- snapShot: () => snapShot,
89
- to: () => to,
90
- toNumber: () => toNumber,
91
- toString: () => toString,
92
- validate: () => validate
93
- });
94
-
95
- // src/core.ts
96
- function isPhecda(target) {
97
- return target && !!target.prototype._namespace;
98
- }
99
- __name(isPhecda, "isPhecda");
100
- function init(target) {
101
- if (!target)
102
- return;
103
- if (!target.hasOwnProperty("_namespace")) {
104
- target._namespace = {
105
- __INIT_EVENT__: /* @__PURE__ */ new Set(),
106
- __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
107
- __IGNORE_VAR__: /* @__PURE__ */ new Set(),
108
- __STATE_VAR__: /* @__PURE__ */ new Set(),
109
- __STATE_HANDLER__: /* @__PURE__ */ new Map(),
110
- __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
111
- };
112
- }
113
- }
114
- __name(init, "init");
115
- function regisInitEvent(target, key) {
116
- init(target);
117
- target._namespace.__INIT_EVENT__.add(key);
118
- }
119
- __name(regisInitEvent, "regisInitEvent");
120
- function getOwnInitEvent(target) {
121
- if (!target?._namespace)
122
- return [];
123
- return [
124
- ...target._namespace.__INIT_EVENT__
125
- ];
126
- }
127
- __name(getOwnInitEvent, "getOwnInitEvent");
128
- function getInitEvent(target) {
129
- let proto = Object.getPrototypeOf(target);
130
- const set = /* @__PURE__ */ new Set();
131
- while (proto?._namespace) {
132
- proto._namespace.__INIT_EVENT__.forEach((item) => set.add(item));
133
- proto = Object.getPrototypeOf(proto);
134
- }
135
- return [
136
- ...set
137
- ];
138
- }
139
- __name(getInitEvent, "getInitEvent");
140
- function setModelVar(target, key) {
141
- init(target);
142
- target._namespace.__STATE_VAR__.add(key);
143
- setExposeKey(target, key);
144
- }
145
- __name(setModelVar, "setModelVar");
146
- function setExposeKey(target, key) {
147
- init(target);
148
- target._namespace.__EXPOSE_VAR__.add(key);
149
- }
150
- __name(setExposeKey, "setExposeKey");
151
- function setIgnoreKey(target, key) {
152
- init(target);
153
- target._namespace.__IGNORE_VAR__.add(key);
154
- }
155
- __name(setIgnoreKey, "setIgnoreKey");
156
- function getOwnModelState(target) {
157
- target = Object.getPrototypeOf(target);
158
- return [
159
- ...target._namespace.__STATE_VAR__
160
- ];
161
- }
162
- __name(getOwnModelState, "getOwnModelState");
163
- function getModelState(target) {
164
- let proto = Object.getPrototypeOf(target);
165
- const set = /* @__PURE__ */ new Set();
166
- while (proto?._namespace) {
167
- proto._namespace.__STATE_VAR__.forEach((item) => set.add(item));
168
- proto = Object.getPrototypeOf(proto);
169
- }
170
- return [
171
- ...set
172
- ];
173
- }
174
- __name(getModelState, "getModelState");
175
- function getOwnExposeKey(target) {
176
- target = Object.getPrototypeOf(target);
177
- return [
178
- ...target._namespace.__EXPOSE_VAR__
179
- ].filter((item) => !target._namespace.__IGNORE_VAR__.has(item));
180
- }
181
- __name(getOwnExposeKey, "getOwnExposeKey");
182
- function getExposeKey(target) {
183
- let proto = Object.getPrototypeOf(target);
184
- const set = /* @__PURE__ */ new Set();
185
- while (proto?._namespace) {
186
- [
187
- ...proto._namespace.__EXPOSE_VAR__
188
- ].forEach((item) => !proto._namespace.__IGNORE_VAR__.has(item) && set.add(item));
189
- proto = Object.getPrototypeOf(proto);
190
- }
191
- return [
192
- ...set
193
- ];
194
- }
195
- __name(getExposeKey, "getExposeKey");
196
- function getOwnIgnoreKey(target) {
197
- if (!target?._namespace)
198
- return [];
199
- return [
200
- ...target._namespace.__IGNORE_VAR__
201
- ];
202
- }
203
- __name(getOwnIgnoreKey, "getOwnIgnoreKey");
204
- function regisHandler(target, key, handler) {
205
- init(target);
206
- if (!target._namespace.__STATE_HANDLER__.has(key))
207
- target._namespace.__STATE_HANDLER__.set(key, [
208
- handler
209
- ]);
210
- else
211
- target._namespace.__STATE_HANDLER__.get(key).push(handler);
212
- }
213
- __name(regisHandler, "regisHandler");
214
- function getOwnHandler(target, key) {
215
- if (!target?._namespace)
216
- return [];
217
- return target._namespace.__STATE_HANDLER__.get(key) || [];
218
- }
219
- __name(getOwnHandler, "getOwnHandler");
220
- function getHandler(target, key) {
221
- let proto = Object.getPrototypeOf(target);
222
- const set = /* @__PURE__ */ new Set();
223
- while (proto?._namespace) {
224
- proto._namespace.__STATE_HANDLER__.get(key)?.forEach((item) => set.add(item));
225
- proto = Object.getPrototypeOf(proto);
226
- }
227
- return [
228
- ...set
229
- ];
230
- }
231
- __name(getHandler, "getHandler");
232
- function setState(target, key, state) {
233
- init(target);
234
- const namespace = target._namespace.__STATE_NAMESPACE__;
235
- namespace.set(key, state);
236
- }
237
- __name(setState, "setState");
238
- function getOwnState(target, key) {
239
- target = Object.getPrototypeOf(target);
240
- return target._namespace.__STATE_NAMESPACE__.get(key) || {};
241
- }
242
- __name(getOwnState, "getOwnState");
243
- function getState(target, key) {
244
- let proto = Object.getPrototypeOf(target);
245
- let ret = {};
246
- while (proto?._namespace) {
247
- const state = proto._namespace.__STATE_NAMESPACE__.get(key);
248
- if (state)
249
- ret = {
250
- ...state,
251
- ...ret
252
- };
253
- proto = Object.getPrototypeOf(proto);
254
- }
255
- return ret;
256
- }
257
- __name(getState, "getState");
258
- function register(instance) {
259
- const stateVars = getExposeKey(instance);
260
- for (const item of stateVars) {
261
- const handlers = getHandler(instance, item);
262
- for (const hanlder of handlers)
263
- hanlder.init?.(instance);
264
- }
265
- }
266
- __name(register, "register");
267
- async function registerAsync(instance) {
268
- const stateVars = getExposeKey(instance);
269
- for (const item of stateVars) {
270
- const handlers = getHandler(instance, item);
271
- for (const hanlder of handlers)
272
- await hanlder.init?.(instance);
273
- }
274
- }
275
- __name(registerAsync, "registerAsync");
276
-
277
- // src/decorators.ts
278
- function Init(target, key) {
279
- setModelVar(target, key);
280
- regisHandler(target, key, {
281
- async init(instance) {
282
- instance[key]();
283
- }
284
- });
285
- }
286
- __name(Init, "Init");
287
- function Bind(value) {
288
- return (target, k) => {
289
- setModelVar(target, k);
290
- setState(target, k, {
291
- value
292
- });
293
- };
294
- }
295
- __name(Bind, "Bind");
296
- function Rule(rule, info, meta) {
297
- return (obj, key) => {
298
- setModelVar(obj, key);
299
- regisHandler(obj, key, {
300
- rule,
301
- info,
302
- meta
303
- });
304
- };
305
- }
306
- __name(Rule, "Rule");
307
- function Ignore(target, key) {
308
- setIgnoreKey(target, key);
309
- }
310
- __name(Ignore, "Ignore");
311
- function Clear(target, key) {
312
- init(target);
313
- target._namespace.__INIT_EVENT__.delete(key);
314
- target._namespace.__EXPOSE_VAR__.delete(key);
315
- target._namespace.__IGNORE_VAR__.delete(key);
316
- target._namespace.__STATE_VAR__.delete(key);
317
- target._namespace.__STATE_HANDLER__.delete(key);
318
- target._namespace.__STATE_NAMESPACE__.delete(key);
319
- }
320
- __name(Clear, "Clear");
321
- function Err(cb) {
322
- return (target, key) => {
323
- setModelVar(target, key);
324
- regisHandler(target, key, {
325
- error: cb
326
- });
327
- };
328
- }
329
- __name(Err, "Err");
330
- function Expose(target, key) {
331
- setExposeKey(target, key);
332
- }
333
- __name(Expose, "Expose");
334
- function Pipe(v) {
335
- return (obj, key) => {
336
- setModelVar(obj, key);
337
- regisHandler(obj, key, {
338
- async pipe(instance) {
339
- const tasks = v.value;
340
- for (const task of tasks)
341
- instance[key] = await task(instance[key]);
342
- }
343
- });
344
- };
345
- }
346
- __name(Pipe, "Pipe");
347
- function Tag(tag) {
348
- return (target) => {
349
- target.prototype.__TAG__ = tag;
350
- };
351
- }
352
- __name(Tag, "Tag");
353
- function Assign(cb) {
354
- return (target) => {
355
- init(target.prototype);
356
- setModelVar(target.prototype, "__CLASS");
357
- regisHandler(target.prototype, "__CLASS", {
358
- init: async (instance) => {
359
- const value = await cb(instance);
360
- if (value && typeof value === "object" && !Array.isArray(value)) {
361
- for (const i in value)
362
- instance[i] = value[i];
363
- }
364
- }
365
- });
366
- };
367
- }
368
- __name(Assign, "Assign");
369
- function Global(target) {
370
- init(target.prototype);
371
- setModelVar(target.prototype, "__CLASS");
372
- regisHandler(target.prototype, "__CLASS", {
373
- init: async (instance) => {
374
- const tag = instance.__TAG__;
375
- if (!tag)
376
- return;
377
- if (!globalThis.__PHECDA__)
378
- globalThis.__PHECDA__ = {};
379
- globalThis.__PHECDA__[tag] = instance.constructor;
380
- }
381
- });
382
- }
383
- __name(Global, "Global");
384
- function Empty(_target) {
385
- }
386
- __name(Empty, "Empty");
387
- var DataMap = {};
388
- function Provide(key, value) {
389
- DataMap[key] = value;
390
- }
391
- __name(Provide, "Provide");
392
- function Inject(key) {
393
- return DataMap[key] || (() => Empty);
394
- }
395
- __name(Inject, "Inject");
396
-
397
- // src/utils.ts
398
- async function validate(p, v) {
399
- if (typeof p === "string" || typeof p === "number") {
400
- if (v === p)
401
- return true;
402
- }
403
- if (typeof p === "function")
404
- return p(v);
405
- if (p instanceof RegExp)
406
- return p.test(v);
407
- return false;
408
- }
409
- __name(validate, "validate");
410
- function getTag(Model) {
411
- return Model.prototype?.__TAG__;
412
- }
413
- __name(getTag, "getTag");
414
-
415
- // src/helper.ts
416
- function getBind(Model) {
417
- const instance = new Model();
418
- const keys = getModelState(instance);
419
- const ret = {};
420
- for (const item of keys) {
421
- const state = getState(instance, item);
422
- if (state.value)
423
- ret[item] = state.value;
424
- }
425
- return ret;
426
- }
427
- __name(getBind, "getBind");
428
- async function plainToClass(Model, input, options = {}) {
429
- const data = new Model();
430
- const err = [];
431
- const stateVars = getModelState(data);
432
- for (const item of stateVars) {
433
- data[item] = input[item];
434
- const handlers = getHandler(data, item);
435
- if (handlers) {
436
- if (options.collectError !== false) {
437
- for (const handler of handlers) {
438
- const rule = handler.rule;
439
- const ret = await validate(rule, data[item]);
440
- if (ret === "ok")
441
- break;
442
- if (rule && !ret) {
443
- err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
444
- if (!options.collectError)
445
- break;
446
- }
447
- }
448
- }
449
- if (err.length > 0 && !options.transform)
450
- return {
451
- err,
452
- data
453
- };
454
- if (options.transform !== false) {
455
- for (const handler of handlers)
456
- await handler.pipe?.(data);
457
- }
458
- }
459
- }
460
- return {
461
- data,
462
- err
463
- };
464
- }
465
- __name(plainToClass, "plainToClass");
466
- function classToValue(instance) {
467
- const data = {};
468
- const exposeVars = getExposeKey(instance);
469
- for (const item of exposeVars)
470
- data[item] = instance[item];
471
- return data;
472
- }
473
- __name(classToValue, "classToValue");
474
- function to(task, oldTasks) {
475
- const tasks = oldTasks || [];
476
- tasks.push(task);
477
- return {
478
- to: (task2) => to(task2, tasks),
479
- value: tasks
480
- };
481
- }
482
- __name(to, "to");
483
- function snapShot(data) {
484
- const snap = {};
485
- for (const i in data)
486
- snap[i] = data[i];
487
- return {
488
- data,
489
- clear() {
490
- for (const i in snap)
491
- delete data[i];
492
- },
493
- apply() {
494
- for (const i in snap)
495
- data[i] = snap[i];
496
- }
497
- };
498
- }
499
- __name(snapShot, "snapShot");
500
- function addDecoToClass(c, key, handler, type = "normal") {
501
- handler(type === "normal" ? c.prototype : c, key);
502
- }
503
- __name(addDecoToClass, "addDecoToClass");
504
-
505
- // src/namespace.ts
506
- var activeInstance = {};
507
- function injectProperty(key, value) {
508
- activeInstance[key] = value;
509
- return activeInstance;
510
- }
511
- __name(injectProperty, "injectProperty");
512
- function getProperty(key) {
513
- return activeInstance[key];
514
- }
515
- __name(getProperty, "getProperty");
516
-
517
- // src/custom/decorator.ts
518
- function Watcher(eventName, options) {
519
- return (obj, key) => {
520
- setModelVar(obj, key);
521
- regisHandler(obj, key, {
522
- init(instance) {
523
- getProperty("watcher")?.({
524
- eventName,
525
- instance,
526
- key,
527
- options
528
- });
529
- }
530
- });
531
- };
532
- }
533
- __name(Watcher, "Watcher");
534
- function Effect(eventName, options) {
535
- return (obj, key) => {
536
- setModelVar(obj, key);
537
- regisHandler(obj, key, {
538
- init(instance) {
539
- instance[`$_${key}`] = instance[key];
540
- Object.defineProperty(instance, key, {
541
- get() {
542
- return instance[`$_${key}`];
543
- },
544
- set(v) {
545
- instance[`$_${key}`] = v;
546
- getProperty(`effect-${eventName}`)?.({
547
- instance,
548
- key,
549
- value: v,
550
- options
551
- });
552
- return true;
553
- }
554
- });
555
- }
556
- });
557
- };
558
- }
559
- __name(Effect, "Effect");
560
- function Storage(storeKey) {
561
- return (target, key) => {
562
- let tag;
563
- if (key) {
564
- init(target);
565
- tag = storeKey || target.__TAG__;
566
- const uniTag = Symbol(tag);
567
- setModelVar(target, uniTag);
568
- regisHandler(target, uniTag, {
569
- init: (instance) => {
570
- getProperty("storage")?.({
571
- instance,
572
- key,
573
- tag
574
- });
575
- }
576
- });
577
- } else {
578
- init(target.prototype);
579
- tag = storeKey || `${target.prototype.__TAG__}_${key}`;
580
- const uniTag = Symbol(tag);
581
- setModelVar(target.prototype, uniTag);
582
- regisHandler(target.prototype, uniTag, {
583
- init: (instance) => {
584
- getProperty("storage")?.({
585
- instance,
586
- key: "",
587
- tag
588
- });
589
- }
590
- });
591
- }
592
- };
593
- }
594
- __name(Storage, "Storage");
595
-
596
- // src/preset/rule.ts
597
- function isOption() {
598
- return Rule((param) => param === void 0 ? "ok" : true, "");
599
- }
600
- __name(isOption, "isOption");
601
- function isArray(info) {
602
- return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
603
- }
604
- __name(isArray, "isArray");
605
- function isBoolean(info) {
606
- return Rule((param) => [
607
- true,
608
- false
609
- ].includes(param), info || ((k) => `'${k}' should be boolean`));
610
- }
611
- __name(isBoolean, "isBoolean");
612
- function isNumber(info) {
613
- return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
614
- }
615
- __name(isNumber, "isNumber");
616
- function isString(info) {
617
- return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
618
- }
619
- __name(isString, "isString");
620
- function isObject(info) {
621
- return Rule((param) => {
622
- return Object.prototype.toString.call(param) === "[object Object]";
623
- }, info || ((k) => `'${k}' should be an object`));
624
- }
625
- __name(isObject, "isObject");
626
- function isMobile(info) {
627
- 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 || ((k) => `'${k}' should be a mobile phone number`));
628
- }
629
- __name(isMobile, "isMobile");
630
- function isLandline(info) {
631
- return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
632
- }
633
- __name(isLandline, "isLandline");
634
- function isMailBox(info) {
635
- 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 || ((k) => `'${k}' should be a mailbox`));
636
- }
637
- __name(isMailBox, "isMailBox");
638
- function isIdCard(info) {
639
- 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 || ((k) => `'${k}' should be an identity card number`));
640
- }
641
- __name(isIdCard, "isIdCard");
642
- function isCnName(info) {
643
- return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
644
- }
645
- __name(isCnName, "isCnName");
646
- function isEnName(info) {
647
- return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
648
- }
649
- __name(isEnName, "isEnName");
650
- function isDate(info) {
651
- 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 || ((k) => `'${k}' should be a valid date`));
652
- }
653
- __name(isDate, "isDate");
654
- function isWechat(info) {
655
- return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
656
- }
657
- __name(isWechat, "isWechat");
658
- function isHexColor(info) {
659
- return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
660
- }
661
- __name(isHexColor, "isHexColor");
662
- function isPostalCode(info) {
663
- 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 || ((k) => `'${k}' should be a valid postal code`));
664
- }
665
- __name(isPostalCode, "isPostalCode");
666
-
667
- // src/preset/pipe.ts
668
- function toNumber() {
669
- return Pipe(to((param) => Number(param)));
670
- }
671
- __name(toNumber, "toNumber");
672
- function toString() {
673
- return Pipe(to((param) => String(param)));
674
- }
675
- __name(toString, "toString");
676
- return __toCommonJS(src_exports);
677
- })();
@@ -1,21 +0,0 @@
1
- declare function isOption(): (obj: any, key: PropertyKey) => void;
2
- declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
3
- declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
4
- declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
5
- declare function isString(info?: string): (obj: any, key: PropertyKey) => void;
6
- declare function isObject(info?: string): (obj: any, key: PropertyKey) => void;
7
- declare function isMobile(info?: string): (obj: any, key: PropertyKey) => void;
8
- declare function isLandline(info?: string): (obj: any, key: PropertyKey) => void;
9
- declare function isMailBox(info?: string): (obj: any, key: PropertyKey) => void;
10
- declare function isIdCard(info?: string): (obj: any, key: PropertyKey) => void;
11
- declare function isCnName(info?: string): (obj: any, key: PropertyKey) => void;
12
- declare function isEnName(info?: string): (obj: any, key: PropertyKey) => void;
13
- declare function isDate(info?: string): (obj: any, key: PropertyKey) => void;
14
- declare function isWechat(info?: string): (obj: any, key: PropertyKey) => void;
15
- declare function isHexColor(info?: string): (obj: any, key: PropertyKey) => void;
16
- declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => void;
17
-
18
- declare function toNumber(): (obj: any, key: PropertyKey) => void;
19
- declare function toString(): (obj: any, key: PropertyKey) => void;
20
-
21
- export { isArray as a, isBoolean as b, isNumber as c, isString as d, isObject as e, isMobile as f, isLandline as g, isMailBox as h, isOption as i, isIdCard as j, isCnName as k, isEnName as l, isDate as m, isWechat as n, isHexColor as o, isPostalCode as p, toString as q, toNumber as t };
@@ -1 +0,0 @@
1
- export { a as isArray, b as isBoolean, k as isCnName, m as isDate, l as isEnName, o as isHexColor, j as isIdCard, g as isLandline, h as isMailBox, f as isMobile, c as isNumber, e as isObject, i as isOption, p as isPostalCode, d as isString, n as isWechat, t as toNumber, q as toString } from '../pipe-5d060247.js';
@@ -1,201 +0,0 @@
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
- isOption: () => isOption,
38
- isPostalCode: () => isPostalCode,
39
- isString: () => isString,
40
- isWechat: () => isWechat,
41
- toNumber: () => toNumber,
42
- toString: () => toString
43
- });
44
-
45
- // src/core.ts
46
- function init(target) {
47
- if (!target)
48
- return;
49
- if (!target.hasOwnProperty("_namespace")) {
50
- target._namespace = {
51
- __INIT_EVENT__: /* @__PURE__ */ new Set(),
52
- __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
53
- __IGNORE_VAR__: /* @__PURE__ */ new Set(),
54
- __STATE_VAR__: /* @__PURE__ */ new Set(),
55
- __STATE_HANDLER__: /* @__PURE__ */ new Map(),
56
- __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
57
- };
58
- }
59
- }
60
- __name(init, "init");
61
- function setModelVar(target, key) {
62
- init(target);
63
- target._namespace.__STATE_VAR__.add(key);
64
- setExposeKey(target, key);
65
- }
66
- __name(setModelVar, "setModelVar");
67
- function setExposeKey(target, key) {
68
- init(target);
69
- target._namespace.__EXPOSE_VAR__.add(key);
70
- }
71
- __name(setExposeKey, "setExposeKey");
72
- function regisHandler(target, key, handler) {
73
- init(target);
74
- if (!target._namespace.__STATE_HANDLER__.has(key))
75
- target._namespace.__STATE_HANDLER__.set(key, [
76
- handler
77
- ]);
78
- else
79
- target._namespace.__STATE_HANDLER__.get(key).push(handler);
80
- }
81
- __name(regisHandler, "regisHandler");
82
-
83
- // src/decorators.ts
84
- function Rule(rule, info, meta) {
85
- return (obj, key) => {
86
- setModelVar(obj, key);
87
- regisHandler(obj, key, {
88
- rule,
89
- info,
90
- meta
91
- });
92
- };
93
- }
94
- __name(Rule, "Rule");
95
- function Pipe(v) {
96
- return (obj, key) => {
97
- setModelVar(obj, key);
98
- regisHandler(obj, key, {
99
- async pipe(instance) {
100
- const tasks = v.value;
101
- for (const task of tasks)
102
- instance[key] = await task(instance[key]);
103
- }
104
- });
105
- };
106
- }
107
- __name(Pipe, "Pipe");
108
-
109
- // src/preset/rule.ts
110
- function isOption() {
111
- return Rule((param) => param === void 0 ? "ok" : true, "");
112
- }
113
- __name(isOption, "isOption");
114
- function isArray(info) {
115
- return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
116
- }
117
- __name(isArray, "isArray");
118
- function isBoolean(info) {
119
- return Rule((param) => [
120
- true,
121
- false
122
- ].includes(param), info || ((k) => `'${k}' should be boolean`));
123
- }
124
- __name(isBoolean, "isBoolean");
125
- function isNumber(info) {
126
- return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
127
- }
128
- __name(isNumber, "isNumber");
129
- function isString(info) {
130
- return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
131
- }
132
- __name(isString, "isString");
133
- function isObject(info) {
134
- return Rule((param) => {
135
- return Object.prototype.toString.call(param) === "[object Object]";
136
- }, info || ((k) => `'${k}' should be an object`));
137
- }
138
- __name(isObject, "isObject");
139
- function isMobile(info) {
140
- 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 || ((k) => `'${k}' should be a mobile phone number`));
141
- }
142
- __name(isMobile, "isMobile");
143
- function isLandline(info) {
144
- return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
145
- }
146
- __name(isLandline, "isLandline");
147
- function isMailBox(info) {
148
- 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 || ((k) => `'${k}' should be a mailbox`));
149
- }
150
- __name(isMailBox, "isMailBox");
151
- function isIdCard(info) {
152
- 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 || ((k) => `'${k}' should be an identity card number`));
153
- }
154
- __name(isIdCard, "isIdCard");
155
- function isCnName(info) {
156
- return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
157
- }
158
- __name(isCnName, "isCnName");
159
- function isEnName(info) {
160
- return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
161
- }
162
- __name(isEnName, "isEnName");
163
- function isDate(info) {
164
- 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 || ((k) => `'${k}' should be a valid date`));
165
- }
166
- __name(isDate, "isDate");
167
- function isWechat(info) {
168
- return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
169
- }
170
- __name(isWechat, "isWechat");
171
- function isHexColor(info) {
172
- return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
173
- }
174
- __name(isHexColor, "isHexColor");
175
- function isPostalCode(info) {
176
- 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 || ((k) => `'${k}' should be a valid postal code`));
177
- }
178
- __name(isPostalCode, "isPostalCode");
179
-
180
- // src/helper.ts
181
- function to(task, oldTasks) {
182
- const tasks = oldTasks || [];
183
- tasks.push(task);
184
- return {
185
- to: (task2) => to(task2, tasks),
186
- value: tasks
187
- };
188
- }
189
- __name(to, "to");
190
-
191
- // src/preset/pipe.ts
192
- function toNumber() {
193
- return Pipe(to((param) => Number(param)));
194
- }
195
- __name(toNumber, "toNumber");
196
- function toString() {
197
- return Pipe(to((param) => String(param)));
198
- }
199
- __name(toString, "toString");
200
- return __toCommonJS(preset_exports);
201
- })();
@@ -1,220 +0,0 @@
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
- isOption: () => isOption,
37
- isPostalCode: () => isPostalCode,
38
- isString: () => isString,
39
- isWechat: () => isWechat,
40
- toNumber: () => toNumber,
41
- toString: () => toString
42
- });
43
- module.exports = __toCommonJS(preset_exports);
44
-
45
- // src/core.ts
46
- function init(target) {
47
- if (!target)
48
- return;
49
- if (!target.hasOwnProperty("_namespace")) {
50
- target._namespace = {
51
- __INIT_EVENT__: /* @__PURE__ */ new Set(),
52
- __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
53
- __IGNORE_VAR__: /* @__PURE__ */ new Set(),
54
- __STATE_VAR__: /* @__PURE__ */ new Set(),
55
- __STATE_HANDLER__: /* @__PURE__ */ new Map(),
56
- __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
57
- };
58
- }
59
- }
60
- __name(init, "init");
61
- function setModelVar(target, key) {
62
- init(target);
63
- target._namespace.__STATE_VAR__.add(key);
64
- setExposeKey(target, key);
65
- }
66
- __name(setModelVar, "setModelVar");
67
- function setExposeKey(target, key) {
68
- init(target);
69
- target._namespace.__EXPOSE_VAR__.add(key);
70
- }
71
- __name(setExposeKey, "setExposeKey");
72
- function regisHandler(target, key, handler) {
73
- init(target);
74
- if (!target._namespace.__STATE_HANDLER__.has(key))
75
- target._namespace.__STATE_HANDLER__.set(key, [
76
- handler
77
- ]);
78
- else
79
- target._namespace.__STATE_HANDLER__.get(key).push(handler);
80
- }
81
- __name(regisHandler, "regisHandler");
82
-
83
- // src/decorators.ts
84
- function Rule(rule, info, meta) {
85
- return (obj, key) => {
86
- setModelVar(obj, key);
87
- regisHandler(obj, key, {
88
- rule,
89
- info,
90
- meta
91
- });
92
- };
93
- }
94
- __name(Rule, "Rule");
95
- function Pipe(v) {
96
- return (obj, key) => {
97
- setModelVar(obj, key);
98
- regisHandler(obj, key, {
99
- async pipe(instance) {
100
- const tasks = v.value;
101
- for (const task of tasks)
102
- instance[key] = await task(instance[key]);
103
- }
104
- });
105
- };
106
- }
107
- __name(Pipe, "Pipe");
108
-
109
- // src/preset/rule.ts
110
- function isOption() {
111
- return Rule((param) => param === void 0 ? "ok" : true, "");
112
- }
113
- __name(isOption, "isOption");
114
- function isArray(info) {
115
- return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
116
- }
117
- __name(isArray, "isArray");
118
- function isBoolean(info) {
119
- return Rule((param) => [
120
- true,
121
- false
122
- ].includes(param), info || ((k) => `'${k}' should be boolean`));
123
- }
124
- __name(isBoolean, "isBoolean");
125
- function isNumber(info) {
126
- return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
127
- }
128
- __name(isNumber, "isNumber");
129
- function isString(info) {
130
- return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
131
- }
132
- __name(isString, "isString");
133
- function isObject(info) {
134
- return Rule((param) => {
135
- return Object.prototype.toString.call(param) === "[object Object]";
136
- }, info || ((k) => `'${k}' should be an object`));
137
- }
138
- __name(isObject, "isObject");
139
- function isMobile(info) {
140
- 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 || ((k) => `'${k}' should be a mobile phone number`));
141
- }
142
- __name(isMobile, "isMobile");
143
- function isLandline(info) {
144
- return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
145
- }
146
- __name(isLandline, "isLandline");
147
- function isMailBox(info) {
148
- 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 || ((k) => `'${k}' should be a mailbox`));
149
- }
150
- __name(isMailBox, "isMailBox");
151
- function isIdCard(info) {
152
- 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 || ((k) => `'${k}' should be an identity card number`));
153
- }
154
- __name(isIdCard, "isIdCard");
155
- function isCnName(info) {
156
- return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
157
- }
158
- __name(isCnName, "isCnName");
159
- function isEnName(info) {
160
- return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
161
- }
162
- __name(isEnName, "isEnName");
163
- function isDate(info) {
164
- 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 || ((k) => `'${k}' should be a valid date`));
165
- }
166
- __name(isDate, "isDate");
167
- function isWechat(info) {
168
- return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
169
- }
170
- __name(isWechat, "isWechat");
171
- function isHexColor(info) {
172
- return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
173
- }
174
- __name(isHexColor, "isHexColor");
175
- function isPostalCode(info) {
176
- 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 || ((k) => `'${k}' should be a valid postal code`));
177
- }
178
- __name(isPostalCode, "isPostalCode");
179
-
180
- // src/helper.ts
181
- function to(task, oldTasks) {
182
- const tasks = oldTasks || [];
183
- tasks.push(task);
184
- return {
185
- to: (task2) => to(task2, tasks),
186
- value: tasks
187
- };
188
- }
189
- __name(to, "to");
190
-
191
- // src/preset/pipe.ts
192
- function toNumber() {
193
- return Pipe(to((param) => Number(param)));
194
- }
195
- __name(toNumber, "toNumber");
196
- function toString() {
197
- return Pipe(to((param) => String(param)));
198
- }
199
- __name(toString, "toString");
200
- // Annotate the CommonJS export names for ESM import in node:
201
- 0 && (module.exports = {
202
- isArray,
203
- isBoolean,
204
- isCnName,
205
- isDate,
206
- isEnName,
207
- isHexColor,
208
- isIdCard,
209
- isLandline,
210
- isMailBox,
211
- isMobile,
212
- isNumber,
213
- isObject,
214
- isOption,
215
- isPostalCode,
216
- isString,
217
- isWechat,
218
- toNumber,
219
- toString
220
- });
@@ -1,178 +0,0 @@
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)
7
- return;
8
- if (!target.hasOwnProperty("_namespace")) {
9
- target._namespace = {
10
- __INIT_EVENT__: /* @__PURE__ */ new Set(),
11
- __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
12
- __IGNORE_VAR__: /* @__PURE__ */ new Set(),
13
- __STATE_VAR__: /* @__PURE__ */ new Set(),
14
- __STATE_HANDLER__: /* @__PURE__ */ new Map(),
15
- __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
16
- };
17
- }
18
- }
19
- __name(init, "init");
20
- function setModelVar(target, key) {
21
- init(target);
22
- target._namespace.__STATE_VAR__.add(key);
23
- setExposeKey(target, key);
24
- }
25
- __name(setModelVar, "setModelVar");
26
- function setExposeKey(target, key) {
27
- init(target);
28
- target._namespace.__EXPOSE_VAR__.add(key);
29
- }
30
- __name(setExposeKey, "setExposeKey");
31
- function regisHandler(target, key, handler) {
32
- init(target);
33
- if (!target._namespace.__STATE_HANDLER__.has(key))
34
- target._namespace.__STATE_HANDLER__.set(key, [
35
- handler
36
- ]);
37
- else
38
- target._namespace.__STATE_HANDLER__.get(key).push(handler);
39
- }
40
- __name(regisHandler, "regisHandler");
41
-
42
- // src/decorators.ts
43
- function Rule(rule, info, meta) {
44
- return (obj, key) => {
45
- setModelVar(obj, key);
46
- regisHandler(obj, key, {
47
- rule,
48
- info,
49
- meta
50
- });
51
- };
52
- }
53
- __name(Rule, "Rule");
54
- function Pipe(v) {
55
- return (obj, key) => {
56
- setModelVar(obj, key);
57
- regisHandler(obj, key, {
58
- async pipe(instance) {
59
- const tasks = v.value;
60
- for (const task of tasks)
61
- instance[key] = await task(instance[key]);
62
- }
63
- });
64
- };
65
- }
66
- __name(Pipe, "Pipe");
67
-
68
- // src/preset/rule.ts
69
- function isOption() {
70
- return Rule((param) => param === void 0 ? "ok" : true, "");
71
- }
72
- __name(isOption, "isOption");
73
- function isArray(info) {
74
- return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
75
- }
76
- __name(isArray, "isArray");
77
- function isBoolean(info) {
78
- return Rule((param) => [
79
- true,
80
- false
81
- ].includes(param), info || ((k) => `'${k}' should be boolean`));
82
- }
83
- __name(isBoolean, "isBoolean");
84
- function isNumber(info) {
85
- return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
86
- }
87
- __name(isNumber, "isNumber");
88
- function isString(info) {
89
- return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
90
- }
91
- __name(isString, "isString");
92
- function isObject(info) {
93
- return Rule((param) => {
94
- return Object.prototype.toString.call(param) === "[object Object]";
95
- }, info || ((k) => `'${k}' should be an object`));
96
- }
97
- __name(isObject, "isObject");
98
- function isMobile(info) {
99
- 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 || ((k) => `'${k}' should be a mobile phone number`));
100
- }
101
- __name(isMobile, "isMobile");
102
- function isLandline(info) {
103
- return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
104
- }
105
- __name(isLandline, "isLandline");
106
- function isMailBox(info) {
107
- 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 || ((k) => `'${k}' should be a mailbox`));
108
- }
109
- __name(isMailBox, "isMailBox");
110
- function isIdCard(info) {
111
- 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 || ((k) => `'${k}' should be an identity card number`));
112
- }
113
- __name(isIdCard, "isIdCard");
114
- function isCnName(info) {
115
- return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
116
- }
117
- __name(isCnName, "isCnName");
118
- function isEnName(info) {
119
- return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
120
- }
121
- __name(isEnName, "isEnName");
122
- function isDate(info) {
123
- 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 || ((k) => `'${k}' should be a valid date`));
124
- }
125
- __name(isDate, "isDate");
126
- function isWechat(info) {
127
- return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
128
- }
129
- __name(isWechat, "isWechat");
130
- function isHexColor(info) {
131
- return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
132
- }
133
- __name(isHexColor, "isHexColor");
134
- function isPostalCode(info) {
135
- 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 || ((k) => `'${k}' should be a valid postal code`));
136
- }
137
- __name(isPostalCode, "isPostalCode");
138
-
139
- // src/helper.ts
140
- function to(task, oldTasks) {
141
- const tasks = oldTasks || [];
142
- tasks.push(task);
143
- return {
144
- to: (task2) => to(task2, tasks),
145
- value: tasks
146
- };
147
- }
148
- __name(to, "to");
149
-
150
- // src/preset/pipe.ts
151
- function toNumber() {
152
- return Pipe(to((param) => Number(param)));
153
- }
154
- __name(toNumber, "toNumber");
155
- function toString() {
156
- return Pipe(to((param) => String(param)));
157
- }
158
- __name(toString, "toString");
159
- export {
160
- isArray,
161
- isBoolean,
162
- isCnName,
163
- isDate,
164
- isEnName,
165
- isHexColor,
166
- isIdCard,
167
- isLandline,
168
- isMailBox,
169
- isMobile,
170
- isNumber,
171
- isObject,
172
- isOption,
173
- isPostalCode,
174
- isString,
175
- isWechat,
176
- toNumber,
177
- toString
178
- };