@coxy/react-validator 2.0.2 → 2.0.4
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.
- package/.eslintignore +0 -1
- package/.eslintrc.js +1 -22
- package/README.md +2 -2
- package/example/{example.jsx → example.tsx} +1 -1
- package/example/tsconfig.json +15 -0
- package/package.json +26 -29
- package/src/use-validator.ts +1 -0
- package/src/validator-wrapper.tsx +1 -2
- package/src/validator.ts +8 -7
- package/babel.config.js +0 -3
- package/example/webpack.config.js +0 -29
package/.eslintignore
CHANGED
package/.eslintrc.js
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
root: true,
|
|
3
3
|
parser: '@typescript-eslint/parser',
|
|
4
|
-
plugins: [
|
|
5
|
-
'react',
|
|
6
|
-
'import',
|
|
7
|
-
'@typescript-eslint'
|
|
8
|
-
],
|
|
9
|
-
rules: {
|
|
10
|
-
'no-void': [0],
|
|
11
|
-
'react/jsx-tag-spacing': ['error', {
|
|
12
|
-
closingSlash: 'never',
|
|
13
|
-
beforeSelfClosing: 'always',
|
|
14
|
-
afterOpening: 'never',
|
|
15
|
-
beforeClosing: 'never'
|
|
16
|
-
}],
|
|
17
|
-
'import/order': ['error', {
|
|
18
|
-
groups: ['type', 'external', 'internal', 'builtin', 'object', 'index', 'parent', 'sibling'],
|
|
19
|
-
'newlines-between': 'always'
|
|
20
|
-
}]
|
|
21
|
-
},
|
|
22
4
|
extends: [
|
|
23
|
-
'
|
|
24
|
-
'eslint:recommended',
|
|
25
|
-
'plugin:@typescript-eslint/eslint-recommended',
|
|
26
|
-
'plugin:@typescript-eslint/recommended'
|
|
5
|
+
'@coxy/eslint-config/react'
|
|
27
6
|
]
|
|
28
7
|
}
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Need react **>=16.3**
|
|
|
20
20
|
|
|
21
21
|
# Example
|
|
22
22
|
|
|
23
|
-
See more examples [here](example/example.
|
|
23
|
+
See more examples [here](example/example.tsx)
|
|
24
24
|
|
|
25
25
|
```jsx
|
|
26
26
|
import React, { useState } from 'react';
|
|
@@ -68,7 +68,7 @@ export default () => {
|
|
|
68
68
|
};
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
See more examples [here](example/example.
|
|
71
|
+
See more examples [here](example/example.tsx)
|
|
72
72
|
|
|
73
73
|
# Rules
|
|
74
74
|
|
|
@@ -6,7 +6,7 @@ import { ValidatorWrapper, rules, ValidatorField, Validator } from '../dist/inde
|
|
|
6
6
|
|
|
7
7
|
function App () {
|
|
8
8
|
const [email, setEmail] = useState('')
|
|
9
|
-
const jsxValidator = createRef()
|
|
9
|
+
const jsxValidator = createRef<ValidatorWrapper>()
|
|
10
10
|
|
|
11
11
|
function handleValidateEmail () {
|
|
12
12
|
const { isValid, message, errors } = jsxValidator.current.validate()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coxy/react-validator",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "🚀 Simple validation form for React or NodeJS apps. useValidator are included ;)",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"start": "ts-node . --watch",
|
|
23
23
|
"build": "NODE_ENV=production tsc --project tsconfig.build.json",
|
|
24
|
-
"example": "
|
|
24
|
+
"example": "tsc --project ./example/tsconfig.json",
|
|
25
25
|
"coverage": "codecov",
|
|
26
26
|
"coveralls": "coveralls .",
|
|
27
27
|
"test": "jest"
|
|
@@ -34,32 +34,29 @@
|
|
|
34
34
|
"react": ">=18.x.x"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@types/
|
|
42
|
-
"@
|
|
43
|
-
"@typescript-eslint/
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"eslint": "
|
|
49
|
-
"eslint-
|
|
50
|
-
"eslint-plugin-
|
|
51
|
-
"eslint-plugin-
|
|
52
|
-
"eslint-plugin-
|
|
53
|
-
"eslint-plugin-
|
|
54
|
-
"
|
|
55
|
-
"jest": "
|
|
56
|
-
"
|
|
57
|
-
"react-
|
|
58
|
-
"
|
|
59
|
-
"ts-
|
|
60
|
-
"
|
|
61
|
-
"typescript": "^4.7.4",
|
|
62
|
-
"webpack": "^5.73.0",
|
|
63
|
-
"webpack-cli": "^4.10.0"
|
|
37
|
+
"@coxy/eslint-config": "1.0.6",
|
|
38
|
+
"@testing-library/react": "13.4.0",
|
|
39
|
+
"@types/jest": "29.1.2",
|
|
40
|
+
"@types/node": "18.8.3",
|
|
41
|
+
"@types/react": "18.0.21",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "5.*",
|
|
43
|
+
"@typescript-eslint/parser": "5.*",
|
|
44
|
+
"codecov": "3.8.3",
|
|
45
|
+
"coveralls": "3.1.1",
|
|
46
|
+
"eslint": "8.25.0",
|
|
47
|
+
"eslint-config-standard": "17.0.0",
|
|
48
|
+
"eslint-plugin-import": "2.26.0",
|
|
49
|
+
"eslint-plugin-jsx-a11y": "6.6.1",
|
|
50
|
+
"eslint-plugin-n": "15.3.0",
|
|
51
|
+
"eslint-plugin-promise": "6.0.1",
|
|
52
|
+
"eslint-plugin-filename-rules": "1.2.0",
|
|
53
|
+
"eslint-plugin-react": "7.31.8",
|
|
54
|
+
"jest": "29.1.2",
|
|
55
|
+
"jest-environment-jsdom": "29.1.2",
|
|
56
|
+
"react-dom": "18.2.0",
|
|
57
|
+
"react-test-renderer": "18.2.0",
|
|
58
|
+
"ts-jest": "29.0.3",
|
|
59
|
+
"ts-node": "10.9.1",
|
|
60
|
+
"typescript": "4.8.4"
|
|
64
61
|
}
|
|
65
62
|
}
|
package/src/use-validator.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint react/sort-comp: [0], camelcase: [0] */
|
|
2
1
|
import { Component, ReactNode, RefObject } from 'react'
|
|
3
2
|
|
|
4
3
|
import { Context } from './context'
|
|
@@ -11,7 +10,7 @@ interface ComponentProps {
|
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export class ValidatorWrapper extends Component<ComponentProps> {
|
|
14
|
-
fields = []
|
|
13
|
+
fields = []
|
|
15
14
|
|
|
16
15
|
constructor (props, ctx) {
|
|
17
16
|
super(props, ctx)
|
package/src/validator.ts
CHANGED
|
@@ -5,14 +5,15 @@ export interface FieldParams {
|
|
|
5
5
|
value: Value
|
|
6
6
|
rules: ValidatorRules,
|
|
7
7
|
required?: boolean
|
|
8
|
-
id?: string
|
|
8
|
+
id?: string|number
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export class Field {
|
|
12
|
-
private rules: ValidatorRules
|
|
13
|
-
private required: boolean
|
|
14
|
-
private value: Value
|
|
15
|
-
public id: string
|
|
12
|
+
private rules: ValidatorRules
|
|
13
|
+
private required: boolean
|
|
14
|
+
private value: Value
|
|
15
|
+
public id: string|number
|
|
16
|
+
|
|
16
17
|
constructor ({
|
|
17
18
|
rules,
|
|
18
19
|
required,
|
|
@@ -61,8 +62,8 @@ export interface ValidatorParams {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
export class Validator {
|
|
64
|
-
private fields: Field[]
|
|
65
|
-
private params: ValidatorParams
|
|
65
|
+
private fields: Field[]
|
|
66
|
+
private params: ValidatorParams
|
|
66
67
|
|
|
67
68
|
constructor (params?: ValidatorParams) {
|
|
68
69
|
this.params = params || null
|
package/babel.config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
target: 'web',
|
|
6
|
-
entry: [
|
|
7
|
-
path.resolve('./example/example.jsx')
|
|
8
|
-
],
|
|
9
|
-
mode: 'development',
|
|
10
|
-
output: {
|
|
11
|
-
path: path.resolve('./example'),
|
|
12
|
-
filename: './dist/example.js'
|
|
13
|
-
},
|
|
14
|
-
devtool: 'source-map',
|
|
15
|
-
module: {
|
|
16
|
-
rules: [{
|
|
17
|
-
test: /\.jsx?$/,
|
|
18
|
-
exclude: /node_modules/,
|
|
19
|
-
loader: 'babel-loader'
|
|
20
|
-
}]
|
|
21
|
-
},
|
|
22
|
-
resolve: {
|
|
23
|
-
extensions: ['.js', '.jsx']
|
|
24
|
-
},
|
|
25
|
-
externals: {
|
|
26
|
-
react: 'React',
|
|
27
|
-
'react-dom': 'ReactDOM'
|
|
28
|
-
}
|
|
29
|
-
}
|