@mionjs/type-formats 0.8.0-alpha.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.
Files changed (134) hide show
  1. package/.dist/cjs/BigintFormats.cjs +14 -0
  2. package/.dist/cjs/BigintFormats.cjs.map +1 -0
  3. package/.dist/cjs/BigintFormats.d.ts +2 -0
  4. package/.dist/cjs/NumberFormats.cjs +20 -0
  5. package/.dist/cjs/NumberFormats.cjs.map +1 -0
  6. package/.dist/cjs/NumberFormats.d.ts +2 -0
  7. package/.dist/cjs/StringFormats.cjs +120 -0
  8. package/.dist/cjs/StringFormats.cjs.map +1 -0
  9. package/.dist/cjs/StringFormats.d.ts +11 -0
  10. package/.dist/cjs/constants.d.ts +1 -0
  11. package/.dist/cjs/package.json +1 -0
  12. package/.dist/cjs/src/bigint/bigIntFormat.runtype.cjs +152 -0
  13. package/.dist/cjs/src/bigint/bigIntFormat.runtype.cjs.map +1 -0
  14. package/.dist/cjs/src/bigint/bigIntFormat.runtype.d.ts +21 -0
  15. package/.dist/cjs/src/bigint/defaultBigNumberFormats.cjs +16 -0
  16. package/.dist/cjs/src/bigint/defaultBigNumberFormats.cjs.map +1 -0
  17. package/.dist/cjs/src/bigint/defaultBigNumberFormats.d.ts +29 -0
  18. package/.dist/cjs/src/constants.cjs +34 -0
  19. package/.dist/cjs/src/constants.cjs.map +1 -0
  20. package/.dist/cjs/src/constants.d.ts +15 -0
  21. package/.dist/cjs/src/constants.mock.cjs +111 -0
  22. package/.dist/cjs/src/constants.mock.cjs.map +1 -0
  23. package/.dist/cjs/src/constants.mock.d.ts +335 -0
  24. package/.dist/cjs/src/number/defaultNumberFormats.cjs +28 -0
  25. package/.dist/cjs/src/number/defaultNumberFormats.cjs.map +1 -0
  26. package/.dist/cjs/src/number/defaultNumberFormats.d.ts +63 -0
  27. package/.dist/cjs/src/number/numberFormat.runtype.cjs +214 -0
  28. package/.dist/cjs/src/number/numberFormat.runtype.cjs.map +1 -0
  29. package/.dist/cjs/src/number/numberFormat.runtype.d.ts +21 -0
  30. package/.dist/cjs/src/string/date.runtype.cjs +88 -0
  31. package/.dist/cjs/src/string/date.runtype.cjs.map +1 -0
  32. package/.dist/cjs/src/string/date.runtype.d.ts +19 -0
  33. package/.dist/cjs/src/string/dateTime.runtype.cjs +83 -0
  34. package/.dist/cjs/src/string/dateTime.runtype.cjs.map +1 -0
  35. package/.dist/cjs/src/string/dateTime.runtype.d.ts +26 -0
  36. package/.dist/cjs/src/string/defaultStringFormats.runtype.cjs +25 -0
  37. package/.dist/cjs/src/string/defaultStringFormats.runtype.cjs.map +1 -0
  38. package/.dist/cjs/src/string/defaultStringFormats.runtype.d.ts +45 -0
  39. package/.dist/cjs/src/string/domain.runtype.cjs +248 -0
  40. package/.dist/cjs/src/string/domain.runtype.cjs.map +1 -0
  41. package/.dist/cjs/src/string/domain.runtype.d.ts +72 -0
  42. package/.dist/cjs/src/string/email.runtype.cjs +159 -0
  43. package/.dist/cjs/src/string/email.runtype.cjs.map +1 -0
  44. package/.dist/cjs/src/string/email.runtype.d.ts +57 -0
  45. package/.dist/cjs/src/string/ip.runtype.cjs +72 -0
  46. package/.dist/cjs/src/string/ip.runtype.cjs.map +1 -0
  47. package/.dist/cjs/src/string/ip.runtype.d.ts +50 -0
  48. package/.dist/cjs/src/string/stringFormat.runtype.cjs +270 -0
  49. package/.dist/cjs/src/string/stringFormat.runtype.cjs.map +1 -0
  50. package/.dist/cjs/src/string/stringFormat.runtype.d.ts +21 -0
  51. package/.dist/cjs/src/string/time.runtype.cjs +100 -0
  52. package/.dist/cjs/src/string/time.runtype.cjs.map +1 -0
  53. package/.dist/cjs/src/string/time.runtype.d.ts +21 -0
  54. package/.dist/cjs/src/string/url.runtype.cjs +160 -0
  55. package/.dist/cjs/src/string/url.runtype.cjs.map +1 -0
  56. package/.dist/cjs/src/string/url.runtype.d.ts +81 -0
  57. package/.dist/cjs/src/string/uuid.runtype.cjs +44 -0
  58. package/.dist/cjs/src/string/uuid.runtype.cjs.map +1 -0
  59. package/.dist/cjs/src/string/uuid.runtype.d.ts +22 -0
  60. package/.dist/cjs/src/type-formats-pure-fns.cjs +390 -0
  61. package/.dist/cjs/src/type-formats-pure-fns.cjs.map +1 -0
  62. package/.dist/cjs/src/type-formats-pure-fns.d.ts +27 -0
  63. package/.dist/cjs/src/utils.cjs +14 -0
  64. package/.dist/cjs/src/utils.cjs.map +1 -0
  65. package/.dist/cjs/src/utils.d.ts +3 -0
  66. package/.dist/cjs/vitest.config.d.ts +2 -0
  67. package/.dist/esm/BigintFormats.d.ts +2 -0
  68. package/.dist/esm/BigintFormats.js +14 -0
  69. package/.dist/esm/BigintFormats.js.map +1 -0
  70. package/.dist/esm/NumberFormats.d.ts +2 -0
  71. package/.dist/esm/NumberFormats.js +20 -0
  72. package/.dist/esm/NumberFormats.js.map +1 -0
  73. package/.dist/esm/StringFormats.d.ts +11 -0
  74. package/.dist/esm/StringFormats.js +120 -0
  75. package/.dist/esm/StringFormats.js.map +1 -0
  76. package/.dist/esm/constants.d.ts +1 -0
  77. package/.dist/esm/src/bigint/bigIntFormat.runtype.d.ts +21 -0
  78. package/.dist/esm/src/bigint/bigIntFormat.runtype.js +152 -0
  79. package/.dist/esm/src/bigint/bigIntFormat.runtype.js.map +1 -0
  80. package/.dist/esm/src/bigint/defaultBigNumberFormats.d.ts +29 -0
  81. package/.dist/esm/src/bigint/defaultBigNumberFormats.js +16 -0
  82. package/.dist/esm/src/bigint/defaultBigNumberFormats.js.map +1 -0
  83. package/.dist/esm/src/constants.d.ts +15 -0
  84. package/.dist/esm/src/constants.js +34 -0
  85. package/.dist/esm/src/constants.js.map +1 -0
  86. package/.dist/esm/src/constants.mock.d.ts +335 -0
  87. package/.dist/esm/src/constants.mock.js +111 -0
  88. package/.dist/esm/src/constants.mock.js.map +1 -0
  89. package/.dist/esm/src/number/defaultNumberFormats.d.ts +63 -0
  90. package/.dist/esm/src/number/defaultNumberFormats.js +28 -0
  91. package/.dist/esm/src/number/defaultNumberFormats.js.map +1 -0
  92. package/.dist/esm/src/number/numberFormat.runtype.d.ts +21 -0
  93. package/.dist/esm/src/number/numberFormat.runtype.js +214 -0
  94. package/.dist/esm/src/number/numberFormat.runtype.js.map +1 -0
  95. package/.dist/esm/src/string/date.runtype.d.ts +19 -0
  96. package/.dist/esm/src/string/date.runtype.js +88 -0
  97. package/.dist/esm/src/string/date.runtype.js.map +1 -0
  98. package/.dist/esm/src/string/dateTime.runtype.d.ts +26 -0
  99. package/.dist/esm/src/string/dateTime.runtype.js +83 -0
  100. package/.dist/esm/src/string/dateTime.runtype.js.map +1 -0
  101. package/.dist/esm/src/string/defaultStringFormats.runtype.d.ts +45 -0
  102. package/.dist/esm/src/string/defaultStringFormats.runtype.js +25 -0
  103. package/.dist/esm/src/string/defaultStringFormats.runtype.js.map +1 -0
  104. package/.dist/esm/src/string/domain.runtype.d.ts +72 -0
  105. package/.dist/esm/src/string/domain.runtype.js +248 -0
  106. package/.dist/esm/src/string/domain.runtype.js.map +1 -0
  107. package/.dist/esm/src/string/email.runtype.d.ts +57 -0
  108. package/.dist/esm/src/string/email.runtype.js +159 -0
  109. package/.dist/esm/src/string/email.runtype.js.map +1 -0
  110. package/.dist/esm/src/string/ip.runtype.d.ts +50 -0
  111. package/.dist/esm/src/string/ip.runtype.js +72 -0
  112. package/.dist/esm/src/string/ip.runtype.js.map +1 -0
  113. package/.dist/esm/src/string/stringFormat.runtype.d.ts +21 -0
  114. package/.dist/esm/src/string/stringFormat.runtype.js +270 -0
  115. package/.dist/esm/src/string/stringFormat.runtype.js.map +1 -0
  116. package/.dist/esm/src/string/time.runtype.d.ts +21 -0
  117. package/.dist/esm/src/string/time.runtype.js +100 -0
  118. package/.dist/esm/src/string/time.runtype.js.map +1 -0
  119. package/.dist/esm/src/string/url.runtype.d.ts +81 -0
  120. package/.dist/esm/src/string/url.runtype.js +160 -0
  121. package/.dist/esm/src/string/url.runtype.js.map +1 -0
  122. package/.dist/esm/src/string/uuid.runtype.d.ts +22 -0
  123. package/.dist/esm/src/string/uuid.runtype.js +44 -0
  124. package/.dist/esm/src/string/uuid.runtype.js.map +1 -0
  125. package/.dist/esm/src/type-formats-pure-fns.d.ts +27 -0
  126. package/.dist/esm/src/type-formats-pure-fns.js +390 -0
  127. package/.dist/esm/src/type-formats-pure-fns.js.map +1 -0
  128. package/.dist/esm/src/utils.d.ts +3 -0
  129. package/.dist/esm/src/utils.js +14 -0
  130. package/.dist/esm/src/utils.js.map +1 -0
  131. package/.dist/esm/vitest.config.d.ts +2 -0
  132. package/LICENSE +21 -0
  133. package/README.md +123 -0
  134. package/package.json +80 -0
@@ -0,0 +1,390 @@
1
+ import { registerPureFnFactory } from "@mionjs/core";
2
+ const cpf_isDateString = registerPureFnFactory("mionFormats", "isDateString", function() {
3
+ return function is_date_string(year, month, day) {
4
+ let y = void 0;
5
+ if (year) {
6
+ if (year.length !== 4)
7
+ return false;
8
+ y = Number(year);
9
+ if (isNaN(y))
10
+ return false;
11
+ if (y < 0 || y > 9999)
12
+ return false;
13
+ }
14
+ if (month.length !== 2)
15
+ return false;
16
+ const m = Number(month);
17
+ if (isNaN(m))
18
+ return false;
19
+ if (m < 1 || m > 12)
20
+ return false;
21
+ if (day) {
22
+ if (day.length !== 2)
23
+ return false;
24
+ const d = Number(day);
25
+ if (isNaN(d))
26
+ return false;
27
+ if (d < 1 || d > 31)
28
+ return false;
29
+ if (m === 2) {
30
+ if (d > 29)
31
+ return false;
32
+ if (y && d === 29 && !(y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0)))
33
+ return false;
34
+ } else if ((m === 4 || m === 6 || m === 9 || m === 11) && d > 30) {
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ };
40
+ }, { bodyHash: "1_oB_gADdf9PX4", paramNames: [], code: "return function is_date_string(year, month, day) {\n let y = void 0;\n if (year) {\n if (year.length !== 4) return false;\n y = Number(year);\n if (isNaN(y)) return false;\n if (y < 0 || y > 9999) return false;\n }\n if (month.length !== 2) return false;\n const m = Number(month);\n if (isNaN(m)) return false;\n if (m < 1 || m > 12) return false;\n if (day) {\n if (day.length !== 2) return false;\n const d = Number(day);\n if (isNaN(d)) return false;\n if (d < 1 || d > 31) return false;\n if (m === 2) {\n if (d > 29) return false;\n if (y && d === 29 && !(y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0))) return false;\n } else if ((m === 4 || m === 6 || m === 9 || m === 11) && d > 30) {\n return false;\n }\n }\n return true;\n };" });
41
+ const cpf_isDateString_YMD = registerPureFnFactory("mionFormats", "isDateString_YMD", function(jUtil) {
42
+ const isDate = jUtil.getPureFn("mionFormats", "isDateString");
43
+ return function is_date(value) {
44
+ const parts = value.split("-");
45
+ return parts.length === 3 && isDate(parts[0], parts[1], parts[2]);
46
+ };
47
+ }, { bodyHash: "TgdYN25ps-eNtS", paramNames: ["jUtil"], code: 'const isDate = jUtil.getPureFn("mionFormats", "isDateString");\n return function is_date(value) {\n const parts = value.split("-");\n return parts.length === 3 && isDate(parts[0], parts[1], parts[2]);\n };' });
48
+ const cpf_isDateString_DMY = registerPureFnFactory("mionFormats", "isDateString_DMY", function(jUtil) {
49
+ const isDate = jUtil.getPureFn("mionFormats", "isDateString");
50
+ return function is_date(value) {
51
+ const parts = value.split("-");
52
+ return parts.length === 3 && isDate(parts[2], parts[1], parts[0]);
53
+ };
54
+ }, { bodyHash: "aVDMyOqrsrbcbW", paramNames: ["jUtil"], code: 'const isDate = jUtil.getPureFn("mionFormats", "isDateString");\n return function is_date(value) {\n const parts = value.split("-");\n return parts.length === 3 && isDate(parts[2], parts[1], parts[0]);\n };' });
55
+ const cpf_isDateString_MDY = registerPureFnFactory("mionFormats", "isDateString_MDY", function(jUtil) {
56
+ const isDate = jUtil.getPureFn("mionFormats", "isDateString");
57
+ return function is_date(value) {
58
+ const parts = value.split("-");
59
+ return parts.length === 3 && isDate(parts[2], parts[0], parts[1]);
60
+ };
61
+ }, { bodyHash: "iM5EqlmgeDmVjF", paramNames: ["jUtil"], code: 'const isDate = jUtil.getPureFn("mionFormats", "isDateString");\n return function is_date(value) {\n const parts = value.split("-");\n return parts.length === 3 && isDate(parts[2], parts[0], parts[1]);\n };' });
62
+ const cpf_isDateString_YM = registerPureFnFactory("mionFormats", "isDateString_YM", function(jUtil) {
63
+ const isDate = jUtil.getPureFn("mionFormats", "isDateString");
64
+ return function is_date(value) {
65
+ const parts = value.split("-");
66
+ return parts.length === 2 && isDate(parts[0], parts[1]);
67
+ };
68
+ }, { bodyHash: "aYQTJv_F4JU3nI", paramNames: ["jUtil"], code: 'const isDate = jUtil.getPureFn("mionFormats", "isDateString");\n return function is_date(value) {\n const parts = value.split("-");\n return parts.length === 2 && isDate(parts[0], parts[1]);\n };' });
69
+ const cpf_isDateString_MD = registerPureFnFactory("mionFormats", "isDateString_MD", function(jUtil) {
70
+ const isDate = jUtil.getPureFn("mionFormats", "isDateString");
71
+ return function is_date(value) {
72
+ const parts = value.split("-");
73
+ return parts.length === 2 && isDate(void 0, parts[0], parts[1]);
74
+ };
75
+ }, { bodyHash: "NVGldNTml6x6cv", paramNames: ["jUtil"], code: 'const isDate = jUtil.getPureFn("mionFormats", "isDateString");\n return function is_date(value) {\n const parts = value.split("-");\n return parts.length === 2 && isDate(void 0, parts[0], parts[1]);\n };' });
76
+ const cpf_isDateString_DM = registerPureFnFactory("mionFormats", "isDateString_DM", function(jUtil) {
77
+ const isDate = jUtil.getPureFn("mionFormats", "isDateString");
78
+ return function is_date(value) {
79
+ const parts = value.split("-");
80
+ return parts.length === 2 && isDate(void 0, parts[1], parts[0]);
81
+ };
82
+ }, { bodyHash: "ItACHY5Jvp_3sG", paramNames: ["jUtil"], code: 'const isDate = jUtil.getPureFn("mionFormats", "isDateString");\n return function is_date(value) {\n const parts = value.split("-");\n return parts.length === 2 && isDate(void 0, parts[1], parts[0]);\n };' });
83
+ const dateFunctions = [
84
+ cpf_isDateString,
85
+ cpf_isDateString_YMD,
86
+ cpf_isDateString_DMY,
87
+ cpf_isDateString_MDY,
88
+ cpf_isDateString_YM,
89
+ cpf_isDateString_MD,
90
+ cpf_isDateString_DM
91
+ ];
92
+ const cpf_isTimeZone = registerPureFnFactory("mionFormats", "isTimeZone", function(jUtil) {
93
+ const isH = jUtil.getPureFn("mionFormats", "isHours");
94
+ const isM = jUtil.getPureFn("mionFormats", "isMinutes");
95
+ return function is_tz(timeZone) {
96
+ const isZ = timeZone === "Z" || timeZone === "z";
97
+ if (isZ)
98
+ return true;
99
+ const tzParts = timeZone.split(":");
100
+ if (tzParts.length !== 2)
101
+ return false;
102
+ const hours = tzParts[0];
103
+ const minutes = tzParts[1];
104
+ return isH(hours) && isM(minutes);
105
+ };
106
+ }, { bodyHash: "0Zcw0D7iktjrgz", paramNames: ["jUtil"], code: 'const isH = jUtil.getPureFn("mionFormats", "isHours");\n const isM = jUtil.getPureFn("mionFormats", "isMinutes");\n return function is_tz(timeZone) {\n const isZ = timeZone === "Z" || timeZone === "z";\n if (isZ) return true;\n const tzParts = timeZone.split(":");\n if (tzParts.length !== 2) return false;\n const hours = tzParts[0];\n const minutes = tzParts[1];\n return isH(hours) && isM(minutes);\n };' });
107
+ const cpf_isHours = registerPureFnFactory("mionFormats", "isHours", function() {
108
+ return function is_h(hours) {
109
+ if (!hours.length || hours.length > 2)
110
+ return false;
111
+ const numberHours = Number(hours);
112
+ if (isNaN(numberHours))
113
+ return false;
114
+ return numberHours >= 0 && numberHours <= 23;
115
+ };
116
+ }, { bodyHash: "wsGHZIT8eblMfW", paramNames: [], code: "return function is_h(hours) {\n if (!hours.length || hours.length > 2) return false;\n const numberHours = Number(hours);\n if (isNaN(numberHours)) return false;\n return numberHours >= 0 && numberHours <= 23;\n };" });
117
+ const cpf_isMinutes = registerPureFnFactory("mionFormats", "isMinutes", function() {
118
+ return function is_m(mins) {
119
+ if (!mins.length || mins.length > 2)
120
+ return false;
121
+ const numberMinutes = Number(mins);
122
+ if (isNaN(numberMinutes))
123
+ return false;
124
+ return numberMinutes >= 0 && numberMinutes <= 59;
125
+ };
126
+ }, { bodyHash: "KEMDuHWSc4_Cv1", paramNames: [], code: "return function is_m(mins) {\n if (!mins.length || mins.length > 2) return false;\n const numberMinutes = Number(mins);\n if (isNaN(numberMinutes)) return false;\n return numberMinutes >= 0 && numberMinutes <= 59;\n };" });
127
+ const cpf_isSeconds = registerPureFnFactory("mionFormats", "isSeconds", function() {
128
+ return function is_s(secs) {
129
+ if (!secs.length || secs.length > 2)
130
+ return false;
131
+ const numberSeconds = Number(secs);
132
+ if (isNaN(numberSeconds))
133
+ return false;
134
+ return numberSeconds >= 0 && numberSeconds <= 59;
135
+ };
136
+ }, { bodyHash: "nq28WUDHB__8hY", paramNames: [], code: "return function is_s(secs) {\n if (!secs.length || secs.length > 2) return false;\n const numberSeconds = Number(secs);\n if (isNaN(numberSeconds)) return false;\n return numberSeconds >= 0 && numberSeconds <= 59;\n };" });
137
+ const cpf_isSecondsWithMs = registerPureFnFactory("mionFormats", "isSecondsWithMs", function(jUtil) {
138
+ const isS = jUtil.getPureFn("mionFormats", "isSeconds");
139
+ return function is_s_ms(secsAnsMls) {
140
+ const parts = secsAnsMls.split(".");
141
+ if (parts.length > 2)
142
+ return false;
143
+ const secs = parts[0];
144
+ if (!isS(secs))
145
+ return false;
146
+ const mls = parts[1];
147
+ if (mls) {
148
+ if (mls.length !== 3)
149
+ return false;
150
+ const millisNumber = Number(mls);
151
+ if (isNaN(millisNumber))
152
+ return false;
153
+ if (millisNumber < 0 || millisNumber > 999)
154
+ return false;
155
+ }
156
+ return true;
157
+ };
158
+ }, { bodyHash: "w-3AxO5Z-3h_a6", paramNames: ["jUtil"], code: 'const isS = jUtil.getPureFn("mionFormats", "isSeconds");\n return function is_s_ms(secsAnsMls) {\n const parts = secsAnsMls.split(".");\n if (parts.length > 2) return false;\n const secs = parts[0];\n if (!isS(secs)) return false;\n const mls = parts[1];\n if (mls) {\n if (mls.length !== 3) return false;\n const millisNumber = Number(mls);\n if (isNaN(millisNumber)) return false;\n if (millisNumber < 0 || millisNumber > 999) return false;\n }\n return true;\n };' });
159
+ const cpf_isTimeString_ISO_TZ = registerPureFnFactory("mionFormats", "isTimeString_ISO_TZ", function(jUtil) {
160
+ const isTWms = jUtil.getPureFn("mionFormats", "isTimeString_ISO");
161
+ const isTZ = jUtil.getPureFn("mionFormats", "isTimeZone");
162
+ return function is_iso_time(value) {
163
+ const isZ = value.endsWith("Z") || value.endsWith("z");
164
+ const isPositiveTZ = isZ || value.indexOf("+") !== -1;
165
+ const isNegativeTZ = isZ || value.indexOf("-") !== -1;
166
+ if (!isZ && !isPositiveTZ && !isNegativeTZ)
167
+ return false;
168
+ const timeAndTz = isZ ? [value.substring(0, value.length - 1), "Z"] : value.split(isPositiveTZ ? "+" : "-");
169
+ if (timeAndTz.length !== 2)
170
+ return false;
171
+ const time = timeAndTz[0];
172
+ const tz = timeAndTz[1];
173
+ return isTWms(time) && isTZ(tz);
174
+ };
175
+ }, { bodyHash: "NCB_K_7BF-8PZQ", paramNames: ["jUtil"], code: 'const isTWms = jUtil.getPureFn("mionFormats", "isTimeString_ISO");\n const isTZ = jUtil.getPureFn("mionFormats", "isTimeZone");\n return function is_iso_time(value) {\n const isZ = value.endsWith("Z") || value.endsWith("z");\n const isPositiveTZ = isZ || value.indexOf("+") !== -1;\n const isNegativeTZ = isZ || value.indexOf("-") !== -1;\n if (!isZ && !isPositiveTZ && !isNegativeTZ) return false;\n const timeAndTz = isZ ? [value.substring(0, value.length - 1), "Z"] : value.split(isPositiveTZ ? "+" : "-");\n if (timeAndTz.length !== 2) return false;\n const time = timeAndTz[0];\n const tz = timeAndTz[1];\n return isTWms(time) && isTZ(tz);\n };' });
176
+ const cpf_isTimeString_ISO = registerPureFnFactory("mionFormats", "isTimeString_ISO", function(jUtil) {
177
+ const isH = jUtil.getPureFn("mionFormats", "isHours");
178
+ const isM = jUtil.getPureFn("mionFormats", "isMinutes");
179
+ const isSWithMls = jUtil.getPureFn("mionFormats", "isSecondsWithMs");
180
+ return function is_iso_time(value) {
181
+ const parts = value.split(":");
182
+ return parts.length === 3 && isH(parts[0]) && isM(parts[1]) && isSWithMls(parts[2]);
183
+ };
184
+ }, { bodyHash: "joUIF3KmQA7Aws", paramNames: ["jUtil"], code: 'const isH = jUtil.getPureFn("mionFormats", "isHours");\n const isM = jUtil.getPureFn("mionFormats", "isMinutes");\n const isSWithMls = jUtil.getPureFn("mionFormats", "isSecondsWithMs");\n return function is_iso_time(value) {\n const parts = value.split(":");\n return parts.length === 3 && isH(parts[0]) && isM(parts[1]) && isSWithMls(parts[2]);\n };' });
185
+ const cpf_isTimeString_HHmmss = registerPureFnFactory("mionFormats", "isTimeString_HHmmss", function(jUtil) {
186
+ const isH = jUtil.getPureFn("mionFormats", "isHours");
187
+ const isM = jUtil.getPureFn("mionFormats", "isMinutes");
188
+ const isS = jUtil.getPureFn("mionFormats", "isSeconds");
189
+ return function is_iso_time(value) {
190
+ const parts = value.split(":");
191
+ return parts.length === 3 && isH(parts[0]) && isM(parts[1]) && isS(parts[2]);
192
+ };
193
+ }, { bodyHash: "QU-R606PNQuAQE", paramNames: ["jUtil"], code: 'const isH = jUtil.getPureFn("mionFormats", "isHours");\n const isM = jUtil.getPureFn("mionFormats", "isMinutes");\n const isS = jUtil.getPureFn("mionFormats", "isSeconds");\n return function is_iso_time(value) {\n const parts = value.split(":");\n return parts.length === 3 && isH(parts[0]) && isM(parts[1]) && isS(parts[2]);\n };' });
194
+ const cpf_isTimeString_HHmm = registerPureFnFactory("mionFormats", "isTimeString_HHmm", function(jUtil) {
195
+ const isH = jUtil.getPureFn("mionFormats", "isHours");
196
+ const isM = jUtil.getPureFn("mionFormats", "isMinutes");
197
+ return function is_iso_time(value) {
198
+ const parts = value.split(":");
199
+ return parts.length === 2 && isH(parts[0]) && isM(parts[1]);
200
+ };
201
+ }, { bodyHash: "wK8lBvI2O4XQ09", paramNames: ["jUtil"], code: 'const isH = jUtil.getPureFn("mionFormats", "isHours");\n const isM = jUtil.getPureFn("mionFormats", "isMinutes");\n return function is_iso_time(value) {\n const parts = value.split(":");\n return parts.length === 2 && isH(parts[0]) && isM(parts[1]);\n };' });
202
+ const cpf_isTimeString_mmss = registerPureFnFactory("mionFormats", "isTimeString_mmss", function(jUtil) {
203
+ const isM = jUtil.getPureFn("mionFormats", "isMinutes");
204
+ const isS = jUtil.getPureFn("mionFormats", "isSeconds");
205
+ return function is_iso_time(value) {
206
+ const parts = value.split(":");
207
+ return parts.length === 2 && isM(parts[0]) && isS(parts[1]);
208
+ };
209
+ }, { bodyHash: "HBjntCm7aZu5JG", paramNames: ["jUtil"], code: 'const isM = jUtil.getPureFn("mionFormats", "isMinutes");\n const isS = jUtil.getPureFn("mionFormats", "isSeconds");\n return function is_iso_time(value) {\n const parts = value.split(":");\n return parts.length === 2 && isM(parts[0]) && isS(parts[1]);\n };' });
210
+ const pureTimeFns = [cpf_isTimeZone, cpf_isHours, cpf_isMinutes, cpf_isSeconds, cpf_isSecondsWithMs];
211
+ const timeFunctions = [
212
+ cpf_isTimeString_ISO_TZ,
213
+ cpf_isTimeString_ISO,
214
+ cpf_isTimeString_HHmmss,
215
+ cpf_isTimeString_HHmm,
216
+ cpf_isTimeString_mmss
217
+ ];
218
+ const cpf_isUUID = registerPureFnFactory("mionFormats", "isUUID", function() {
219
+ return function is_uuid(value, p) {
220
+ if (value.length !== 36)
221
+ return false;
222
+ for (let i = 0; i < 36; i++) {
223
+ if (i === 8 || i === 13 || i === 18 || i === 23) {
224
+ if (value[i] !== "-")
225
+ return false;
226
+ } else if (i === 14) {
227
+ if (value[i] !== p.version)
228
+ return false;
229
+ } else {
230
+ const charCode = value.charCodeAt(i);
231
+ const is09 = charCode >= 48 && charCode <= 57;
232
+ const isaf = charCode >= 97 && charCode <= 102;
233
+ const isAF = charCode >= 65 && charCode <= 70;
234
+ if (!(is09 || isaf || isAF))
235
+ return false;
236
+ }
237
+ }
238
+ return true;
239
+ };
240
+ }, { bodyHash: "32EsOFrtBtCSbQ", paramNames: [], code: 'return function is_uuid(value, p) {\n if (value.length !== 36) return false;\n for (let i = 0; i < 36; i++) {\n if (i === 8 || i === 13 || i === 18 || i === 23) {\n if (value[i] !== "-") return false;\n } else if (i === 14) {\n if (value[i] !== p.version) return false;\n } else {\n const charCode = value.charCodeAt(i);\n const is09 = charCode >= 48 && charCode <= 57;\n const isaf = charCode >= 97 && charCode <= 102;\n const isAF = charCode >= 65 && charCode <= 70;\n if (!(is09 || isaf || isAF)) return false;\n }\n }\n return true;\n };' });
241
+ const cpf_isLocalHost = registerPureFnFactory("mionFormats", "isLocalHost", function() {
242
+ const lhr = /^localhost$/i;
243
+ return function is_local_host(ip, p) {
244
+ if (p.version === 4)
245
+ return lhr.test(ip) || ip === "127:0:0:1";
246
+ if (p.version === 6)
247
+ return ip === "::1" || ip === "0:0:0:0:0:0:0:1";
248
+ return lhr.test(ip) || ip === "127:0:0:1" || ip === "::1" || ip === "0:0:0:0:0:0:0:1";
249
+ };
250
+ }, { bodyHash: "ik5yJC7tT_L6xO", paramNames: [], code: 'const lhr = /^localhost$/i;\n return function is_local_host(ip, p) {\n if (p.version === 4) return lhr.test(ip) || ip === "127:0:0:1";\n if (p.version === 6) return ip === "::1" || ip === "0:0:0:0:0:0:0:1";\n return lhr.test(ip) || ip === "127:0:0:1" || ip === "::1" || ip === "0:0:0:0:0:0:0:1";\n };' });
251
+ const cpf_isIPV4 = registerPureFnFactory("mionFormats", "isIPV4", function(utl) {
252
+ const is_Localhost = utl.getPureFn("mionFormats", "isLocalHost");
253
+ function get_address(ip, p) {
254
+ if (!p.allowPort)
255
+ return ip;
256
+ const parts = ip.split(":");
257
+ if (parts.length > 2)
258
+ return false;
259
+ const [address, portS] = parts;
260
+ if (!portS)
261
+ return address;
262
+ const port = Number(portS);
263
+ if (isNaN(port) || port < 0 || port > 65535)
264
+ return false;
265
+ return address;
266
+ }
267
+ return function is_ip_v4(ip, p) {
268
+ const address = get_address(ip, p);
269
+ if (address === false)
270
+ return false;
271
+ const isLocal = is_Localhost(address, p);
272
+ if (p.allowLocalHost && isLocal)
273
+ return true;
274
+ if (!p.allowLocalHost && isLocal)
275
+ return false;
276
+ const sections = address.split(".");
277
+ if (sections.length !== 4)
278
+ return false;
279
+ for (const section of sections) {
280
+ const num = Number(section);
281
+ if (isNaN(num) || num < 0 || num > 255)
282
+ return false;
283
+ }
284
+ return true;
285
+ };
286
+ }, { bodyHash: "DL89ezU80jTaqc", paramNames: ["utl"], code: 'const is_Localhost = utl.getPureFn("mionFormats", "isLocalHost");\n function get_address(ip, p) {\n if (!p.allowPort) return ip;\n const parts = ip.split(":");\n if (parts.length > 2) return false;\n const [address, portS] = parts;\n if (!portS) return address;\n const port = Number(portS);\n if (isNaN(port) || port < 0 || port > 65535) return false;\n return address;\n }\n return function is_ip_v4(ip, p) {\n const address = get_address(ip, p);\n if (address === false) return false;\n const isLocal = is_Localhost(address, p);\n if (p.allowLocalHost && isLocal) return true;\n if (!p.allowLocalHost && isLocal) return false;\n const sections = address.split(".");\n if (sections.length !== 4) return false;\n for (const section of sections) {\n const num = Number(section);\n if (isNaN(num) || num < 0 || num > 255) return false;\n }\n return true;\n };' });
287
+ const cpf_isIPV6 = registerPureFnFactory("mionFormats", "isIPV6", function(utl) {
288
+ const is_Localhost = utl.getPureFn("mionFormats", "isLocalHost");
289
+ const ipv6PortRegexp = /^\[([^\]]+)\](?::(\d+))?$/;
290
+ function get_address(ip, p) {
291
+ if (!p.allowPort)
292
+ return ip;
293
+ const match = ip.match(ipv6PortRegexp);
294
+ if (!match)
295
+ return false;
296
+ const address = match[1];
297
+ const port = match[2];
298
+ if (!port)
299
+ return address;
300
+ const num = Number(port);
301
+ if (isNaN(num) || num < 0 || num > 65535)
302
+ return false;
303
+ return address;
304
+ }
305
+ return function is_ip_v6(ip, p) {
306
+ const address = get_address(ip, p);
307
+ if (address === false)
308
+ return false;
309
+ const isLocal = is_Localhost(address, p);
310
+ if (p.allowLocalHost && isLocal)
311
+ return true;
312
+ if (!p.allowLocalHost && isLocal)
313
+ return false;
314
+ const sections = address.split(":");
315
+ if (sections.length < 3 || sections.length > 8)
316
+ return false;
317
+ let doubleColon = 0;
318
+ for (const section of sections) {
319
+ if (section.length === 0) {
320
+ doubleColon++;
321
+ if (doubleColon > 1)
322
+ return false;
323
+ continue;
324
+ }
325
+ if (section.length > 4)
326
+ return false;
327
+ const num = parseInt(section, 16);
328
+ if (isNaN(num) || num < 0 || num > 65535)
329
+ return false;
330
+ }
331
+ return true;
332
+ };
333
+ }, { bodyHash: "SL4Gk3IId9J6aa", paramNames: ["utl"], code: 'const is_Localhost = utl.getPureFn("mionFormats", "isLocalHost");\n const ipv6PortRegexp = /^\\[([^\\]]+)\\](?::(\\d+))?$/;\n function get_address(ip, p) {\n if (!p.allowPort) return ip;\n const match = ip.match(ipv6PortRegexp);\n if (!match) return false;\n const address = match[1];\n const port = match[2];\n if (!port) return address;\n const num = Number(port);\n if (isNaN(num) || num < 0 || num > 65535) return false;\n return address;\n }\n return function is_ip_v6(ip, p) {\n const address = get_address(ip, p);\n if (address === false) return false;\n const isLocal = is_Localhost(address, p);\n if (p.allowLocalHost && isLocal) return true;\n if (!p.allowLocalHost && isLocal) return false;\n const sections = address.split(":");\n if (sections.length < 3 || sections.length > 8) return false;\n let doubleColon = 0;\n for (const section of sections) {\n if (section.length === 0) {\n doubleColon++;\n if (doubleColon > 1) return false;\n continue;\n }\n if (section.length > 4) return false;\n const num = parseInt(section, 16);\n if (isNaN(num) || num < 0 || num > 65535) return false;\n }\n return true;\n };' });
334
+ const cpf_mionGetIPErrors = registerPureFnFactory("mionFormats", "mionGetIPErrors", function(utl) {
335
+ const is_ip_v4 = utl.getPureFn("mionFormats", "isIPV4");
336
+ const is_ip_v6 = utl.getPureFn("mionFormats", "isIPV6");
337
+ const noopDeps = {};
338
+ return function get_ip_errors(ip, p, fPath, fErrs, name = "ip") {
339
+ if (p.version === 4 && !is_ip_v4(ip, p, noopDeps))
340
+ return fErrs.push({ name, formatPath: [...fPath, "version"], val: 4 }), fErrs;
341
+ if (p.version === 6 && !is_ip_v6(ip, p, noopDeps))
342
+ return fErrs.push({ name, formatPath: [...fPath, "version"], val: 6 }), fErrs;
343
+ const isIP = is_ip_v4(ip, p, noopDeps) || is_ip_v6(ip, p, noopDeps);
344
+ if (!isIP)
345
+ fErrs.push({ name, formatPath: ["version"], val: "any" });
346
+ return fErrs;
347
+ };
348
+ }, { bodyHash: "DqM0k2QRxqOTpQ", paramNames: ["utl"], code: 'const is_ip_v4 = utl.getPureFn("mionFormats", "isIPV4");\n const is_ip_v6 = utl.getPureFn("mionFormats", "isIPV6");\n const noopDeps = {};\n return function get_ip_errors(ip, p, fPath, fErrs, name = "ip") {\n if (p.version === 4 && !is_ip_v4(ip, p, noopDeps))\n return fErrs.push({ name, formatPath: [...fPath, "version"], val: 4 }), fErrs;\n if (p.version === 6 && !is_ip_v6(ip, p, noopDeps))\n return fErrs.push({ name, formatPath: [...fPath, "version"], val: 6 }), fErrs;\n const isIP = is_ip_v4(ip, p, noopDeps) || is_ip_v6(ip, p, noopDeps);\n if (!isIP) fErrs.push({ name, formatPath: ["version"], val: "any" });\n return fErrs;\n };' });
349
+ const ipFunctions = [cpf_isLocalHost, cpf_isIPV4, cpf_isIPV6, cpf_mionGetIPErrors];
350
+ const mionFormatsPureFunctions = [
351
+ // Date functions
352
+ ...dateFunctions,
353
+ // Time functions
354
+ ...pureTimeFns,
355
+ ...timeFunctions,
356
+ // UUID functions
357
+ cpf_isUUID,
358
+ // IP functions
359
+ ...ipFunctions
360
+ ];
361
+ export {
362
+ cpf_isDateString,
363
+ cpf_isDateString_DM,
364
+ cpf_isDateString_DMY,
365
+ cpf_isDateString_MD,
366
+ cpf_isDateString_MDY,
367
+ cpf_isDateString_YM,
368
+ cpf_isDateString_YMD,
369
+ cpf_isHours,
370
+ cpf_isIPV4,
371
+ cpf_isIPV6,
372
+ cpf_isLocalHost,
373
+ cpf_isMinutes,
374
+ cpf_isSeconds,
375
+ cpf_isSecondsWithMs,
376
+ cpf_isTimeString_HHmm,
377
+ cpf_isTimeString_HHmmss,
378
+ cpf_isTimeString_ISO,
379
+ cpf_isTimeString_ISO_TZ,
380
+ cpf_isTimeString_mmss,
381
+ cpf_isTimeZone,
382
+ cpf_isUUID,
383
+ cpf_mionGetIPErrors,
384
+ dateFunctions,
385
+ ipFunctions,
386
+ mionFormatsPureFunctions,
387
+ pureTimeFns,
388
+ timeFunctions
389
+ };
390
+ //# sourceMappingURL=type-formats-pure-fns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-formats-pure-fns.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ import { FormatParam, FormatParamLiteral } from '@mionjs/core';
2
+ export declare function paramVal<L extends FormatParamLiteral>(p: FormatParam<L>): L;
3
+ export declare function regexpEscape(val: string): string;
@@ -0,0 +1,14 @@
1
+ import { isFormatParamMeta } from "@mionjs/run-types";
2
+ function paramVal(p) {
3
+ return isFormatParamMeta(p) ? p.val : p;
4
+ }
5
+ paramVal.__type = ["FormatParam", "p", "paramVal", 'P"w!2""/#'];
6
+ function regexpEscape(val) {
7
+ return val.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
8
+ }
9
+ regexpEscape.__type = ["val", "regexpEscape", 'P&2!&/"'];
10
+ export {
11
+ paramVal,
12
+ regexpEscape
13
+ };
14
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vite').UserConfig;
2
+ export default _default;
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mion
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/MionKit/mion/master/assets/public/bannerx90-dark.png">
4
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/MionKit/mion/master/assets/public/bannerx90.png">
5
+ <img alt='mion, a mikro kit for Typescript Serverless APIs' src='https://raw.githubusercontent.com/MionKit/mion/master/assets/public/bannerx90.png'>
6
+ </picture>
7
+ </p>
8
+ <p align="center">
9
+ <strong>mion standard middleFns and routes.
10
+ </strong>
11
+ </p>
12
+ <p align=center>
13
+ <img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square&maxAge=99999999" alt="npm" style="max-width:100%;">
14
+ <img src="https://img.shields.io/badge/license-MIT-97ca00.svg?style=flat-square&maxAge=99999999" alt="npm" style="max-width:100%;">
15
+ </p>
16
+
17
+ # `@mionjs/type-formats`
18
+
19
+ `@mionjs/type-formats` provides runtype functionality such as validation and serialization based on TypeScript types. Unlike libraries like Zod or AJV-formats, which use JavaScript to declare schemas, `@mionjs/type-formats` directly leverages TypeScript types and extracts information at compile time to generate validation and serialization functions.
20
+
21
+ You can find examples of how to use these formats in the various spec files under the `string` directory.
22
+
23
+ > **âš¡ Fast**:
24
+ > The validation and serialization functions generated by `@mionjs/type-formats` are JIT (Just-In-Time) compiled, ensuring they are highly optimized for performance. This makes them suitable for use in high-throughput applications where efficiency is critical.
25
+
26
+ ## Available Formats
27
+
28
+ Below is a list of available formats parsed from the spec files:
29
+
30
+ ### String Formats
31
+
32
+ - **Base String Format**
33
+ - `StringFormat`: The base format for all string-related validations and transformations. It provides a set of customizable parameters that can be reused to create any custom string format. Below are the available parameters:
34
+ - **Validators**:
35
+ - `maxLength`: Maximum length of the string.
36
+ - `minLength`: Minimum length of the string.
37
+ - `length`: Exact length of the string.
38
+ - `allowedChars`: A string containing characters allowed in the string.
39
+ - `disallowedChars`: A string containing characters not allowed in the string.
40
+ - `allowedValues`: An array of allowed string values.
41
+ - `disallowedValues`: An array of disallowed string values.
42
+ - `pattern`: A regular expression pattern with an optional message and sample values.
43
+
44
+ - **Transformers**:
45
+ - `lowercase`: Converts the string to lowercase.
46
+ - `uppercase`: Converts the string to uppercase.
47
+ - `capitalize`: Capitalizes the first letter of the string.
48
+ - `trim`: Removes whitespace from both ends of the string.
49
+ - `replace`: Replaces the first occurrence of a substring with another value.
50
+ - `replaceAll`: Replaces all occurrences of a substring with another value.
51
+
52
+ - **UUID Formats**
53
+ - `UUID_V4`: Validates UUID version 4.
54
+ - `UUID_V7`: Validates UUID version 7.
55
+
56
+ - **Time Formats**
57
+ - `TimeString`: Supports formats like `ISO`, `HH:mm:ss[.mmm]TZ`, `HH:mm:ss`, `HH:mm`, `mm:ss`, `HH`, `mm`, `ss`.
58
+
59
+ - **Date Formats**
60
+ - `DateString`: Supports formats like `ISO`, `YYYY-MM-DD`, `DD-MM-YYYY`, `MM-DD-YYYY`, `MM-DD`, `DD-MM`, `YYYY-MM`.
61
+
62
+ - **DateTime Formats**
63
+ - `DateTimeString`: Combines date and time formats in a customizable way. Most common format is ISO, i.e., `YYYY-MM-DDTHH:mm:ssTZ`.
64
+
65
+ - **String Validation Formats**
66
+ - `AlphaString`: Validates strings containing only alphabetic characters.
67
+ - `AlphaNumericString`: Validates strings containing only alphanumeric characters.
68
+ - `NumericString`: Validates strings containing only numeric characters.
69
+ - `LowerString`: Validates strings in lowercase.
70
+ - `UpperString`: Validates strings in uppercase.
71
+ - `CapitalString`: Validates strings with the first letter capitalized.
72
+
73
+ - **Domain Formats**
74
+ - `Domain`: Validates domain names with customizable parameters for subdomains, TLDs, and length.
75
+
76
+ - **Email Formats**
77
+ - `Email`: Validates email addresses with customizable parameters for local parts and domains.
78
+
79
+ - **IP Formats**
80
+ - `IP`: Validates IP addresses (IPv4, IPv6, or both) with options for localhost and port inclusion.
81
+
82
+ - **URL Formats**
83
+ - `URL`: Validates URLs with customizable parameters for protocols, length, and allowed/disallowed characters.
84
+
85
+ ## Example Usage
86
+
87
+ ### Using `DateTimeString` Format with `isType`
88
+
89
+ The `DateTimeString` format allows you to validate date-time strings with customizable date and time formats. Below is an example of how to use it with the `isType` function:
90
+
91
+ ```typescript
92
+ import {isTypeFn} from '@mionjs/run-types';
93
+ import {DateTimeString} from '@mionjs/type-formats';
94
+
95
+ // Customizing DateTimeString to include only year, month, and time (HH:mm:ss)
96
+ type CustomDateTimeString = DateTimeString<{date: {format: 'YYYY-MM'}; time: {format: 'HH:mm:ss'}; splitChar: '/'}>;
97
+
98
+ const isIsoDateTime = await isTypeFn<DateTimeString>();
99
+
100
+ // Example usage for default ISO DateTimeString
101
+ console.log(await isIsoDateTime('2024-01-01T12:30:45Z')); // true
102
+ console.log(await isIsoDateTime('2024-01-01T12:30:45')); // true
103
+ console.log(await isIsoDateTime('2024-01-01 12:30:45')); // false (missing 'T' separator)
104
+ console.log(await isIsoDateTime('2024-13-01T12:30:45Z')); // false (invalid month 13)
105
+
106
+ const isCustomDateTime = await isTypeFn<CustomDateTimeString>();
107
+
108
+ // Example usage for custom DateTimeString
109
+ console.log(isCustomDateTime('2024-01/12:30:45')); // true
110
+ console.log(isCustomDateTime('2024-01T12:30:45')); // false (wrong split char T instead of the custom /)
111
+ console.log(isCustomDateTime('2024-01-01/12:30:45')); // false (day is not allowed)
112
+ console.log(isCustomDateTime('2024-13/12:30:45')); // false (invalid month 13)
113
+ ```
114
+
115
+ This example demonstrates how to validate both default ISO date-time strings and a custom date-time string format.
116
+
117
+ ## Check Out The [Website And Documentation](http://mion.io) 📚
118
+
119
+ [![mion-website-banner](https://raw.githubusercontent.com/MionKit/mion/master/assets/public/mion-website-banner.png)](http://mion.io)
120
+
121
+ ---
122
+
123
+ [MIT LICENSE](../../LICENSE)
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@mionjs/type-formats",
3
+ "version": "0.8.0-alpha.0",
4
+ "type": "module",
5
+ "description": "mion standard middleFns and routes",
6
+ "keywords": [
7
+ "typescript",
8
+ "API",
9
+ "RPC",
10
+ "json",
11
+ "schema",
12
+ "generate",
13
+ "server",
14
+ "serverless",
15
+ "framework",
16
+ "node",
17
+ "runtime types"
18
+ ],
19
+ "author": "ma jerez",
20
+ "homepage": "https://mion.io/",
21
+ "license": "MIT",
22
+ "browser": {},
23
+ "exports": {
24
+ "./NumberFormats": {
25
+ "source": "./NumberFormats.ts",
26
+ "types": "./.dist/esm/NumberFormats.d.ts",
27
+ "require": "./.dist/cjs/NumberFormats.cjs",
28
+ "default": "./.dist/esm/NumberFormats.js"
29
+ },
30
+ "./StringFormats": {
31
+ "source": "./StringFormats.ts",
32
+ "types": "./.dist/esm/StringFormats.d.ts",
33
+ "require": "./.dist/cjs/StringFormats.cjs",
34
+ "default": "./.dist/esm/StringFormats.js"
35
+ },
36
+ "./BigintFormats": {
37
+ "source": "./BigintFormats.ts",
38
+ "types": "./.dist/esm/BigintFormats.d.ts",
39
+ "require": "./.dist/cjs/BigintFormats.cjs",
40
+ "default": "./.dist/esm/BigintFormats.js"
41
+ },
42
+ "./constants": {
43
+ "source": "./constants.ts",
44
+ "types": "./.dist/esm/src/constants.d.ts",
45
+ "require": "./.dist/cjs/src/constants.cjs",
46
+ "default": "./.dist/esm/src/constants.js"
47
+ }
48
+ },
49
+ "directories": {
50
+ "lib": ".dist"
51
+ },
52
+ "files": [
53
+ ".dist"
54
+ ],
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "git+https://github.com/MionKit/mion.git"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "scripts": {
63
+ "test": "vitest run",
64
+ "dev": "vite build --watch",
65
+ "dev:test": "vitest watch",
66
+ "lint": "npx eslint src",
67
+ "format": "prettier --write src/**/*.ts",
68
+ "build": "vite build",
69
+ "clean": "rimraf .dist & rimraf .coverage",
70
+ "fresh-start": "npm run clean && rimraf node_modules"
71
+ },
72
+ "bugs": {
73
+ "url": "https://github.com/MionKit/mion/issues"
74
+ },
75
+ "dependencies": {
76
+ "@mionjs/core": "^0.8.0-alpha.0",
77
+ "@mionjs/run-types": "^0.8.0-alpha.0"
78
+ },
79
+ "gitHead": "5d2ec524ba39d040338ce8946d8edf78aa7291a3"
80
+ }