Skip to content

Commit 260968d

Browse files
committed
fix: added force update to add function
1 parent 56c369e commit 260968d

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"rimraf": "^3.0.2",
7373
"standard-version": "^9.3.1",
7474
"ts-jest": "^27.1.1",
75+
"ts-node": "^10.9.1",
7576
"typescript": "^4.5.3",
7677
"vue": "^2.6.14"
7778
},

src/__tests__/validator.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ describe('Validator', () => {
1414
validator.add('name', 'The name field is required.')
1515
expect(validator.any()).toBeTruthy()
1616
})
17+
test('Add an error with forceUpdate', () => {
18+
validator.add('name', 'The name field is required.', true)
19+
expect(validator.any()).toBeTruthy()
20+
})
1721
test('add error with missed attribute', () => {
18-
validator.add('name-3diidi', 'The name field is required.')
22+
validator.add('name-3', 'The name field is required.')
1923
expect(validator.any()).toBeTruthy()
2024
})
2125
test('Add an error message as string', () => {

src/core/Validator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ class Validator {
1212
this.errors = errors
1313
}
1414

15-
add(attribute: string, message: string) {
15+
add(attribute: string, message: string, forceUpdate?: boolean) {
1616
if (this.missed(attribute)) {
1717
this.errors[attribute] = []
1818
}
1919
if (!this.errors[attribute].includes(message)) {
20+
this.errors[attribute].unshift(message)
21+
}
22+
if (forceUpdate) {
23+
this.errors[attribute] = []
2024
this.errors[attribute].push(message)
2125
}
2226
}

yarn.lock

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,13 @@
15231523
dependencies:
15241524
"@cspotcode/source-map-consumer" "0.8.0"
15251525

1526+
"@cspotcode/source-map-support@^0.8.0":
1527+
version "0.8.1"
1528+
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"
1529+
integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==
1530+
dependencies:
1531+
"@jridgewell/trace-mapping" "0.3.9"
1532+
15261533
"@csstools/convert-colors@^1.4.0":
15271534
version "1.4.0"
15281535
resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7"
@@ -1773,6 +1780,24 @@
17731780
"@types/yargs" "^16.0.0"
17741781
chalk "^4.0.0"
17751782

1783+
"@jridgewell/resolve-uri@^3.0.3":
1784+
version "3.1.0"
1785+
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78"
1786+
integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==
1787+
1788+
"@jridgewell/sourcemap-codec@^1.4.10":
1789+
version "1.4.14"
1790+
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24"
1791+
integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==
1792+
1793+
"@jridgewell/[email protected]":
1794+
version "0.3.9"
1795+
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9"
1796+
integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==
1797+
dependencies:
1798+
"@jridgewell/resolve-uri" "^3.0.3"
1799+
"@jridgewell/sourcemap-codec" "^1.4.10"
1800+
17761801
"@nodelib/[email protected]":
17771802
version "2.1.5"
17781803
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
@@ -11316,6 +11341,25 @@ ts-node@^10.7.0:
1131611341
v8-compile-cache-lib "^3.0.0"
1131711342
yn "3.1.1"
1131811343

11344+
ts-node@^10.9.1:
11345+
version "10.9.1"
11346+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b"
11347+
integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==
11348+
dependencies:
11349+
"@cspotcode/source-map-support" "^0.8.0"
11350+
"@tsconfig/node10" "^1.0.7"
11351+
"@tsconfig/node12" "^1.0.7"
11352+
"@tsconfig/node14" "^1.0.0"
11353+
"@tsconfig/node16" "^1.0.2"
11354+
acorn "^8.4.1"
11355+
acorn-walk "^8.1.1"
11356+
arg "^4.1.0"
11357+
create-require "^1.1.0"
11358+
diff "^4.0.1"
11359+
make-error "^1.1.1"
11360+
v8-compile-cache-lib "^3.0.1"
11361+
yn "3.1.1"
11362+
1131911363
ts-pnp@^1.1.6:
1132011364
version "1.2.0"
1132111365
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
@@ -11630,7 +11674,7 @@ [email protected]:
1163011674
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
1163111675
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=
1163211676

11633-
v8-compile-cache-lib@^3.0.0:
11677+
v8-compile-cache-lib@^3.0.0, v8-compile-cache-lib@^3.0.1:
1163411678
version "3.0.1"
1163511679
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
1163611680
integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==

0 commit comments

Comments
 (0)