phecda-core 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # phecda-core
2
+ provide base function and abstract limit to other phecda module
3
+
package/dist/index.d.ts CHANGED
@@ -79,7 +79,6 @@ declare function Err<Fn extends (...args: any) => any>(cb: Fn): (target: any, ke
79
79
  declare function P(target: any, key: PropertyKey): void;
80
80
  declare function Pipe(v: ReturnType<typeof to>): (obj: any, key: PropertyKey) => void;
81
81
  declare function Tag(tag: string): (target: any) => void;
82
- declare function Storage(target: any): void;
83
82
  declare function Global(target: any): void;
84
83
 
85
84
  declare function validate(p: RegExp | string | Function | Object | Number, v: any): Promise<any>;
@@ -103,25 +102,6 @@ declare function getState(target: Phecda, key: PropertyKey): Object | undefined;
103
102
  declare function register(instance: Phecda): void;
104
103
  declare function registerAsync(instance: Phecda): Promise<void>;
105
104
 
106
- declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
107
- declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
108
- declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
109
- declare function isString(info?: string): (obj: any, key: PropertyKey) => void;
110
- declare function isObject(info?: string): (obj: any, key: PropertyKey) => void;
111
- declare function isMobile(info?: string): (obj: any, key: PropertyKey) => void;
112
- declare function isLandline(info?: string): (obj: any, key: PropertyKey) => void;
113
- declare function isMailBox(info?: string): (obj: any, key: PropertyKey) => void;
114
- declare function isIdCard(info?: string): (obj: any, key: PropertyKey) => void;
115
- declare function isCnName(info?: string): (obj: any, key: PropertyKey) => void;
116
- declare function isEnName(info?: string): (obj: any, key: PropertyKey) => void;
117
- declare function isDate(info?: string): (obj: any, key: PropertyKey) => void;
118
- declare function isWechat(info?: string): (obj: any, key: PropertyKey) => void;
119
- declare function isHexColor(info?: string): (obj: any, key: PropertyKey) => void;
120
- declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => void;
121
-
122
- declare function toNumber(): (obj: any, key: PropertyKey) => void;
123
- declare function toString(): (obj: any, key: PropertyKey) => void;
124
-
125
105
  declare const activeInstance: Record<string, any>;
126
106
  declare function injectProperty(key: string, value: any): Record<string, any>;
127
107
  declare function getProperty(key: string): any;
@@ -129,5 +109,6 @@ declare function getProperty(key: string): any;
129
109
  declare function Watcher(eventName: keyof PhecdaEvents, options?: {
130
110
  once: boolean;
131
111
  }): (obj: any, key: string) => void;
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);
@@ -301,29 +284,6 @@ function Tag(tag) {
301
284
  };
302
285
  }
303
286
  __name(Tag, "Tag");
304
- function Storage(target) {
305
- init(target.prototype);
306
- const tag = target.prototype._namespace.__TAG__;
307
- if (tag === "")
308
- throw new Error("miss tag");
309
- const uniTag = Symbol(tag);
310
- setModalVar(target.prototype, uniTag);
311
- regisHandler(target.prototype, uniTag, {
312
- init: (instance) => {
313
- const { state } = instance;
314
- globalThis.addEventListener("beforeunload", () => {
315
- localStorage.setItem(`_phecda_${tag}`, JSON.stringify(state));
316
- });
317
- const lastObjStr = localStorage.getItem(`_phecda_${tag}`);
318
- if (lastObjStr && lastObjStr !== "undefined") {
319
- const lastObj = JSON.parse(lastObjStr);
320
- for (const i in lastObj)
321
- state[i] = lastObj[i];
322
- }
323
- }
324
- });
325
- }
326
- __name(Storage, "Storage");
327
287
  function Global(target) {
328
288
  if (!globalThis.__PHECDA__)
329
289
  globalThis.__PHECDA__ = {};
@@ -408,83 +368,6 @@ function addDecoToClass(c, key, handler, type = "normal") {
408
368
  }
409
369
  __name(addDecoToClass, "addDecoToClass");
410
370
 
411
- // src/preset/rule.ts
412
- function isArray(info) {
413
- return Rule((param) => Array.isArray(param), info || "it should be an array");
414
- }
415
- __name(isArray, "isArray");
416
- function isBoolean(info) {
417
- return Rule((param) => [
418
- true,
419
- false
420
- ].includes(param), info || "it should be true or false");
421
- }
422
- __name(isBoolean, "isBoolean");
423
- function isNumber(info) {
424
- return Rule((param) => typeof param === "number", info || "it should be true or false");
425
- }
426
- __name(isNumber, "isNumber");
427
- function isString(info) {
428
- return Rule((param) => typeof param === "string", info || "it should be a string");
429
- }
430
- __name(isString, "isString");
431
- function isObject2(info) {
432
- return Rule((param) => {
433
- return Object.prototype.toString.call(param) === "[object Object]";
434
- }, info || "it should be an object");
435
- }
436
- __name(isObject2, "isObject");
437
- function isMobile(info) {
438
- 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");
439
- }
440
- __name(isMobile, "isMobile");
441
- function isLandline(info) {
442
- return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || "it should be a mobile phone number");
443
- }
444
- __name(isLandline, "isLandline");
445
- function isMailBox(info) {
446
- 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");
447
- }
448
- __name(isMailBox, "isMailBox");
449
- function isIdCard(info) {
450
- 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");
451
- }
452
- __name(isIdCard, "isIdCard");
453
- function isCnName(info) {
454
- return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57");
455
- }
456
- __name(isCnName, "isCnName");
457
- function isEnName(info) {
458
- return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || "it should be a valid en-name");
459
- }
460
- __name(isEnName, "isEnName");
461
- function isDate(info) {
462
- 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");
463
- }
464
- __name(isDate, "isDate");
465
- function isWechat(info) {
466
- return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || "it should be a valid date");
467
- }
468
- __name(isWechat, "isWechat");
469
- function isHexColor(info) {
470
- return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || "it should be a valid hex-color");
471
- }
472
- __name(isHexColor, "isHexColor");
473
- function isPostalCode(info) {
474
- 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");
475
- }
476
- __name(isPostalCode, "isPostalCode");
477
-
478
- // src/preset/pipe.ts
479
- function toNumber() {
480
- return Pipe(to((param) => Number(param)));
481
- }
482
- __name(toNumber, "toNumber");
483
- function toString() {
484
- return Pipe(to((param) => String(param)));
485
- }
486
- __name(toString, "toString");
487
-
488
371
  // src/namespace.ts
489
372
  var activeInstance = {};
490
373
  function injectProperty(key, value) {
@@ -514,6 +397,41 @@ function Watcher(eventName, options) {
514
397
  };
515
398
  }
516
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");
517
435
  // Annotate the CommonJS export names for ESM import in node:
518
436
  0 && (module.exports = {
519
437
  Clear,
@@ -540,22 +458,7 @@ __name(Watcher, "Watcher");
540
458
  getTag,
541
459
  init,
542
460
  injectProperty,
543
- isArray,
544
- isBoolean,
545
- isCnName,
546
- isDate,
547
- isEnName,
548
- isHexColor,
549
- isIdCard,
550
- isLandline,
551
- isMailBox,
552
- isMobile,
553
- isNumber,
554
- isObject,
555
461
  isPhecda,
556
- isPostalCode,
557
- isString,
558
- isWechat,
559
462
  mergeOptions,
560
463
  mergeState,
561
464
  plainToClass,
@@ -568,7 +471,5 @@ __name(Watcher, "Watcher");
568
471
  setModalVar,
569
472
  snapShot,
570
473
  to,
571
- toNumber,
572
- toString,
573
474
  validate
574
475
  });