phecda-core 1.0.1 → 1.0.2

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
@@ -103,4 +103,23 @@ declare function regisHandler(target: Phecda, key: PropertyKey, handler: PhecdaH
103
103
  declare function getHandler(target: Phecda, key: PropertyKey): PhecdaHandler[];
104
104
  declare function register(instance: Phecda): void;
105
105
 
106
- export { ClassValue, Clear, Err, Get, Ignore, Init, Phecda, PhecdaHandler, PhecdaNameSpace, Pipe, Rule, Storage, Tag, UsePipeOptions, addDecoToClass, classToValue, getExposeKey, getHandler, getIgnoreKey, getInitEvent, getModelState, init, plainToClass, regisHandler, regisInitEvent, register, setExposeKey, setIgnoreKey, setModalState, snapShot, to, validate };
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
+ export { ClassValue, Clear, Err, Get, Ignore, Init, Phecda, PhecdaHandler, PhecdaNameSpace, Pipe, Rule, Storage, Tag, UsePipeOptions, addDecoToClass, classToValue, getExposeKey, getHandler, getIgnoreKey, getInitEvent, getModelState, init, isArray, isBoolean, isCnName, isDate, isEnName, isHexColor, isIdCard, isLandline, isMailBox, isMobile, isNumber, isObject, isPostalCode, isString, isWechat, plainToClass, regisHandler, regisInitEvent, register, setExposeKey, setIgnoreKey, setModalState, snapShot, to, toNumber, toString, validate };
package/dist/index.js CHANGED
@@ -37,6 +37,21 @@ __export(src_exports, {
37
37
  getInitEvent: () => getInitEvent,
38
38
  getModelState: () => getModelState,
39
39
  init: () => init,
40
+ isArray: () => isArray,
41
+ isBoolean: () => isBoolean,
42
+ isCnName: () => isCnName,
43
+ isDate: () => isDate,
44
+ isEnName: () => isEnName,
45
+ isHexColor: () => isHexColor,
46
+ isIdCard: () => isIdCard,
47
+ isLandline: () => isLandline,
48
+ isMailBox: () => isMailBox,
49
+ isMobile: () => isMobile,
50
+ isNumber: () => isNumber,
51
+ isObject: () => isObject,
52
+ isPostalCode: () => isPostalCode,
53
+ isString: () => isString,
54
+ isWechat: () => isWechat,
40
55
  plainToClass: () => plainToClass,
41
56
  regisHandler: () => regisHandler,
42
57
  regisInitEvent: () => regisInitEvent,
@@ -46,6 +61,8 @@ __export(src_exports, {
46
61
  setModalState: () => setModalState,
47
62
  snapShot: () => snapShot,
48
63
  to: () => to,
64
+ toNumber: () => toNumber,
65
+ toString: () => toString,
49
66
  validate: () => validate
50
67
  });
51
68
  module.exports = __toCommonJS(src_exports);
@@ -275,6 +292,93 @@ function snapShot(data) {
275
292
  function addDecoToClass(c, key, handler, type = "normal") {
276
293
  handler(type === "normal" ? c.prototype : c, key);
277
294
  }
295
+
296
+ // src/preset/rule.ts
297
+ function isArray(info) {
298
+ return Rule((param) => Array.isArray(param), info || "it should be an array");
299
+ }
300
+ function isBoolean(info) {
301
+ return Rule((param) => [true, false].includes(param), info || "it should be true or false");
302
+ }
303
+ function isNumber(info) {
304
+ return Rule((param) => typeof param === "number", info || "it should be true or false");
305
+ }
306
+ function isString(info) {
307
+ return Rule((param) => typeof param === "string", info || "it should be a string");
308
+ }
309
+ function isObject(info) {
310
+ return Rule((param) => {
311
+ return Object.prototype.toString.call(param) === "[object Object]";
312
+ }, info || "it should be an object");
313
+ }
314
+ function isMobile(info) {
315
+ return Rule(
316
+ /^((\+|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}$/,
317
+ info || "it should be a mobile phone number"
318
+ );
319
+ }
320
+ function isLandline(info) {
321
+ return Rule(
322
+ /\d{3}-\d{8}|\d{4}-\d{7}/,
323
+ info || "it should be a mobile phone number"
324
+ );
325
+ }
326
+ function isMailBox(info) {
327
+ return Rule(
328
+ /^[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])?)*$/,
329
+ info || "it should be a mailbox number"
330
+ );
331
+ }
332
+ function isIdCard(info) {
333
+ return Rule(
334
+ /(^\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)$)/,
335
+ info || "it should be an identity card number"
336
+ );
337
+ }
338
+ function isCnName(info) {
339
+ return Rule(
340
+ /^([\u4E00-\u9FA5·]{2,16})$/,
341
+ info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57"
342
+ );
343
+ }
344
+ function isEnName(info) {
345
+ return Rule(
346
+ /(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/,
347
+ info || "it should be a valid en-name"
348
+ );
349
+ }
350
+ function isDate(info) {
351
+ return Rule(
352
+ /^(?:(?!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)$/,
353
+ info || "it should be a valid date"
354
+ );
355
+ }
356
+ function isWechat(info) {
357
+ return Rule(
358
+ /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/,
359
+ info || "it should be a valid date"
360
+ );
361
+ }
362
+ function isHexColor(info) {
363
+ return Rule(
364
+ /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
365
+ info || "it should be a valid hex-color"
366
+ );
367
+ }
368
+ function isPostalCode(info) {
369
+ return Rule(
370
+ /^(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}$/,
371
+ info || "it should be a valid postal code"
372
+ );
373
+ }
374
+
375
+ // src/preset/pipe.ts
376
+ function toNumber() {
377
+ return Pipe(to((param) => Number(param)));
378
+ }
379
+ function toString() {
380
+ return Pipe(to((param) => String(param)));
381
+ }
278
382
  // Annotate the CommonJS export names for ESM import in node:
279
383
  0 && (module.exports = {
280
384
  Clear,
@@ -294,6 +398,21 @@ function addDecoToClass(c, key, handler, type = "normal") {
294
398
  getInitEvent,
295
399
  getModelState,
296
400
  init,
401
+ isArray,
402
+ isBoolean,
403
+ isCnName,
404
+ isDate,
405
+ isEnName,
406
+ isHexColor,
407
+ isIdCard,
408
+ isLandline,
409
+ isMailBox,
410
+ isMobile,
411
+ isNumber,
412
+ isObject,
413
+ isPostalCode,
414
+ isString,
415
+ isWechat,
297
416
  plainToClass,
298
417
  regisHandler,
299
418
  regisInitEvent,
@@ -303,5 +422,7 @@ function addDecoToClass(c, key, handler, type = "normal") {
303
422
  setModalState,
304
423
  snapShot,
305
424
  to,
425
+ toNumber,
426
+ toString,
306
427
  validate
307
428
  });
package/dist/index.mjs CHANGED
@@ -223,6 +223,93 @@ function snapShot(data) {
223
223
  function addDecoToClass(c, key, handler, type = "normal") {
224
224
  handler(type === "normal" ? c.prototype : c, key);
225
225
  }
226
+
227
+ // src/preset/rule.ts
228
+ function isArray(info) {
229
+ return Rule((param) => Array.isArray(param), info || "it should be an array");
230
+ }
231
+ function isBoolean(info) {
232
+ return Rule((param) => [true, false].includes(param), info || "it should be true or false");
233
+ }
234
+ function isNumber(info) {
235
+ return Rule((param) => typeof param === "number", info || "it should be true or false");
236
+ }
237
+ function isString(info) {
238
+ return Rule((param) => typeof param === "string", info || "it should be a string");
239
+ }
240
+ function isObject(info) {
241
+ return Rule((param) => {
242
+ return Object.prototype.toString.call(param) === "[object Object]";
243
+ }, info || "it should be an object");
244
+ }
245
+ function isMobile(info) {
246
+ return Rule(
247
+ /^((\+|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}$/,
248
+ info || "it should be a mobile phone number"
249
+ );
250
+ }
251
+ function isLandline(info) {
252
+ return Rule(
253
+ /\d{3}-\d{8}|\d{4}-\d{7}/,
254
+ info || "it should be a mobile phone number"
255
+ );
256
+ }
257
+ function isMailBox(info) {
258
+ return Rule(
259
+ /^[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])?)*$/,
260
+ info || "it should be a mailbox number"
261
+ );
262
+ }
263
+ function isIdCard(info) {
264
+ return Rule(
265
+ /(^\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)$)/,
266
+ info || "it should be an identity card number"
267
+ );
268
+ }
269
+ function isCnName(info) {
270
+ return Rule(
271
+ /^([\u4E00-\u9FA5·]{2,16})$/,
272
+ info || "\u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57"
273
+ );
274
+ }
275
+ function isEnName(info) {
276
+ return Rule(
277
+ /(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/,
278
+ info || "it should be a valid en-name"
279
+ );
280
+ }
281
+ function isDate(info) {
282
+ return Rule(
283
+ /^(?:(?!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)$/,
284
+ info || "it should be a valid date"
285
+ );
286
+ }
287
+ function isWechat(info) {
288
+ return Rule(
289
+ /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/,
290
+ info || "it should be a valid date"
291
+ );
292
+ }
293
+ function isHexColor(info) {
294
+ return Rule(
295
+ /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
296
+ info || "it should be a valid hex-color"
297
+ );
298
+ }
299
+ function isPostalCode(info) {
300
+ return Rule(
301
+ /^(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}$/,
302
+ info || "it should be a valid postal code"
303
+ );
304
+ }
305
+
306
+ // src/preset/pipe.ts
307
+ function toNumber() {
308
+ return Pipe(to((param) => Number(param)));
309
+ }
310
+ function toString() {
311
+ return Pipe(to((param) => String(param)));
312
+ }
226
313
  export {
227
314
  Clear,
228
315
  Err,
@@ -241,6 +328,21 @@ export {
241
328
  getInitEvent,
242
329
  getModelState,
243
330
  init,
331
+ isArray,
332
+ isBoolean,
333
+ isCnName,
334
+ isDate,
335
+ isEnName,
336
+ isHexColor,
337
+ isIdCard,
338
+ isLandline,
339
+ isMailBox,
340
+ isMobile,
341
+ isNumber,
342
+ isObject,
343
+ isPostalCode,
344
+ isString,
345
+ isWechat,
244
346
  plainToClass,
245
347
  regisHandler,
246
348
  regisInitEvent,
@@ -250,5 +352,7 @@ export {
250
352
  setModalState,
251
353
  snapShot,
252
354
  to,
355
+ toNumber,
356
+ toString,
253
357
  validate
254
358
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",