@coxy/react-validator 2.0.1 → 2.0.3
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/dist/rules.d.ts +3 -2
- package/dist/{validator-field.jsx → validator-field.js} +2 -3
- package/dist/{validator-wrapper.jsx → validator-wrapper.js} +2 -3
- package/example/{example.jsx → example.tsx} +1 -1
- package/example/tsconfig.json +15 -0
- package/package.json +25 -29
- package/src/use-validator.ts +1 -0
- package/src/validator-wrapper.tsx +1 -2
- package/src/validator.ts +8 -7
- package/tsconfig.json +1 -1
- 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
|
|
package/dist/rules.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { Value } from './validator-field';
|
|
2
|
+
declare type Fn = (value: Value) => string;
|
|
2
3
|
export interface RuleInstance {
|
|
3
|
-
rule: (value:
|
|
4
|
+
rule: (value: Value) => boolean;
|
|
4
5
|
message: string | Fn;
|
|
5
6
|
}
|
|
6
7
|
export declare type ValidatorRules = RuleInstance[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValidatorField = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const context_1 = require("./context");
|
|
6
7
|
const validator_1 = require("./validator");
|
|
@@ -27,8 +28,6 @@ class ValidationFieldWrapper extends react_1.Component {
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
function ValidatorField(props) {
|
|
30
|
-
return (
|
|
31
|
-
{(data) => (<ValidationFieldWrapper {...props} registerField={data.registerField} unregisterField={data.unregisterField}/>)}
|
|
32
|
-
</context_1.Context.Consumer>);
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)(context_1.Context.Consumer, { children: (data) => ((0, jsx_runtime_1.jsx)(ValidationFieldWrapper, Object.assign({}, props, { registerField: data.registerField, unregisterField: data.unregisterField }))) }));
|
|
33
32
|
}
|
|
34
33
|
exports.ValidatorField = ValidatorField;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValidatorWrapper = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const context_1 = require("./context");
|
|
6
7
|
const validator_1 = require("./validator");
|
|
@@ -35,9 +36,7 @@ class ValidatorWrapper extends react_1.Component {
|
|
|
35
36
|
return validator.validate();
|
|
36
37
|
}
|
|
37
38
|
render() {
|
|
38
|
-
return (
|
|
39
|
-
{this.props.children}
|
|
40
|
-
</context_1.Context.Provider>);
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)(context_1.Context.Provider, Object.assign({ value: { registerField: this.registerField, unregisterField: this.unregisterField } }, { children: this.props.children })));
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
exports.ValidatorWrapper = ValidatorWrapper;
|
|
@@ -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.3",
|
|
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,28 @@
|
|
|
34
34
|
"react": ">=18.x.x"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"eslint": "
|
|
49
|
-
"eslint-
|
|
50
|
-
"eslint-plugin-
|
|
51
|
-
"eslint-plugin-
|
|
52
|
-
"eslint-plugin-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"ts-node": "^10.8.2",
|
|
61
|
-
"typescript": "^4.7.4",
|
|
62
|
-
"webpack": "^5.73.0",
|
|
63
|
-
"webpack-cli": "^4.10.0"
|
|
37
|
+
"@coxy/eslint-config": "1.0.5",
|
|
38
|
+
"@testing-library/react": "13.4.0",
|
|
39
|
+
"@types/jest": "29.1.2",
|
|
40
|
+
"@types/react": "18.0.21",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "5.*",
|
|
42
|
+
"@typescript-eslint/parser": "5.*",
|
|
43
|
+
"codecov": "3.8.3",
|
|
44
|
+
"coveralls": "3.1.1",
|
|
45
|
+
"eslint": "8.25.0",
|
|
46
|
+
"eslint-config-standard": "17.0.0",
|
|
47
|
+
"eslint-plugin-import": "2.26.0",
|
|
48
|
+
"eslint-plugin-jsx-a11y": "6.6.1",
|
|
49
|
+
"eslint-plugin-n": "15.3.0",
|
|
50
|
+
"eslint-plugin-promise": "6.0.1",
|
|
51
|
+
"eslint-plugin-filename-rules": "1.2.0",
|
|
52
|
+
"eslint-plugin-react": "7.31.8",
|
|
53
|
+
"jest": "29.1.2",
|
|
54
|
+
"jest-environment-jsdom": "29.1.2",
|
|
55
|
+
"react-dom": "18.2.0",
|
|
56
|
+
"react-test-renderer": "18.2.0",
|
|
57
|
+
"ts-jest": "29.0.3",
|
|
58
|
+
"ts-node": "10.9.1",
|
|
59
|
+
"typescript": "4.8.4"
|
|
64
60
|
}
|
|
65
61
|
}
|
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/tsconfig.json
CHANGED
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
|
-
}
|