Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2cbf673

Browse files
chore: clean up
1 parent 5906cd0 commit 2cbf673

File tree

6 files changed

+201
-25
lines changed

6 files changed

+201
-25
lines changed

‎.eslintignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build/
22
dist/
33
node_modules/
44
.snapshots/
5-
*.min.js
5+
*.min.js
6+
*.d.ts

‎.eslintrc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"node": true
1212
},
1313
"parserOptions": {
14+
"parser": "@typescript-eslint/parser",
1415
"ecmaVersion": 2020,
1516
"ecmaFeatures": {
1617
"legacyDecorators": true,
@@ -30,4 +31,4 @@
3031
"react/no-unused-prop-types": 0,
3132
"import/export": 0
3233
}
33-
}
34+
}

‎@types/index.d.ts‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1+
import { ChangeEvent } from "react";
2+
13
declare module "use-form-input-validator" {
2-
import { ChangeEvent, SyntheticEvent } from "react";
3-
interface InputField {
4-
[key: string]: {
5-
value: string
6-
checks: string
7-
validate: (value: string) => string
8-
}
9-
}
10-
interface InputValues {
11-
[key: string]: [value: string]
12-
}
13-
interface InputErrors {
14-
[key: string]: [error: string]
4+
export type InputField = {
5+
value: string
6+
checks: string
7+
validate: (value: string, values: Record<string, string>) => string
158
}
169

17-
export defaultfunctionuseFormValidator(inputs: InputField): {
18-
values: InputValues
19-
errors: InputErrors
10+
export typeFormValidator= {
11+
values: Record<string,InputField>;
12+
errors: Record<string,string>
2013
updateField: (event: ChangeEvent<HTMLInputElement>) => void
2114
isFieldValid: (key) => boolean
2215
isAllFieldsValid: () => boolean
23-
};
16+
}
17+
export default function useFormValidator(inputs: InputField): FormValidator;
2418
}

‎package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"react": "^16.0.0"
2929
},
3030
"devDependencies": {
31-
"microbundle-crl": "^0.13.10",
31+
"@typescript-eslint/parser": "^4.28.4",
3232
"babel-eslint": "^10.0.3",
3333
"cross-env": "^7.0.2",
3434
"eslint": "^6.8.0",
@@ -42,6 +42,7 @@
4242
"eslint-plugin-react": "^7.17.0",
4343
"eslint-plugin-standard": "^4.0.1",
4444
"gh-pages": "^2.2.0",
45+
"microbundle-crl": "^0.13.10",
4546
"npm-run-all": "^4.1.5",
4647
"prettier": "^2.0.4",
4748
"react": "^16.13.1",
@@ -65,4 +66,4 @@
6566
"dependencies": {
6667
"validator": "^13.1.17"
6768
}
68-
}
69+
}

‎src/index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ const useFormValidator = (inputs) => {
142142
for (const key in fields.values) {
143143
const error = validate({
144144
value: fields.values[key],
145-
checks: fields.checks[key]
145+
values: fields.values,
146+
checks: fields.checks[key],
147+
customValidator: fields.validators[key]
146148
})
147149

148150
if (error) valid = false

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /