@zemkogabor/vue-form-validator 0.0.3 → 1.1.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.
@@ -1,54 +1,62 @@
1
- import { ref as v } from "vue";
2
- import { useI18n as m } from "vue-i18n";
3
- function c(i) {
4
- const { t: e } = m(), t = v(null);
5
- function l(r) {
6
- const a = i.value;
7
- a !== null && (r !== null ? a.setCustomValidity(r) : a.setCustomValidity(""), t.value = o(a));
1
+ import { inject as f, ref as u } from "vue";
2
+ const v = /* @__PURE__ */ Symbol("VALIDATOR_CONFIG");
3
+ function g(s) {
4
+ const a = f(
5
+ v,
6
+ void 0
7
+ );
8
+ if (!a || !a.messages)
9
+ throw new Error(
10
+ "[vue-form-validator] Validator messages are not provided. Did you forget to call app.provide(VALIDATOR_CONFIG_KEY, ...)?"
11
+ );
12
+ const r = a.messages, i = u(null);
13
+ function l(e) {
14
+ const t = s.value;
15
+ t !== null && (e !== null ? t.setCustomValidity(e) : t.setCustomValidity(""), i.value = o(t));
8
16
  }
9
- function o(r) {
10
- if (r.validity.valueMissing)
11
- return e("validator.error.value_missing");
12
- if (r.validity.tooShort)
13
- return e("validator.error.too_short", [r.minLength]);
14
- if (r.validity.tooLong)
15
- return e("validator.error.too_long", [r.maxLength]);
16
- if (r.validity.rangeUnderflow)
17
- return e("validator.error.range_underflow", [r.min]);
18
- if (r.validity.rangeOverflow)
19
- return e("validator.error.range_overflow", [r.max]);
20
- if (r.validity.typeMismatch) {
21
- if (r.type === "email")
22
- return e("validator.error.type_mismatch.email");
23
- if (r.type === "url")
24
- return e("validator.error.type_mismatch.url");
17
+ function o(e) {
18
+ if (e.validity.valueMissing)
19
+ return r.valueMissing;
20
+ if (e.validity.tooShort)
21
+ return r.tooShort(e.minLength);
22
+ if (e.validity.tooLong)
23
+ return r.tooLong(e.maxLength);
24
+ if (e.validity.rangeUnderflow)
25
+ return r.rangeUnderflow(e.min);
26
+ if (e.validity.rangeOverflow)
27
+ return r.rangeOverflow(e.max);
28
+ if (e.validity.typeMismatch) {
29
+ if (e.type === "email")
30
+ return r.typeMismatchEmail;
31
+ if (e.type === "url")
32
+ return r.typeMismatchUrl;
25
33
  }
26
- if (r.validity.badInput) {
27
- if (r.type === "number")
28
- return e("validator.error.bad_input.number");
29
- if (r.type === "date")
30
- return e("validator.error.bad_input.date");
34
+ if (e.validity.badInput) {
35
+ if (e.type === "number")
36
+ return r.badInputNumber;
37
+ if (e.type === "date")
38
+ return r.badInputDate;
31
39
  }
32
- if (r.validity.patternMismatch)
33
- return e("validator.error.pattern_mismatch");
34
- if (r.validity.stepMismatch) {
35
- const a = Math.floor(Number(r.value) / Number(r.step)) * Number(r.step), d = Math.ceil(Number(r.value) / Number(r.step)) * Number(r.step);
36
- return e("validator.error.step_mismatch", [a, d]);
40
+ if (e.validity.patternMismatch)
41
+ return r.patternMismatch;
42
+ if (e.validity.stepMismatch) {
43
+ const t = Math.floor(Number(e.value) / Number(e.step)) * Number(e.step), d = Math.ceil(Number(e.value) / Number(e.step)) * Number(e.step);
44
+ return r.stepMismatch(t, d);
37
45
  }
38
- return r.validity.customError ? r.validationMessage : null;
46
+ return e.validity.customError ? e.validationMessage : null;
39
47
  }
40
- function n(r) {
41
- r.target !== null && (t.value = o(r.target));
48
+ function n(e) {
49
+ e.target !== null && (i.value = o(e.target));
42
50
  }
43
- function s() {
44
- return t.value;
51
+ function m() {
52
+ return i.value;
45
53
  }
46
54
  return {
47
55
  onInvalid: n,
48
- getInvalidMessage: s,
56
+ getInvalidMessage: m,
49
57
  setCustomError: l
50
58
  };
51
59
  }
52
60
  export {
53
- c as useValidator
61
+ g as useValidator
54
62
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zemkogabor/vue-form-validator",
3
- "version": "0.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "A lightweight Vue.js library that implements the JavaScript Constraint Validation API, offering advanced form validation with custom error messages and internationalization support.",
5
5
  "module": "./dist/vue-form-validator.js",
6
6
  "types": "./dist/index.d.ts",
@@ -32,28 +32,28 @@
32
32
  ],
33
33
  "author": "Gabor Zemko <gaborzemko@gmail.com>",
34
34
  "peerDependencies": {
35
- "vue": "^3.0.0",
36
- "vue-i18n": "^9.0.0"
35
+ "vue": "^3.0.0"
37
36
  },
38
37
  "devDependencies": {
39
- "@rushstack/eslint-patch": "^1.3.3",
40
- "@tsconfig/node20": "^20.1.2",
41
- "@types/node": "^20.11.10",
42
- "@vitejs/plugin-vue": "^5.0.3",
43
- "@vue/eslint-config-typescript": "^12.0.0",
44
- "@vue/tsconfig": "^0.5.1",
45
- "eslint": "^8.49.0",
38
+ "@eslint/js": "^9.39.2",
39
+ "@tsconfig/node22": "^22.0.5",
40
+ "@types/bootstrap": "^5.2.10",
41
+ "@types/node": "^22.10.1",
42
+ "@vue/eslint-config-typescript": "^14.6.0",
43
+ "@vue/tsconfig": "^0.8.1",
44
+ "@vitejs/plugin-vue": "^6.0.3",
45
+ "eslint": "^9.39.2",
46
46
  "eslint-config-standard": "^17.1.0",
47
- "eslint-plugin-import": "^2.29.1",
48
- "eslint-plugin-n": "^16.6.2",
47
+ "eslint-plugin-import": "^2.32.0",
48
+ "eslint-plugin-n": "^17.23.1",
49
49
  "eslint-plugin-node": "^11.1.0",
50
- "eslint-plugin-promise": "^6.1.1",
51
- "eslint-plugin-vue": "^9.22.0",
52
- "typescript": "~5.3.0",
53
- "vite": "^5.0.11",
54
- "vite-plugin-dts": "^3.8.3",
55
- "vue": "^3.4.21",
56
- "vue-i18n": "^9.10.1",
57
- "vue-tsc": "^1.8.27"
50
+ "eslint-plugin-promise": "^7.2.1",
51
+ "eslint-plugin-vue": "^10.6.2",
52
+ "lint-staged": "^16.2.7",
53
+ "typescript-eslint": "^8.52.0",
54
+ "vue-tsc": "^3.2.2",
55
+ "vue": "^3.5.27",
56
+ "vite": "^7.3.1",
57
+ "vite-plugin-dts": "^4.5.4"
58
58
  }
59
59
  }
@@ -1,7 +0,0 @@
1
- import { Ref } from 'vue';
2
-
3
- export declare function useValidator(inputRef: Ref<HTMLInputElement | null>): {
4
- onInvalid: (event: Event) => void;
5
- getInvalidMessage: () => string | null;
6
- setCustomError: (data: string) => void;
7
- };
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { useValidator } from './Validator';