@keysdown/form-wrapper 1.0.5 → 2.0.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.
Files changed (65) hide show
  1. package/README.md +335 -31
  2. package/dist/form-wrapper.cjs +1 -1
  3. package/dist/form-wrapper.js +114 -28
  4. package/dist/form-wrapper.umd.cjs +1 -1
  5. package/dist/plugins/formValidation.cjs +1 -0
  6. package/dist/plugins/formValidation.d.ts +4 -0
  7. package/dist/plugins/formValidation.js +7 -0
  8. package/dist/plugins/locales.cjs +1 -0
  9. package/dist/plugins/locales.d.ts +2 -0
  10. package/dist/plugins/locales.js +115 -0
  11. package/dist/plugins/rules.cjs +1 -0
  12. package/dist/plugins/rules.d.ts +2 -0
  13. package/dist/plugins/rules.js +2 -0
  14. package/dist/rules-BIt-pifQ.cjs +1 -0
  15. package/dist/rules-DZmnRoUy.js +196 -0
  16. package/dist/src/core/Errors.d.ts +1 -1
  17. package/dist/src/core/Form.d.ts +11 -0
  18. package/dist/src/plugins/formValidation.d.ts +3 -0
  19. package/dist/src/plugins/locales/en.d.ts +3 -0
  20. package/dist/src/plugins/locales/es.d.ts +3 -0
  21. package/dist/src/plugins/locales/index.d.ts +3 -0
  22. package/dist/src/plugins/locales/pt.d.ts +3 -0
  23. package/dist/src/plugins/rules/alpha.d.ts +2 -0
  24. package/dist/src/plugins/rules/alphaNumeric.d.ts +2 -0
  25. package/dist/src/plugins/rules/array.d.ts +2 -0
  26. package/dist/src/plugins/rules/between.d.ts +2 -0
  27. package/dist/src/plugins/rules/boolean.d.ts +2 -0
  28. package/dist/src/plugins/rules/confirmed.d.ts +2 -0
  29. package/dist/src/plugins/rules/date.d.ts +2 -0
  30. package/dist/src/plugins/rules/different.d.ts +2 -0
  31. package/dist/src/plugins/rules/digits.d.ts +2 -0
  32. package/dist/src/plugins/rules/digitsBetween.d.ts +2 -0
  33. package/dist/src/plugins/rules/email.d.ts +2 -0
  34. package/dist/src/plugins/rules/endsWith.d.ts +2 -0
  35. package/dist/src/plugins/rules/greaterThan.d.ts +2 -0
  36. package/dist/src/plugins/rules/greaterThanOrEqual.d.ts +2 -0
  37. package/dist/src/plugins/rules/in.d.ts +2 -0
  38. package/dist/src/plugins/rules/index.d.ts +35 -0
  39. package/dist/src/plugins/rules/integer.d.ts +2 -0
  40. package/dist/src/plugins/rules/ip.d.ts +2 -0
  41. package/dist/src/plugins/rules/json.d.ts +2 -0
  42. package/dist/src/plugins/rules/lessThan.d.ts +2 -0
  43. package/dist/src/plugins/rules/lessThanOrEqual.d.ts +2 -0
  44. package/dist/src/plugins/rules/max.d.ts +2 -0
  45. package/dist/src/plugins/rules/min.d.ts +2 -0
  46. package/dist/src/plugins/rules/notIn.d.ts +2 -0
  47. package/dist/src/plugins/rules/nullable.d.ts +2 -0
  48. package/dist/src/plugins/rules/numeric.d.ts +2 -0
  49. package/dist/src/plugins/rules/regex.d.ts +2 -0
  50. package/dist/src/plugins/rules/required.d.ts +2 -0
  51. package/dist/src/plugins/rules/same.d.ts +2 -0
  52. package/dist/src/plugins/rules/size.d.ts +2 -0
  53. package/dist/src/plugins/rules/startsWith.d.ts +2 -0
  54. package/dist/src/plugins/rules/string.d.ts +2 -0
  55. package/dist/src/plugins/rules/url.d.ts +2 -0
  56. package/dist/src/plugins/rules/uuid.d.ts +2 -0
  57. package/dist/src/types/fields.d.ts +1 -0
  58. package/dist/src/types/locale.d.ts +7 -0
  59. package/dist/src/types/plugin.d.ts +2 -0
  60. package/dist/src/types/rules.d.ts +7 -1
  61. package/dist/src/types/validations.d.ts +3 -2
  62. package/dist/src/utils/rule.d.ts +2 -0
  63. package/package.json +17 -2
  64. package/dist/form-wrapper.iife.js +0 -1
  65. package/dist/src/utils/validations.d.ts +0 -3
@@ -1,5 +1,32 @@
1
1
  //#region src/utils/fields.ts
2
- var e = (e) => typeof e == "string" ? e.split("|") : e, t = (t) => ({
2
+ var e = (e) => {
3
+ if (typeof e == "string") {
4
+ let t = [], n = e;
5
+ for (; n.length > 0;) {
6
+ let e = n.indexOf("regex:");
7
+ if (e !== -1) {
8
+ let r = n.substring(0, e);
9
+ r && t.push(...r.split("|").filter(Boolean));
10
+ let i = n.substring(e), a = i.indexOf(":/");
11
+ if (a !== -1) {
12
+ let e = a + 1, r = i.lastIndexOf("/");
13
+ if (r > e) {
14
+ let e = i.substring(r + 1), a = e.match(/^[gimsuy]*/)[0], o = i.substring(0, r + 1 + a.length);
15
+ t.push(o), n = e.substring(a.length), n.startsWith("|") && (n = n.substring(1));
16
+ continue;
17
+ }
18
+ }
19
+ t.push(i);
20
+ break;
21
+ } else {
22
+ t.push(...n.split("|").filter(Boolean));
23
+ break;
24
+ }
25
+ }
26
+ return t;
27
+ }
28
+ return e;
29
+ }, t = (t) => ({
3
30
  validation: {
4
31
  rules: t.validation?.rules ? e(t.validation.rules) : [],
5
32
  messages: t.validation?.messages ?? {}
@@ -12,9 +39,9 @@ var e = (e) => typeof e == "string" ? e.split("|") : e, t = (t) => ({
12
39
  }
13
40
  first(e) {
14
41
  let t = this.get(e);
15
- if (t) {
42
+ if (t !== null) {
16
43
  let e = Array.isArray(t) ? t[0] : t;
17
- if (e) return String(e);
44
+ if (e != null) return String(e);
18
45
  }
19
46
  return null;
20
47
  }
@@ -57,32 +84,45 @@ var e = (e) => typeof e == "string" ? e.split("|") : e, t = (t) => ({
57
84
  errors = new a();
58
85
  messages = new r();
59
86
  rules = new i();
60
- }, s = { required: (e) => new Promise((t, n) => {
61
- if (e == null) return n();
62
- String(e).replace(/\s/g, "").length > 0 ? t(e) : n();
63
- }) }, c = (e) => typeof e == "object" && !!e && !Array.isArray(e), l = (e, t, n = null) => {
87
+ }, s = (e) => typeof e == "object" && !!e && !Array.isArray(e), c = (e, t, n = null) => {
64
88
  let r = t || new FormData();
65
89
  return Object.keys(e).forEach((t) => {
66
90
  let i = e[t];
67
91
  if (t = n ? `${n}[${t}]` : t, !([void 0, null].indexOf(i) > -1)) {
68
- if (c(i) && !(i instanceof File) || Array.isArray(i)) {
69
- l(i, r, t);
92
+ if (s(i) && !(i instanceof File) || Array.isArray(i)) {
93
+ c(i, r, t);
70
94
  return;
71
95
  }
72
96
  r.append(t, i);
73
97
  }
74
98
  }), r;
75
- }, u = class {
99
+ }, l = class e {
100
+ static rules = {};
101
+ static defaultMessages = {};
102
+ static interpolateMessage(e, t, n, r) {
103
+ let i = r[t] || t.replace(/_/g, " ");
104
+ return e.replace(/:field/g, i).replace(/:min/g, n[0] || "").replace(/:max/g, n[1] || "").replace(/:size/g, n[0] || "").replace(/:digits/g, n[0] || "").replace(/:other/g, n[0] ? r[n[0]] || n[0].replace(/_/g, " ") : "").replace(/:values/g, n.join(", "));
105
+ }
76
106
  awaiting = !1;
77
107
  originalValues = {};
108
+ fieldAttributes = {};
78
109
  validation = new o();
79
110
  constructor(e) {
80
111
  this.addFields(e);
81
112
  }
113
+ static extend(t) {
114
+ return t(e, e.rules), e;
115
+ }
116
+ static addRule(t, n) {
117
+ return e.rules[t] = Object.assign(n, { ruleName: t }), e;
118
+ }
119
+ static locale(t) {
120
+ return e.defaultMessages = t.messages, e;
121
+ }
82
122
  addField(e, n) {
83
123
  if (typeof n == "object" && n && Object.prototype.toString.call(n) === "[object Object]" && "value" in n) {
84
124
  let r = t(n);
85
- this[e] = r.value, this.originalValues[e] = r.value, this.validation.messages.push(e, r.validation.messages), this.validation.rules.push(e, r.validation.rules);
125
+ this[e] = r.value, this.originalValues[e] = r.value, this.validation.messages.push(e, r.validation.messages), this.validation.rules.push(e, r.validation.rules), n.attribute && (this.fieldAttributes[e] = n.attribute);
86
126
  } else this[e] = n, this.originalValues[e] = n;
87
127
  return this;
88
128
  }
@@ -97,14 +137,14 @@ var e = (e) => typeof e == "string" ? e.split("|") : e, t = (t) => ({
97
137
  fill(e, t = !1) {
98
138
  return Object.keys(e).forEach((n) => {
99
139
  let r = e[n];
100
- t && (this.originalValues[n] = r), this[n] = r;
140
+ t && (this.originalValues[n] = r), this[n] = r, n in this.originalValues || (this.originalValues[n] = r);
101
141
  }), this;
102
142
  }
103
143
  get messages() {
104
144
  return this.validation.messages;
105
145
  }
106
146
  removeField(e) {
107
- return delete this[e], delete this.originalValues[e], this.validation.errors.unset(e), this.validation.messages.unset(e), this.validation.rules.unset(e), this;
147
+ return delete this[e], delete this.originalValues[e], delete this.fieldAttributes[e], this.validation.errors.unset(e), this.validation.messages.unset(e), this.validation.rules.unset(e), this;
108
148
  }
109
149
  removeFields(e) {
110
150
  return e.forEach((e) => {
@@ -131,18 +171,58 @@ var e = (e) => typeof e == "string" ? e.split("|") : e, t = (t) => ({
131
171
  validate(e = null) {
132
172
  return e ? this.validateField(e) : this.validateForm();
133
173
  }
134
- validateField(e) {
135
- this.validation.errors.unset(e);
136
- let t = this.validation.rules.get(e);
137
- if (t && t.length > 0) {
138
- let n = t.map((t) => {
139
- let n = t.split(":"), r = n[0], i = n.length === 2 ? n[1].split(",") : [];
140
- return r in s ? s[r](this[e], i).catch((t) => {
141
- let n = this.validation.messages.get(e);
142
- return n && r in n && this.validation.errors.push(e, n[r]), Promise.reject(t);
143
- }) : Promise.reject(/* @__PURE__ */ Error(`There is no validation rule called "${r}"`));
144
- });
145
- return Promise.all(n).then(() => {});
174
+ validateField(t) {
175
+ this.validation.errors.unset(t);
176
+ let n = this.validation.rules.get(t);
177
+ if (n && n.length > 0) {
178
+ let r = this.constructor.rules;
179
+ return (async () => {
180
+ for (let i of n) {
181
+ let n = i;
182
+ if (typeof n == "function") {
183
+ if ("ruleName" in n) {
184
+ let r = n.ruleName;
185
+ if (r === "nullable" && (this[t] === null || this[t] === void 0 || this[t] === "")) return;
186
+ try {
187
+ await n(this[t], [], this, t);
188
+ } catch (n) {
189
+ let i = this.validation.messages.get(t);
190
+ throw r && i && r in i ? this.validation.errors.push(t, i[r]) : r in e.defaultMessages && this.validation.errors.push(t, e.interpolateMessage(e.defaultMessages[r], t, [], this.fieldAttributes)), n;
191
+ }
192
+ } else await new Promise((e, r) => {
193
+ let i = !1, a = (e) => {
194
+ i = !0, e && this.validation.errors.push(t, e);
195
+ };
196
+ try {
197
+ let o = n({
198
+ value: this[t],
199
+ fail: a,
200
+ form: this,
201
+ field: t
202
+ });
203
+ o instanceof Promise ? o.then(() => {
204
+ i ? r() : e();
205
+ }).catch(() => {
206
+ r();
207
+ }) : i ? r() : e();
208
+ } catch {
209
+ r();
210
+ }
211
+ });
212
+ continue;
213
+ }
214
+ let a = n.indexOf(":"), o = a === -1 ? n : n.substring(0, a);
215
+ if (o === "nullable" && (this[t] === null || this[t] === void 0 || this[t] === "")) return;
216
+ let s = a === -1 ? [] : n.substring(a + 1).split(",");
217
+ if (o in r) try {
218
+ await r[o](this[t], s, this, t);
219
+ } catch (n) {
220
+ let r = this.validation.messages.get(t);
221
+ throw r && o in r ? this.validation.errors.push(t, r[o]) : o in e.defaultMessages && this.validation.errors.push(t, e.interpolateMessage(e.defaultMessages[o], t, s, this.fieldAttributes)), n;
222
+ }
223
+ else throw Error(`There is no validation rule called "${o}"`);
224
+ }
225
+ })();
146
226
  }
147
227
  return Promise.resolve();
148
228
  }
@@ -156,9 +236,15 @@ var e = (e) => typeof e == "string" ? e.split("|") : e, t = (t) => ({
156
236
  (!e || e.includes(n)) && (t[n] = this[n]);
157
237
  }), t;
158
238
  }
239
+ filledValues(e) {
240
+ let t = {};
241
+ return Object.keys(this.originalValues).forEach((n) => {
242
+ (!e || e.includes(n)) && this[n] != null && (t[n] = this[n]);
243
+ }), t;
244
+ }
159
245
  valuesAsFormData(e) {
160
- return l(this.values(e));
246
+ return c(this.values(e));
161
247
  }
162
- }, d = (e) => new u(e), f = u;
248
+ }, u = (e) => new l(e), d = l;
163
249
  //#endregion
164
- export { d as createForm, f as default };
250
+ export { u as createForm, d as default };
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.FormWrapper={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=e=>typeof e==`string`?e.split(`|`):e,n=e=>({validation:{rules:e.validation?.rules?t(e.validation.rules):[],messages:e.validation?.messages??{}},value:e.value??null}),r=class{collection={};all(){return this.collection}first(e){let t=this.get(e);if(t){let e=Array.isArray(t)?t[0]:t;if(e)return String(e)}return null}any(){return Object.keys(this.collection).length>0}fill(e){return this.collection=e,this}push(e,t){return this.collection={...this.collection,[e]:t},this}has(e){return Array.isArray(e)?e.some(e=>this.collection.hasOwnProperty(e)):this.collection.hasOwnProperty(e)}get(e,t=null){return this.has(e)?this.collection[e]:t}unset(e){return this.has(e)&&delete this.collection[e],this}clear(){return this.collection={},this}},i=class extends r{},a=class extends r{},o=class extends r{push(e,t){let n=this.get(e)||[];return this.collection={...this.collection,[e]:[...n,t]},this}get(e){return super.get(e,[])}},s=class{errors=new o;messages=new i;rules=new a},c={required:e=>new Promise((t,n)=>{if(e==null)return n();String(e).replace(/\s/g,``).length>0?t(e):n()})},l=e=>typeof e==`object`&&!!e&&!Array.isArray(e),u=(e,t,n=null)=>{let r=t||new FormData;return Object.keys(e).forEach(t=>{let i=e[t];if(t=n?`${n}[${t}]`:t,!([void 0,null].indexOf(i)>-1)){if(l(i)&&!(i instanceof File)||Array.isArray(i)){u(i,r,t);return}r.append(t,i)}}),r},d=class{awaiting=!1;originalValues={};validation=new s;constructor(e){this.addFields(e)}addField(e,t){if(typeof t==`object`&&t&&Object.prototype.toString.call(t)===`[object Object]`&&`value`in t){let r=n(t);this[e]=r.value,this.originalValues[e]=r.value,this.validation.messages.push(e,r.validation.messages),this.validation.rules.push(e,r.validation.rules)}else this[e]=t,this.originalValues[e]=t;return this}addFields(e){return Object.keys(e).forEach(t=>{this.addField(t,e[t])}),this}get errors(){return this.validation.errors}fill(e,t=!1){return Object.keys(e).forEach(n=>{let r=e[n];t&&(this.originalValues[n]=r),this[n]=r}),this}get messages(){return this.validation.messages}removeField(e){return delete this[e],delete this.originalValues[e],this.validation.errors.unset(e),this.validation.messages.unset(e),this.validation.rules.unset(e),this}removeFields(e){return e.forEach(e=>{this.removeField(e)}),this}reset(){return this.validation.errors.clear(),Object.keys(this.originalValues).forEach(e=>{this[e]=this.originalValues[e]}),this}wasChanged(e){return Array.isArray(e)?e.some(e=>this[e]!==this.originalValues[e]):this[e]!==this.originalValues[e]}filled(e){return Array.isArray(e)?e.every(e=>this[e]!==null&&this[e]!==void 0&&this[e]!==``):this[e]!==null&&this[e]!==void 0&&this[e]!==``}get rules(){return this.validation.rules}setAwaiting(e=!0){return this.awaiting=e,this}validate(e=null){return e?this.validateField(e):this.validateForm()}validateField(e){this.validation.errors.unset(e);let t=this.validation.rules.get(e);if(t&&t.length>0){let n=t.map(t=>{let n=t.split(`:`),r=n[0],i=n.length===2?n[1].split(`,`):[];return r in c?c[r](this[e],i).catch(t=>{let n=this.validation.messages.get(e);return n&&r in n&&this.validation.errors.push(e,n[r]),Promise.reject(t)}):Promise.reject(Error(`There is no validation rule called "${r}"`))});return Promise.all(n).then(()=>{})}return Promise.resolve()}validateForm(){let e=Object.keys(this.originalValues).map(e=>this.validateField(e));return Promise.all(e).then(()=>Promise.resolve(this)).catch(()=>Promise.reject(this))}values(e){let t={};return Object.keys(this.originalValues).forEach(n=>{(!e||e.includes(n))&&(t[n]=this[n])}),t}valuesAsFormData(e){return u(this.values(e))}},f=e=>new d(e),p=d;e.createForm=f,e.default=p});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.FormWrapper={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=e=>{if(typeof e==`string`){let t=[],n=e;for(;n.length>0;){let e=n.indexOf(`regex:`);if(e!==-1){let r=n.substring(0,e);r&&t.push(...r.split(`|`).filter(Boolean));let i=n.substring(e),a=i.indexOf(`:/`);if(a!==-1){let e=a+1,r=i.lastIndexOf(`/`);if(r>e){let e=i.substring(r+1),a=e.match(/^[gimsuy]*/)[0],o=i.substring(0,r+1+a.length);t.push(o),n=e.substring(a.length),n.startsWith(`|`)&&(n=n.substring(1));continue}}t.push(i);break}else{t.push(...n.split(`|`).filter(Boolean));break}}return t}return e},n=e=>({validation:{rules:e.validation?.rules?t(e.validation.rules):[],messages:e.validation?.messages??{}},value:e.value??null}),r=class{collection={};all(){return this.collection}first(e){let t=this.get(e);if(t!==null){let e=Array.isArray(t)?t[0]:t;if(e!=null)return String(e)}return null}any(){return Object.keys(this.collection).length>0}fill(e){return this.collection=e,this}push(e,t){return this.collection={...this.collection,[e]:t},this}has(e){return Array.isArray(e)?e.some(e=>this.collection.hasOwnProperty(e)):this.collection.hasOwnProperty(e)}get(e,t=null){return this.has(e)?this.collection[e]:t}unset(e){return this.has(e)&&delete this.collection[e],this}clear(){return this.collection={},this}},i=class extends r{},a=class extends r{},o=class extends r{push(e,t){let n=this.get(e)||[];return this.collection={...this.collection,[e]:[...n,t]},this}get(e){return super.get(e,[])}},s=class{errors=new o;messages=new i;rules=new a},c=e=>typeof e==`object`&&!!e&&!Array.isArray(e),l=(e,t,n=null)=>{let r=t||new FormData;return Object.keys(e).forEach(t=>{let i=e[t];if(t=n?`${n}[${t}]`:t,!([void 0,null].indexOf(i)>-1)){if(c(i)&&!(i instanceof File)||Array.isArray(i)){l(i,r,t);return}r.append(t,i)}}),r},u=class e{static rules={};static defaultMessages={};static interpolateMessage(e,t,n,r){let i=r[t]||t.replace(/_/g,` `);return e.replace(/:field/g,i).replace(/:min/g,n[0]||``).replace(/:max/g,n[1]||``).replace(/:size/g,n[0]||``).replace(/:digits/g,n[0]||``).replace(/:other/g,n[0]?r[n[0]]||n[0].replace(/_/g,` `):``).replace(/:values/g,n.join(`, `))}awaiting=!1;originalValues={};fieldAttributes={};validation=new s;constructor(e){this.addFields(e)}static extend(t){return t(e,e.rules),e}static addRule(t,n){return e.rules[t]=Object.assign(n,{ruleName:t}),e}static locale(t){return e.defaultMessages=t.messages,e}addField(e,t){if(typeof t==`object`&&t&&Object.prototype.toString.call(t)===`[object Object]`&&`value`in t){let r=n(t);this[e]=r.value,this.originalValues[e]=r.value,this.validation.messages.push(e,r.validation.messages),this.validation.rules.push(e,r.validation.rules),t.attribute&&(this.fieldAttributes[e]=t.attribute)}else this[e]=t,this.originalValues[e]=t;return this}addFields(e){return Object.keys(e).forEach(t=>{this.addField(t,e[t])}),this}get errors(){return this.validation.errors}fill(e,t=!1){return Object.keys(e).forEach(n=>{let r=e[n];t&&(this.originalValues[n]=r),this[n]=r,n in this.originalValues||(this.originalValues[n]=r)}),this}get messages(){return this.validation.messages}removeField(e){return delete this[e],delete this.originalValues[e],delete this.fieldAttributes[e],this.validation.errors.unset(e),this.validation.messages.unset(e),this.validation.rules.unset(e),this}removeFields(e){return e.forEach(e=>{this.removeField(e)}),this}reset(){return this.validation.errors.clear(),Object.keys(this.originalValues).forEach(e=>{this[e]=this.originalValues[e]}),this}wasChanged(e){return Array.isArray(e)?e.some(e=>this[e]!==this.originalValues[e]):this[e]!==this.originalValues[e]}filled(e){return Array.isArray(e)?e.every(e=>this[e]!==null&&this[e]!==void 0&&this[e]!==``):this[e]!==null&&this[e]!==void 0&&this[e]!==``}get rules(){return this.validation.rules}setAwaiting(e=!0){return this.awaiting=e,this}validate(e=null){return e?this.validateField(e):this.validateForm()}validateField(t){this.validation.errors.unset(t);let n=this.validation.rules.get(t);if(n&&n.length>0){let r=this.constructor.rules;return(async()=>{for(let i of n){let n=i;if(typeof n==`function`){if(`ruleName`in n){let r=n.ruleName;if(r===`nullable`&&(this[t]===null||this[t]===void 0||this[t]===``))return;try{await n(this[t],[],this,t)}catch(n){let i=this.validation.messages.get(t);throw r&&i&&r in i?this.validation.errors.push(t,i[r]):r in e.defaultMessages&&this.validation.errors.push(t,e.interpolateMessage(e.defaultMessages[r],t,[],this.fieldAttributes)),n}}else await new Promise((e,r)=>{let i=!1,a=e=>{i=!0,e&&this.validation.errors.push(t,e)};try{let o=n({value:this[t],fail:a,form:this,field:t});o instanceof Promise?o.then(()=>{i?r():e()}).catch(()=>{r()}):i?r():e()}catch{r()}});continue}let a=n.indexOf(`:`),o=a===-1?n:n.substring(0,a);if(o===`nullable`&&(this[t]===null||this[t]===void 0||this[t]===``))return;let s=a===-1?[]:n.substring(a+1).split(`,`);if(o in r)try{await r[o](this[t],s,this,t)}catch(n){let r=this.validation.messages.get(t);throw r&&o in r?this.validation.errors.push(t,r[o]):o in e.defaultMessages&&this.validation.errors.push(t,e.interpolateMessage(e.defaultMessages[o],t,s,this.fieldAttributes)),n}else throw Error(`There is no validation rule called "${o}"`)}})()}return Promise.resolve()}validateForm(){let e=Object.keys(this.originalValues).map(e=>this.validateField(e));return Promise.all(e).then(()=>Promise.resolve(this)).catch(()=>Promise.reject(this))}values(e){let t={};return Object.keys(this.originalValues).forEach(n=>{(!e||e.includes(n))&&(t[n]=this[n])}),t}filledValues(e){let t={};return Object.keys(this.originalValues).forEach(n=>{(!e||e.includes(n))&&this[n]!=null&&(t[n]=this[n])}),t}valuesAsFormData(e){return l(this.values(e))}},d=e=>new u(e),f=u;e.createForm=d,e.default=f});
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../rules-BIt-pifQ.cjs`);var t=(t,n)=>{Object.assign(n,e.t)};exports.default=t;
@@ -0,0 +1,4 @@
1
+ export {}
2
+ import _default from '../src/plugins/formValidation'
3
+ export default _default
4
+ export {}
@@ -0,0 +1,7 @@
1
+ import { t as e } from "../rules-DZmnRoUy.js";
2
+ //#region src/plugins/formValidation.ts
3
+ var t = (t, n) => {
4
+ Object.assign(n, e);
5
+ };
6
+ //#endregion
7
+ export { t as default };
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e={name:`en`,messages:{required:`The :field field is required.`,email:`The :field must be a valid email address.`,url:`The :field must be a valid URL.`,min:`The :field must be at least :min.`,max:`The :field may not be greater than :max.`,between:`The :field must be between :min and :max.`,size:`The :field must be :size.`,alpha:`The :field may only contain letters.`,alphaNumeric:`The :field may only contain letters and numbers.`,string:`The :field must be a string.`,integer:`The :field must be an integer.`,numeric:`The :field must be a number.`,array:`The :field must be an array.`,boolean:`The :field field must be true or false.`,date:`The :field is not a valid date.`,same:`The :field and :other must match.`,different:`The :field and :other must be different.`,confirmed:`The :field confirmation does not match.`,in:`The selected :field is invalid.`,notIn:`The selected :field is invalid.`,regex:`The :field format is invalid.`,startsWith:`The :field must start with one of the following: :values.`,endsWith:`The :field must end with one of the following: :values.`,digits:`The :field must be :digits digits.`,digitsBetween:`The :field must be between :min and :max digits.`,ip:`The :field must be a valid IP address.`,json:`The :field must be a valid JSON string.`,uuid:`The :field must be a valid UUID.`,lessThan:`The :field must be less than :other.`,greaterThan:`The :field must be greater than :other.`,lessThanOrEqual:`The :field must be less than or equal to :other.`,greaterThanOrEqual:`The :field must be greater than or equal to :other.`,nullable:`The :field must be nullable.`}},t={name:`pt`,messages:{required:`O campo :field é obrigatório.`,email:`O campo :field deve ser um endereço de email válido.`,url:`O campo :field deve ser uma URL válida.`,min:`O campo :field deve ter no mínimo :min.`,max:`O campo :field não deve ser maior que :max.`,between:`O campo :field deve estar entre :min e :max.`,size:`O campo :field deve ter :size.`,alpha:`O campo :field deve conter apenas letras.`,alphaNumeric:`O campo :field deve conter apenas letras e números.`,string:`O campo :field deve ser uma string.`,integer:`O campo :field deve ser um número inteiro.`,numeric:`O campo :field deve ser um número.`,array:`O campo :field deve ser um array.`,boolean:`O campo :field deve ser verdadeiro ou falso.`,date:`O campo :field não é uma data válida.`,same:`O campo :field e :other devem ser iguais.`,different:`O campo :field e :other devem ser diferentes.`,confirmed:`A confirmação do campo :field não corresponde.`,in:`O campo :field selecionado é inválido.`,notIn:`O campo :field selecionado é inválido.`,regex:`O formato do campo :field é inválido.`,startsWith:`O campo :field deve começar com um dos seguintes valores: :values.`,endsWith:`O campo :field deve terminar com um dos seguintes valores: :values.`,digits:`O campo :field deve ter :digits dígitos.`,digitsBetween:`O campo :field deve ter entre :min e :max dígitos.`,ip:`O campo :field deve ser um endereço de IP válido.`,json:`O campo :field deve ser uma string JSON válida.`,uuid:`O campo :field deve ser um UUID válido.`,lessThan:`O campo :field deve ser menor que :other.`,greaterThan:`O campo :field deve ser maior que :other.`,lessThanOrEqual:`O campo :field deve ser menor ou igual a :other.`,greaterThanOrEqual:`O campo :field deve ser maior ou igual a :other.`,nullable:`O campo :field deve ser nulo.`}},n={name:`es`,messages:{required:`El campo :field es obligatorio.`,email:`El campo :field debe ser una dirección de correo electrónico válida.`,url:`El campo :field debe ser una URL válida.`,min:`El campo :field debe tener al menos :min.`,max:`El campo :field no debe ser mayor que :max.`,between:`El campo :field debe estar entre :min y :max.`,size:`El campo :field debe tener :size.`,alpha:`El campo :field solo debe contener letras.`,alphaNumeric:`El campo :field solo debe contener letras y números.`,string:`El campo :field debe ser una cadena de texto.`,integer:`El campo :field debe ser un número entero.`,numeric:`El campo :field debe ser un número.`,array:`El campo :field debe ser un array.`,boolean:`El campo :field debe ser verdadero o falso.`,date:`El campo :field no es una fecha válida.`,same:`El campo :field y :other deben coincidir.`,different:`El campo :field y :other deben ser diferentes.`,confirmed:`La confirmación del campo :field no coincide.`,in:`El campo :field seleccionado no es válido.`,notIn:`El campo :field seleccionado no es válido.`,regex:`El formato del campo :field no es válido.`,startsWith:`El campo :field debe comenzar con uno de los siguientes valores: :values.`,endsWith:`El campo :field debe terminar con uno de los siguientes valores: :values.`,digits:`El campo :field debe tener :digits dígitos.`,digitsBetween:`El campo :field debe tener entre :min y :max dígitos.`,ip:`El campo :field debe ser una dirección IP válida.`,json:`El campo :field debe ser una cadena JSON válida.`,uuid:`El campo :field debe ser un UUID válido.`,lessThan:`El campo :field debe ser menor que :other.`,greaterThan:`El campo :field debe ser mayor que :other.`,lessThanOrEqual:`El campo :field debe ser menor o igual que :other.`,greaterThanOrEqual:`El campo :field debe ser mayor o igual que :other.`,nullable:`El campo :field debe ser nulo.`}};exports.en=e,exports.es=n,exports.pt=t;
@@ -0,0 +1,2 @@
1
+ export * from '../src/plugins/locales/index'
2
+ export {}
@@ -0,0 +1,115 @@
1
+ //#region src/plugins/locales/en.ts
2
+ var e = {
3
+ name: "en",
4
+ messages: {
5
+ required: "The :field field is required.",
6
+ email: "The :field must be a valid email address.",
7
+ url: "The :field must be a valid URL.",
8
+ min: "The :field must be at least :min.",
9
+ max: "The :field may not be greater than :max.",
10
+ between: "The :field must be between :min and :max.",
11
+ size: "The :field must be :size.",
12
+ alpha: "The :field may only contain letters.",
13
+ alphaNumeric: "The :field may only contain letters and numbers.",
14
+ string: "The :field must be a string.",
15
+ integer: "The :field must be an integer.",
16
+ numeric: "The :field must be a number.",
17
+ array: "The :field must be an array.",
18
+ boolean: "The :field field must be true or false.",
19
+ date: "The :field is not a valid date.",
20
+ same: "The :field and :other must match.",
21
+ different: "The :field and :other must be different.",
22
+ confirmed: "The :field confirmation does not match.",
23
+ in: "The selected :field is invalid.",
24
+ notIn: "The selected :field is invalid.",
25
+ regex: "The :field format is invalid.",
26
+ startsWith: "The :field must start with one of the following: :values.",
27
+ endsWith: "The :field must end with one of the following: :values.",
28
+ digits: "The :field must be :digits digits.",
29
+ digitsBetween: "The :field must be between :min and :max digits.",
30
+ ip: "The :field must be a valid IP address.",
31
+ json: "The :field must be a valid JSON string.",
32
+ uuid: "The :field must be a valid UUID.",
33
+ lessThan: "The :field must be less than :other.",
34
+ greaterThan: "The :field must be greater than :other.",
35
+ lessThanOrEqual: "The :field must be less than or equal to :other.",
36
+ greaterThanOrEqual: "The :field must be greater than or equal to :other.",
37
+ nullable: "The :field must be nullable."
38
+ }
39
+ }, t = {
40
+ name: "pt",
41
+ messages: {
42
+ required: "O campo :field é obrigatório.",
43
+ email: "O campo :field deve ser um endereço de email válido.",
44
+ url: "O campo :field deve ser uma URL válida.",
45
+ min: "O campo :field deve ter no mínimo :min.",
46
+ max: "O campo :field não deve ser maior que :max.",
47
+ between: "O campo :field deve estar entre :min e :max.",
48
+ size: "O campo :field deve ter :size.",
49
+ alpha: "O campo :field deve conter apenas letras.",
50
+ alphaNumeric: "O campo :field deve conter apenas letras e números.",
51
+ string: "O campo :field deve ser uma string.",
52
+ integer: "O campo :field deve ser um número inteiro.",
53
+ numeric: "O campo :field deve ser um número.",
54
+ array: "O campo :field deve ser um array.",
55
+ boolean: "O campo :field deve ser verdadeiro ou falso.",
56
+ date: "O campo :field não é uma data válida.",
57
+ same: "O campo :field e :other devem ser iguais.",
58
+ different: "O campo :field e :other devem ser diferentes.",
59
+ confirmed: "A confirmação do campo :field não corresponde.",
60
+ in: "O campo :field selecionado é inválido.",
61
+ notIn: "O campo :field selecionado é inválido.",
62
+ regex: "O formato do campo :field é inválido.",
63
+ startsWith: "O campo :field deve começar com um dos seguintes valores: :values.",
64
+ endsWith: "O campo :field deve terminar com um dos seguintes valores: :values.",
65
+ digits: "O campo :field deve ter :digits dígitos.",
66
+ digitsBetween: "O campo :field deve ter entre :min e :max dígitos.",
67
+ ip: "O campo :field deve ser um endereço de IP válido.",
68
+ json: "O campo :field deve ser uma string JSON válida.",
69
+ uuid: "O campo :field deve ser um UUID válido.",
70
+ lessThan: "O campo :field deve ser menor que :other.",
71
+ greaterThan: "O campo :field deve ser maior que :other.",
72
+ lessThanOrEqual: "O campo :field deve ser menor ou igual a :other.",
73
+ greaterThanOrEqual: "O campo :field deve ser maior ou igual a :other.",
74
+ nullable: "O campo :field deve ser nulo."
75
+ }
76
+ }, n = {
77
+ name: "es",
78
+ messages: {
79
+ required: "El campo :field es obligatorio.",
80
+ email: "El campo :field debe ser una dirección de correo electrónico válida.",
81
+ url: "El campo :field debe ser una URL válida.",
82
+ min: "El campo :field debe tener al menos :min.",
83
+ max: "El campo :field no debe ser mayor que :max.",
84
+ between: "El campo :field debe estar entre :min y :max.",
85
+ size: "El campo :field debe tener :size.",
86
+ alpha: "El campo :field solo debe contener letras.",
87
+ alphaNumeric: "El campo :field solo debe contener letras y números.",
88
+ string: "El campo :field debe ser una cadena de texto.",
89
+ integer: "El campo :field debe ser un número entero.",
90
+ numeric: "El campo :field debe ser un número.",
91
+ array: "El campo :field debe ser un array.",
92
+ boolean: "El campo :field debe ser verdadero o falso.",
93
+ date: "El campo :field no es una fecha válida.",
94
+ same: "El campo :field y :other deben coincidir.",
95
+ different: "El campo :field y :other deben ser diferentes.",
96
+ confirmed: "La confirmación del campo :field no coincide.",
97
+ in: "El campo :field seleccionado no es válido.",
98
+ notIn: "El campo :field seleccionado no es válido.",
99
+ regex: "El formato del campo :field no es válido.",
100
+ startsWith: "El campo :field debe comenzar con uno de los siguientes valores: :values.",
101
+ endsWith: "El campo :field debe terminar con uno de los siguientes valores: :values.",
102
+ digits: "El campo :field debe tener :digits dígitos.",
103
+ digitsBetween: "El campo :field debe tener entre :min y :max dígitos.",
104
+ ip: "El campo :field debe ser una dirección IP válida.",
105
+ json: "El campo :field debe ser una cadena JSON válida.",
106
+ uuid: "El campo :field debe ser un UUID válido.",
107
+ lessThan: "El campo :field debe ser menor que :other.",
108
+ greaterThan: "El campo :field debe ser mayor que :other.",
109
+ lessThanOrEqual: "El campo :field debe ser menor o igual que :other.",
110
+ greaterThanOrEqual: "El campo :field debe ser mayor o igual que :other.",
111
+ nullable: "El campo :field debe ser nulo."
112
+ }
113
+ };
114
+ //#endregion
115
+ export { e as en, n as es, t as pt };
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../rules-BIt-pifQ.cjs`);exports.allRules=e.t,exports.alpha=e.D,exports.alphaNumeric=e.E,exports.array=e.S,exports.between=e.k,exports.boolean=e.x,exports.confirmed=e._,exports.date=e.b,exports.different=e.v,exports.digits=e.d,exports.digitsBetween=e.u,exports.email=e.N,exports.endsWith=e.f,exports.greaterThan=e.a,exports.greaterThanOrEqual=e.r,exports.inRule=e.g,exports.integer=e.w,exports.ip=e.l,exports.json=e.c,exports.lessThan=e.o,exports.lessThanOrEqual=e.i,exports.max=e.A,exports.min=e.j,exports.notIn=e.h,exports.nullable=e.n,exports.numeric=e.C,exports.regex=e.m,exports.required=e.P,exports.same=e.y,exports.size=e.O,exports.startsWith=e.p,exports.string=e.T,exports.url=e.M,exports.uuid=e.s;
@@ -0,0 +1,2 @@
1
+ export * from '../src/plugins/rules/index'
2
+ export {}
@@ -0,0 +1,2 @@
1
+ import { A as e, C as t, D as n, E as r, M as i, N as a, O as o, P as s, S as c, T as l, _ as u, a as d, b as f, c as p, d as m, f as h, g, h as _, i as v, j as y, k as b, l as x, m as S, n as C, o as w, p as T, r as E, s as D, t as O, u as k, v as A, w as j, x as M, y as N } from "../rules-DZmnRoUy.js";
2
+ export { O as allRules, n as alpha, r as alphaNumeric, c as array, b as between, M as boolean, u as confirmed, f as date, A as different, m as digits, k as digitsBetween, a as email, h as endsWith, d as greaterThan, E as greaterThanOrEqual, g as inRule, j as integer, x as ip, p as json, w as lessThan, v as lessThanOrEqual, e as max, y as min, _ as notIn, C as nullable, t as numeric, S as regex, s as required, N as same, o as size, T as startsWith, l as string, i as url, D as uuid };
@@ -0,0 +1 @@
1
+ function e(e,t){return Object.assign(t,{ruleName:e})}var t=e(`required`,e=>new Promise((t,n)=>{if(e==null)return n();String(e).replace(/\s/g,``).length>0?t(e):n()})),n=e(`email`,e=>new Promise((t,n)=>{if(e==null||e===``)return n();/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(e))?t(e):n()})),r=e(`url`,e=>new Promise((t,n)=>{if(e==null||e===``)return n();try{new URL(String(e)),t(e)}catch{n()}})),i=e(`min`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``)return r();let i=Number(t[0]);if(isNaN(i))return r();if(typeof e==`number`)return e>=i?n(e):r();if(Array.isArray(e))return e.length>=i?n(e):r();String(e).length>=i?n(e):r()})),a=e(`max`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``)return r();let i=Number(t[0]);if(isNaN(i))return r();if(typeof e==`number`)return e<=i?n(e):r();if(Array.isArray(e))return e.length<=i?n(e):r();String(e).length<=i?n(e):r()})),o=e(`between`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``)return r();let i=Number(t[0]),a=Number(t[1]);if(isNaN(i)||isNaN(a))return r();if(typeof e==`number`)return e>=i&&e<=a?n(e):r();if(Array.isArray(e))return e.length>=i&&e.length<=a?n(e):r();let o=String(e).length;o>=i&&o<=a?n(e):r()})),s=e(`size`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``)return r();let i=Number(t[0]);if(isNaN(i))return r();if(typeof e==`number`)return e===i?n(e):r();if(Array.isArray(e))return e.length===i?n(e):r();String(e).length===i?n(e):r()})),c=e(`alpha`,e=>new Promise((t,n)=>{if(e==null||e===``)return n();/^[a-zA-Z]+$/.test(String(e))?t(e):n()})),l=e(`alphaNumeric`,e=>new Promise((t,n)=>{if(e==null||e===``)return n();/^[a-zA-Z0-9]+$/.test(String(e))?t(e):n()})),u=e(`string`,e=>new Promise((t,n)=>{if(e==null)return n();typeof e==`string`?t(e):n()})),d=e(`integer`,e=>new Promise((t,n)=>{if(e==null||e===``||typeof e==`boolean`||Array.isArray(e))return n();Number.isInteger(Number(e))?t(e):n()})),f=e(`numeric`,e=>new Promise((t,n)=>{if(e==null||e===``||typeof e==`boolean`||Array.isArray(e))return n();isNaN(Number(e))?n():t(e)})),p=e(`array`,e=>new Promise((t,n)=>{if(e==null)return n();Array.isArray(e)?t(e):n()})),m=e(`boolean`,e=>new Promise((t,n)=>{if(e==null)return n();[!0,!1,0,1,`0`,`1`].includes(e)?t(e):n()})),h=e(`date`,e=>new Promise((t,n)=>{if(e==null||e===``)return n();let r=new Date(String(e));isNaN(r.getTime())?n():t(e)})),g=e(`same`,(e,t,n)=>new Promise((r,i)=>{if(!n||!t[0])return i();e===n[t[0]]?r(e):i()})),_=e(`different`,(e,t,n)=>new Promise((r,i)=>{if(!n||!t[0])return i();e===n[t[0]]?i():r(e)})),v=e(`confirmed`,(e,t,n,r)=>new Promise((i,a)=>{if(!n)return a();let o=t[0]||r;if(!o)return a();let s=`${o}_confirmation`;if(n[s]!==void 0)return e===n[s]?i(e):a();a()})),y=e(`in`,(e,t)=>new Promise((n,r)=>{if(e==null||t.length===0)return r();t.includes(String(e))?n(e):r()})),b=e(`notIn`,(e,t)=>new Promise((n,r)=>{if(e==null)return r();if(t.length===0)return n(e);t.includes(String(e))?r():n(e)})),x=e(`regex`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``||!t[0])return r();let i=t[0].match(/^\/(.+)\/([gimsuy]*)$/);if(!i)return r();new RegExp(i[1],i[2]).test(String(e))?n(e):r()})),S=e(`startsWith`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``||!t.length)return r();let i=String(e);t.some(e=>i.startsWith(e))?n(e):r()})),C=e(`endsWith`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``||!t.length)return r();let i=String(e);t.some(e=>i.endsWith(e))?n(e):r()})),w=e(`digits`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``)return r();let i=Number(t[0]);if(isNaN(i))return r();let a=String(e);/^\d+$/.test(a)&&a.length===i?n(e):r()})),T=e(`digitsBetween`,(e,t)=>new Promise((n,r)=>{if(e==null||e===``)return r();let i=Number(t[0]),a=Number(t[1]);if(isNaN(i)||isNaN(a))return r();let o=String(e);/^\d+$/.test(o)&&o.length>=i&&o.length<=a?n(e):r()})),E=e(`ip`,e=>new Promise((t,n)=>{if(e==null||e===``)return n();let r=String(e);/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/.test(r)||/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?\d)?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d)|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?\d)?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d))$/.test(r)?t(e):n()})),D=e(`json`,e=>new Promise((t,n)=>{if(e==null||e===``)return n();try{JSON.parse(String(e)),t(e)}catch{n()}})),O=e(`uuid`,e=>new Promise((t,n)=>{if(e==null||e===``)return n();/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(String(e))?t(e):n()})),k=e(`lessThan`,(e,t,n)=>new Promise((r,i)=>{if(!n||!t[0])return i();let a=n[t[0]];if(typeof e!=`number`||typeof a!=`number`)return i();e<a?r(e):i()})),A=e(`greaterThan`,(e,t,n)=>new Promise((r,i)=>{if(!n||!t[0])return i();let a=n[t[0]];if(typeof e!=`number`||typeof a!=`number`)return i();e>a?r(e):i()})),j=e(`lessThanOrEqual`,(e,t,n)=>new Promise((r,i)=>{if(!n||!t[0])return i();let a=n[t[0]];if(typeof e!=`number`||typeof a!=`number`)return i();e<=a?r(e):i()})),M=e(`greaterThanOrEqual`,(e,t,n)=>new Promise((r,i)=>{if(!n||!t[0])return i();let a=n[t[0]];if(typeof e!=`number`||typeof a!=`number`)return i();e>=a?r(e):i()})),N=e(`nullable`,e=>Promise.resolve(e)),P={required:t,email:n,url:r,min:i,max:a,between:o,size:s,alpha:c,alphaNumeric:l,string:u,integer:d,numeric:f,array:p,boolean:m,date:h,same:g,different:_,confirmed:v,in:y,notIn:b,regex:x,startsWith:S,endsWith:C,digits:w,digitsBetween:T,ip:E,json:D,uuid:O,lessThan:k,greaterThan:A,lessThanOrEqual:j,greaterThanOrEqual:M,nullable:N};Object.defineProperty(exports,`A`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`D`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`E`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`M`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`N`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`O`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`P`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`T`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`j`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`k`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`w`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return g}});
@@ -0,0 +1,196 @@
1
+ //#region src/utils/rule.ts
2
+ function e(e, t) {
3
+ return Object.assign(t, { ruleName: e });
4
+ }
5
+ //#endregion
6
+ //#region src/plugins/rules/required.ts
7
+ var t = e("required", (e) => new Promise((t, n) => {
8
+ if (e == null) return n();
9
+ String(e).replace(/\s/g, "").length > 0 ? t(e) : n();
10
+ })), n = e("email", (e) => new Promise((t, n) => {
11
+ if (e == null || e === "") return n();
12
+ /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(e)) ? t(e) : n();
13
+ })), r = e("url", (e) => new Promise((t, n) => {
14
+ if (e == null || e === "") return n();
15
+ try {
16
+ new URL(String(e)), t(e);
17
+ } catch {
18
+ n();
19
+ }
20
+ })), i = e("min", (e, t) => new Promise((n, r) => {
21
+ if (e == null || e === "") return r();
22
+ let i = Number(t[0]);
23
+ if (isNaN(i)) return r();
24
+ if (typeof e == "number") return e >= i ? n(e) : r();
25
+ if (Array.isArray(e)) return e.length >= i ? n(e) : r();
26
+ String(e).length >= i ? n(e) : r();
27
+ })), a = e("max", (e, t) => new Promise((n, r) => {
28
+ if (e == null || e === "") return r();
29
+ let i = Number(t[0]);
30
+ if (isNaN(i)) return r();
31
+ if (typeof e == "number") return e <= i ? n(e) : r();
32
+ if (Array.isArray(e)) return e.length <= i ? n(e) : r();
33
+ String(e).length <= i ? n(e) : r();
34
+ })), o = e("between", (e, t) => new Promise((n, r) => {
35
+ if (e == null || e === "") return r();
36
+ let i = Number(t[0]), a = Number(t[1]);
37
+ if (isNaN(i) || isNaN(a)) return r();
38
+ if (typeof e == "number") return e >= i && e <= a ? n(e) : r();
39
+ if (Array.isArray(e)) return e.length >= i && e.length <= a ? n(e) : r();
40
+ let o = String(e).length;
41
+ o >= i && o <= a ? n(e) : r();
42
+ })), s = e("size", (e, t) => new Promise((n, r) => {
43
+ if (e == null || e === "") return r();
44
+ let i = Number(t[0]);
45
+ if (isNaN(i)) return r();
46
+ if (typeof e == "number") return e === i ? n(e) : r();
47
+ if (Array.isArray(e)) return e.length === i ? n(e) : r();
48
+ String(e).length === i ? n(e) : r();
49
+ })), c = e("alpha", (e) => new Promise((t, n) => {
50
+ if (e == null || e === "") return n();
51
+ /^[a-zA-Z]+$/.test(String(e)) ? t(e) : n();
52
+ })), l = e("alphaNumeric", (e) => new Promise((t, n) => {
53
+ if (e == null || e === "") return n();
54
+ /^[a-zA-Z0-9]+$/.test(String(e)) ? t(e) : n();
55
+ })), u = e("string", (e) => new Promise((t, n) => {
56
+ if (e == null) return n();
57
+ typeof e == "string" ? t(e) : n();
58
+ })), d = e("integer", (e) => new Promise((t, n) => {
59
+ if (e == null || e === "" || typeof e == "boolean" || Array.isArray(e)) return n();
60
+ Number.isInteger(Number(e)) ? t(e) : n();
61
+ })), f = e("numeric", (e) => new Promise((t, n) => {
62
+ if (e == null || e === "" || typeof e == "boolean" || Array.isArray(e)) return n();
63
+ isNaN(Number(e)) ? n() : t(e);
64
+ })), p = e("array", (e) => new Promise((t, n) => {
65
+ if (e == null) return n();
66
+ Array.isArray(e) ? t(e) : n();
67
+ })), m = e("boolean", (e) => new Promise((t, n) => {
68
+ if (e == null) return n();
69
+ [
70
+ !0,
71
+ !1,
72
+ 0,
73
+ 1,
74
+ "0",
75
+ "1"
76
+ ].includes(e) ? t(e) : n();
77
+ })), h = e("date", (e) => new Promise((t, n) => {
78
+ if (e == null || e === "") return n();
79
+ let r = new Date(String(e));
80
+ isNaN(r.getTime()) ? n() : t(e);
81
+ })), g = e("same", (e, t, n) => new Promise((r, i) => {
82
+ if (!n || !t[0]) return i();
83
+ e === n[t[0]] ? r(e) : i();
84
+ })), _ = e("different", (e, t, n) => new Promise((r, i) => {
85
+ if (!n || !t[0]) return i();
86
+ e === n[t[0]] ? i() : r(e);
87
+ })), v = e("confirmed", (e, t, n, r) => new Promise((i, a) => {
88
+ if (!n) return a();
89
+ let o = t[0] || r;
90
+ if (!o) return a();
91
+ let s = `${o}_confirmation`;
92
+ if (n[s] !== void 0) return e === n[s] ? i(e) : a();
93
+ a();
94
+ })), y = e("in", (e, t) => new Promise((n, r) => {
95
+ if (e == null || t.length === 0) return r();
96
+ t.includes(String(e)) ? n(e) : r();
97
+ })), b = e("notIn", (e, t) => new Promise((n, r) => {
98
+ if (e == null) return r();
99
+ if (t.length === 0) return n(e);
100
+ t.includes(String(e)) ? r() : n(e);
101
+ })), x = e("regex", (e, t) => new Promise((n, r) => {
102
+ if (e == null || e === "" || !t[0]) return r();
103
+ let i = t[0].match(/^\/(.+)\/([gimsuy]*)$/);
104
+ if (!i) return r();
105
+ new RegExp(i[1], i[2]).test(String(e)) ? n(e) : r();
106
+ })), S = e("startsWith", (e, t) => new Promise((n, r) => {
107
+ if (e == null || e === "" || !t.length) return r();
108
+ let i = String(e);
109
+ t.some((e) => i.startsWith(e)) ? n(e) : r();
110
+ })), C = e("endsWith", (e, t) => new Promise((n, r) => {
111
+ if (e == null || e === "" || !t.length) return r();
112
+ let i = String(e);
113
+ t.some((e) => i.endsWith(e)) ? n(e) : r();
114
+ })), w = e("digits", (e, t) => new Promise((n, r) => {
115
+ if (e == null || e === "") return r();
116
+ let i = Number(t[0]);
117
+ if (isNaN(i)) return r();
118
+ let a = String(e);
119
+ /^\d+$/.test(a) && a.length === i ? n(e) : r();
120
+ })), T = e("digitsBetween", (e, t) => new Promise((n, r) => {
121
+ if (e == null || e === "") return r();
122
+ let i = Number(t[0]), a = Number(t[1]);
123
+ if (isNaN(i) || isNaN(a)) return r();
124
+ let o = String(e);
125
+ /^\d+$/.test(o) && o.length >= i && o.length <= a ? n(e) : r();
126
+ })), E = e("ip", (e) => new Promise((t, n) => {
127
+ if (e == null || e === "") return n();
128
+ let r = String(e);
129
+ /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/.test(r) || /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?\d)?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d)|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?\d)?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d))$/.test(r) ? t(e) : n();
130
+ })), D = e("json", (e) => new Promise((t, n) => {
131
+ if (e == null || e === "") return n();
132
+ try {
133
+ JSON.parse(String(e)), t(e);
134
+ } catch {
135
+ n();
136
+ }
137
+ })), O = e("uuid", (e) => new Promise((t, n) => {
138
+ if (e == null || e === "") return n();
139
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(String(e)) ? t(e) : n();
140
+ })), k = e("lessThan", (e, t, n) => new Promise((r, i) => {
141
+ if (!n || !t[0]) return i();
142
+ let a = n[t[0]];
143
+ if (typeof e != "number" || typeof a != "number") return i();
144
+ e < a ? r(e) : i();
145
+ })), A = e("greaterThan", (e, t, n) => new Promise((r, i) => {
146
+ if (!n || !t[0]) return i();
147
+ let a = n[t[0]];
148
+ if (typeof e != "number" || typeof a != "number") return i();
149
+ e > a ? r(e) : i();
150
+ })), j = e("lessThanOrEqual", (e, t, n) => new Promise((r, i) => {
151
+ if (!n || !t[0]) return i();
152
+ let a = n[t[0]];
153
+ if (typeof e != "number" || typeof a != "number") return i();
154
+ e <= a ? r(e) : i();
155
+ })), M = e("greaterThanOrEqual", (e, t, n) => new Promise((r, i) => {
156
+ if (!n || !t[0]) return i();
157
+ let a = n[t[0]];
158
+ if (typeof e != "number" || typeof a != "number") return i();
159
+ e >= a ? r(e) : i();
160
+ })), N = e("nullable", (e) => Promise.resolve(e)), P = {
161
+ required: t,
162
+ email: n,
163
+ url: r,
164
+ min: i,
165
+ max: a,
166
+ between: o,
167
+ size: s,
168
+ alpha: c,
169
+ alphaNumeric: l,
170
+ string: u,
171
+ integer: d,
172
+ numeric: f,
173
+ array: p,
174
+ boolean: m,
175
+ date: h,
176
+ same: g,
177
+ different: _,
178
+ confirmed: v,
179
+ in: y,
180
+ notIn: b,
181
+ regex: x,
182
+ startsWith: S,
183
+ endsWith: C,
184
+ digits: w,
185
+ digitsBetween: T,
186
+ ip: E,
187
+ json: D,
188
+ uuid: O,
189
+ lessThan: k,
190
+ greaterThan: A,
191
+ lessThanOrEqual: j,
192
+ greaterThanOrEqual: M,
193
+ nullable: N
194
+ };
195
+ //#endregion
196
+ export { a as A, f as C, c as D, l as E, r as M, n as N, s as O, t as P, p as S, u as T, v as _, A as a, h as b, D as c, w as d, C as f, y as g, b as h, j as i, i as j, o as k, E as l, x as m, N as n, k as o, S as p, M as r, O as s, P as t, T as u, _ as v, d as w, m as x, g as y };
@@ -1,5 +1,5 @@
1
1
  import { Collection } from '../utils/collections';
2
2
  export declare class Errors extends Collection<string[]> {
3
3
  push(item: string, data: any): this;
4
- get(key: string): string[] | null;
4
+ get(key: string): string[];
5
5
  }
@@ -1,12 +1,22 @@
1
1
  import { Field, Fields, RawFields } from '../types/fields';
2
2
  import { Values } from '../types/values';
3
3
  import { Validation } from './Validation';
4
+ import { Rules, RuleHandler } from '../types/rules';
5
+ import { FormWrapperPlugin } from '../types/plugin';
6
+ import { Locale, LocaleMessages } from '../types/locale';
4
7
  export declare class Form {
5
8
  [key: string]: any;
9
+ static rules: Rules;
10
+ static defaultMessages: LocaleMessages;
11
+ private static interpolateMessage;
6
12
  awaiting: boolean;
7
13
  originalValues: Values;
14
+ fieldAttributes: Record<string, string>;
8
15
  validation: Validation;
9
16
  constructor(fields: Fields | RawFields);
17
+ static extend(plugin: FormWrapperPlugin): typeof Form;
18
+ static addRule(name: string, handler: RuleHandler): typeof Form;
19
+ static locale(locale: Locale): typeof Form;
10
20
  addField(field: string, value: Field): this;
11
21
  addFields(fields: Fields | RawFields): this;
12
22
  get errors(): import('./Errors').Errors;
@@ -25,5 +35,6 @@ export declare class Form {
25
35
  validateField(field: string): Promise<void>;
26
36
  validateForm(): Promise<this>;
27
37
  values(only?: string[]): Values;
38
+ filledValues(only?: string[]): Values;
28
39
  valuesAsFormData(only?: string[]): FormData;
29
40
  }