Skip to content

Commit 132c8b4

Browse files
authored
Merge pull request #7 from balavishnuvj/chores/auto-release
Chores/auto release
2 parents e617508 + ba7aa16 commit 132c8b4

File tree

10 files changed

+5529
-127
lines changed

10 files changed

+5529
-127
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/dist
2+
/node_modules

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
extends: ["eslint:recommended", "plugin:prettier/recommended"],
3+
env: {
4+
node: true,
5+
jest: true,
6+
browser: true,
7+
es6: true,
8+
},
9+
parser: "babel-eslint",
10+
rules: {
11+
"prettier/prettier": "error",
12+
},
13+
};

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<p>Simple, extensible and config based form validation.</p>
1414
</div>
1515

16+
**Small.** 9 KB (minified and gzipped).
17+
[Size Limit](https://github.com/ai/size-limit) controls the size.
18+
1619
## Table of Contents
1720

1821
- [The problem](#the-problem)
@@ -261,7 +264,7 @@ Basic usage is like
261264
| addFieldConfig | Dynamically add a field | `fn(fieldName, fieldConfig)` or `fn(fieldName, (formState)) => fieldConfig`| `formObject.addFieldConfig('useraname', { required: true })` or `formObject.addFieldConfig('useraname', (formState) => { required: !formState.email })` |
262265
| removeFieldConfig | Dynamically remove a field | `fn(fieldName)`| `formObject.removeFieldConfig('useraname')`|
263266
| reset | Resets the form config before adding or removing fields |`() => {}` | |
264-
| config | Current form config | `s{}`|
267+
| config | Current form config | `{}`|
265268

266269
## LICENSE
267270

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {extends: ['@commitlint/config-conventional']};

package.json

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
"module": "dist/react-hooks-form-validator.es.js",
77
"scripts": {
88
"build": "rollup --config",
9+
"lint": "eslint src/**",
10+
"prerelease": "yarn prettier:check && yarn test && yarn build && yarn size",
11+
"release": "standard-version -a",
12+
"release:dry": "standard-version --dry-run -a",
13+
"size": "size-limit",
14+
"prettier:check": "prettier --check 'src/**/*.{js,mdx}'",
915
"test": "jest"
1016
},
1117
"files": [
@@ -31,21 +37,58 @@
3137
"devDependencies": {
3238
"@babel/core": "^7.8.3",
3339
"@babel/preset-env": "^7.8.3",
40+
"@commitlint/cli": "^8.3.5",
41+
"@commitlint/config-conventional": "^8.3.4",
3442
"@rollup/plugin-commonjs": "^11.0.1",
3543
"@rollup/plugin-node-resolve": "^7.0.0",
44+
"@size-limit/preset-small-lib": "^4.5.0",
3645
"@testing-library/react-hooks": "^3.2.1",
46+
"babel-eslint": "^10.1.0",
3747
"babel-jest": "^24.9.0",
3848
"babel-preset-react": "^6.24.1",
49+
"cz-conventional-changelog": "3.2.0",
50+
"eslint": "^7.0.0",
51+
"eslint-config-prettier": "^6.11.0",
52+
"eslint-plugin-prettier": "^3.1.3",
53+
"husky": "^4.2.5",
3954
"jest": "^24.9.0",
55+
"lint-staged": "^10.2.2",
56+
"prettier": "^2.0.5",
4057
"react-test-renderer": "^16.12.0",
4158
"rollup": "^1.29.0",
4259
"rollup-plugin-babel": "^4.3.3",
43-
"rollup-plugin-terser": "^5.2.0"
60+
"rollup-plugin-terser": "^5.2.0",
61+
"size-limit": "^4.5.0",
62+
"standard-version": "^8.0.0"
4463
},
4564
"peerDependencies": {
4665
"react": "^16.12.0"
4766
},
4867
"dependencies": {
4968
"fastest-validator": "1.4.1"
69+
},
70+
"husky": {
71+
"hooks": {
72+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
73+
"pre-commit": "lint-staged"
74+
}
75+
},
76+
"config": {
77+
"commitizen": {
78+
"path": "./node_modules/cz-conventional-changelog"
79+
}
80+
},
81+
"size-limit": [
82+
{
83+
"path": "dist/react-hooks-form-validator.es.js",
84+
"limit": "10 KB"
85+
}
86+
],
87+
"lint-staged": {
88+
"src/**/*.js": [
89+
"prettier --write",
90+
"eslint --fix",
91+
"git add"
92+
]
5093
}
5194
}

prettier.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
printWidth: 80,
3+
singleQuote: true,
4+
trailingComma: "all",
5+
arrowParens: "always",
6+
};

src/constants.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
const PER_FIELD_CONFIG = {
2-
defaultValue: { type: "any", optional: true },
2+
defaultValue: { type: 'any', optional: true },
33
required: [
4-
{ type: "boolean", optional: true },
4+
{ type: 'boolean', optional: true },
55
{
6-
type: "object",
6+
type: 'object',
77
optional: true,
88
props: {
9-
errorMsg: { type: "string" },
9+
errorMsg: { type: 'string' },
1010
},
1111
},
1212
],
1313
min: [
14-
{ type: "number", optional: true, positive: true, integer: true },
14+
{ type: 'number', optional: true, positive: true, integer: true },
1515
{
16-
type: "object",
16+
type: 'object',
1717
optional: true,
1818
props: {
19-
errorMsg: { type: "string" },
20-
length: { type: "number", positive: true, integer: true },
19+
errorMsg: { type: 'string' },
20+
length: { type: 'number', positive: true, integer: true },
2121
},
2222
},
2323
],
2424
max: [
25-
{ type: "number", optional: true, positive: true, integer: true },
25+
{ type: 'number', optional: true, positive: true, integer: true },
2626
{
27-
type: "object",
27+
type: 'object',
2828
optional: true,
2929
props: {
30-
errorMsg: { type: "string" },
31-
length: { type: "number", positive: true, integer: true },
30+
errorMsg: { type: 'string' },
31+
length: { type: 'number', positive: true, integer: true },
3232
},
3333
},
3434
],
3535
patterns: {
36-
type: "array",
36+
type: 'array',
3737
items: {
38-
type: "object",
38+
type: 'object',
3939
props: {
40-
regex: { type: "regex" },
41-
errorMsg: { type: "string" },
40+
regex: { type: 'regex' },
41+
errorMsg: { type: 'string' },
4242
},
4343
},
4444
optional: true,
4545
},
46-
validationFns: { type: "array", items: "function", optional: true },
47-
extraInfo: { type: "any", optional: true },
46+
validationFns: { type: 'array', items: 'function', optional: true },
47+
extraInfo: { type: 'any', optional: true },
4848
};
4949

5050
export const PER_FIELD_SCHEMA = {
@@ -55,9 +55,9 @@ export const PER_FIELD_SCHEMA = {
5555
export const FIELD_CONFIG_SCHEMA = {
5656
$$strict: true, // no additional properties allowed
5757
configs: {
58-
type: "array",
58+
type: 'array',
5959
items: {
60-
type: "object",
60+
type: 'object',
6161
props: PER_FIELD_CONFIG,
6262
},
6363
},

src/schema-validator.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import Validator from "fastest-validator";
1+
import Validator from 'fastest-validator';
22

33
const validator = new Validator({
44
messages: {
55
regex: "The '{field}' field must be an valid regex! Actual: {actual}",
66
},
77
});
88

9-
validator.add("regex", function ({ schema, messages }, path, context) {
9+
validator.add('regex', function ({ messages }) {
1010
return {
1111
source: `
1212
if (!(value instanceof RegExp))
1313
${this.makeError({
14-
type: "regex",
15-
actual: "value",
14+
type: 'regex',
15+
actual: 'value',
1616
messages,
1717
})}
1818

src/utilities.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { getSchemaValidator } from './schema-validator'
1+
import { getSchemaValidator } from './schema-validator';
22
import { PER_FIELD_SCHEMA, FIELD_CONFIG_SCHEMA } from './constants';
33

4-
const fieldSchemaValidator = getSchemaValidator(
5-
FIELD_CONFIG_SCHEMA,
6-
);
4+
const fieldSchemaValidator = getSchemaValidator(FIELD_CONFIG_SCHEMA);
75

8-
const perFieldSchemaValidator = getSchemaValidator(
9-
PER_FIELD_SCHEMA,
10-
);
6+
const perFieldSchemaValidator = getSchemaValidator(PER_FIELD_SCHEMA);
117

128
export function getDefaultValues(formFieldConfig) {
139
const defaultValues = {};

0 commit comments

Comments
 (0)