Skip to content

Commit 254dc00

Browse files
committed
chore: add prettier script
1 parent 44f0e70 commit 254dc00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1765
-1309
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ webpack.config.js
66
jestTestFile.js
77
BackupCopia
88
.eslintrc.js
9+
jest.config.js

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
name: Bug report
33
about: Create a report to help us improve
4-
title: ''
5-
labels: ''
6-
assignees: ''
7-
4+
title: ""
5+
labels: ""
6+
assignees: ""
87
---
98

109
**Describe the bug**
1110
A clear and concise description of what the bug is.
1211

1312
**To Reproduce**
1413
Steps to reproduce the behavior:
14+
1515
1. Go to '...'
1616
2. Click on '....'
1717
3. Scroll down to '....'
@@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
2424
If applicable, add screenshots to help explain your problem.
2525

2626
**Desktop (please complete the following information):**
27-
- OS: [e.g. iOS]
28-
- Browser [e.g. chrome, safari]
29-
- Version [e.g. 22]
27+
28+
- OS: [e.g. iOS]
29+
- Browser [e.g. chrome, safari]
30+
- Version [e.g. 22]
3031

3132
**Smartphone (please complete the following information):**
32-
- Device: [e.g. iPhone6]
33-
- OS: [e.g. iOS8.1]
34-
- Browser [e.g. stock browser, safari]
35-
- Version [e.g. 22]
33+
34+
- Device: [e.g. iPhone6]
35+
- OS: [e.g. iOS8.1]
36+
- Browser [e.g. stock browser, safari]
37+
- Version [e.g. 22]
3638

3739
**Additional context**
3840
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
name: Feature request
33
about: Suggest an idea for this project
4-
title: ''
5-
labels: ''
6-
assignees: ''
7-
4+
title: ""
5+
labels: ""
6+
assignees: ""
87
---
98

109
**Is your feature request related to a problem? Please describe.**

.github/workflows/typescript-pr-check.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Typescript Pull Request Check
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66

77
pull_request:
8-
branches: [ main ]
8+
branches: [main]
99

1010
# Allows you to run this workflow manually from the Actions tab
1111
workflow_dispatch:
@@ -15,13 +15,13 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v4
19-
- uses: actions/setup-node@v3
20-
with:
21-
node-version: 20
22-
registry-url: https://registry.npmjs.org/
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-node@v3
20+
with:
21+
node-version: 20
22+
registry-url: https://registry.npmjs.org/
2323

24-
- name: Test
25-
run: |
24+
- name: Test
25+
run: |
2626
yarn install
2727
yarn pr-check

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"code-runner.executorMap": {
3-
"typescript": "npx ts-node",
4-
},
3+
"typescript": "npx ts-node"
4+
}
55
}

README.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ Feel free to find bugs and report them to me. Your feedback is highly appreciate
1616
## CDNs
1717

1818
jsDelivr:
19+
1920
```bash
2021
https://cdn.jsdelivr.net/npm/multiform-validator@2.1.3/dist/bundle.min.js
2122
```
23+
2224
```html
2325
<script src="https://cdn.jsdelivr.net/npm/multiform-validator@2.1.3/dist/bundle.min.js"></script>
2426
```
2527

2628
unpkg:
29+
2730
```bash
2831
https://unpkg.com/multiform-validator@2.1.3/dist/bundle.js
2932
```
33+
3034
```html
3135
<script src="https://unpkg.com/multiform-validator@2.1.3/dist/bundle.js"></script>
3236
```
@@ -36,13 +40,11 @@ https://unpkg.com/multiform-validator@2.1.3/dist/bundle.js
3640
```html
3741
<script src="https://cdn.jsdelivr.net/npm/multiform-validator@2.1.3/dist/bundle.min.js"></script>
3842
<script>
39-
40-
const emailResult = isEmail('123456');
41-
const cpfResult = cpfIsValid('123456');
43+
const emailResult = isEmail("123456");
44+
const cpfResult = cpfIsValid("123456");
4245
4346
console.log(emailResult); // returns false
4447
console.log(cpfResult.isValid); // returns false
45-
4648
</script>
4749
```
4850

@@ -100,6 +102,7 @@ This package contains various modules for validating different types of data. Be
100102
- **validateUSPhoneNumber**: US phone number validation.
101103

102104
### You can use it in React Native, Angular, any javascript framework or any javascript or typescript code.
105+
103106
#### Example using Reactjs:
104107

105108
![Example using Reactjs](https://raw.githubusercontent.com/Multiform-Validator/docs/main/images/exampleWithReactjs.png)
@@ -109,19 +112,17 @@ This package contains various modules for validating different types of data. Be
109112
### For better information, read the documentation
110113

111114
```javascript
112-
113-
const validator = require('multiform-validator');
115+
const validator = require("multiform-validator");
114116
// or
115-
import validator from 'multiform-validator';
117+
import validator from "multiform-validator";
116118

117-
or
119+
or;
118120

119121
// Attention, FUNCTION_NAME is not a valid function name! It is just an example of how to import the functions.
120122

121-
const { FUNCTION_NAME } = require('multiform-validator');
123+
const { FUNCTION_NAME } = require("multiform-validator");
122124
// or
123-
import { FUNCTION_NAME } from 'multiform-validator';
124-
125+
import { FUNCTION_NAME } from "multiform-validator";
125126
```
126127

127128
```javascript
@@ -144,32 +145,36 @@ validator.FUNCTION_NAME.errorMsg = 'ErrorMsg' // You can customize errors
144145
```
145146

146147
## Documentation
148+
147149
### https://multiformvalidator.netlify.app
148150

149151
```javascript
150-
151-
const { validateEmail } = require('multiform-validator');
152+
const { validateEmail } = require("multiform-validator");
152153
// or
153-
import { validateEmail } from 'multiform-validator';
154+
import { validateEmail } from "multiform-validator";
154155

155156
// It has many more validations, you can read the documentation or
156157
// do several tests to learn how to use the library in the best possible way.
157158

158159
// Two last parameters are optional
159-
console.log(validateEmail('email@email.com', { maxLength: 30, country: 'br' }).isValid); // returns false
160-
console.log(validateEmail('email@email.com.br', { maxLength: 30, country: 'br' }).isValid); // returns true
161-
console.log(validateEmail('email@email.com', { maxLength: 30 }).isValid); // returns true
160+
console.log(
161+
validateEmail("email@email.com", { maxLength: 30, country: "br" }).isValid,
162+
); // returns false
163+
console.log(
164+
validateEmail("email@email.com.br", { maxLength: 30, country: "br" }).isValid,
165+
); // returns true
166+
console.log(validateEmail("email@email.com", { maxLength: 30 }).isValid); // returns true
162167

163168
// All examples return default messages, below is an example setting your own messages
164169

165170
// If you want to use a default parameter, use null.
166171

167-
const validationResult = validateEmail('email@email.com', { maxLength: 30 });
172+
const validationResult = validateEmail("email@email.com", { maxLength: 30 });
168173

169174
if (validationResult.isValid) {
170-
console.log('0 errors');
175+
console.log("0 errors");
171176
} else {
172-
console.log(validationResult.errorMsg); // returns the error
177+
console.log(validationResult.errorMsg); // returns the error
173178
}
174179

175180
// or
@@ -180,11 +185,10 @@ const validationResult = validateEmail("1email@email.com", {
180185
});
181186

182187
if (validationResult.isValid) {
183-
console.log('0 errors');
188+
console.log("0 errors");
184189
} else {
185-
console.log(validationResult.errorMsg); // Return 'This is an invalid email with my own errors'
190+
console.log(validationResult.errorMsg); // Return 'This is an invalid email with my own errors'
186191
}
187-
188192
```
189193

190194
Feel free to explore the various functions and experiment with different inputs to understand their behavior. If you encounter any issues or have suggestions, don't hesitate to reach out to me. Your feedback is valuable and helps improve the package. Happy coding!

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} */
22
module.exports = {
3-
preset: 'ts-jest',
4-
testEnvironment: 'node',
3+
preset: "ts-jest",
4+
testEnvironment: "node",
55
};

jestTestFile.js

Whitespace-only changes.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"build:browser": "webpack",
1515
"build": "yarn build:types && yarn build:src && yarn build:browser",
1616
"lint": "eslint . --ext .ts",
17-
"pr-check": "yarn lint && yarn build && yarn test"
17+
"prettier": "prettier --write .",
18+
"pr-check": "yarn prettier && yarn lint && yarn build && yarn test"
1819
},
1920
"repository": {
2021
"type": "git",

tests/src/cnpjValidator.test.ts

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,70 @@
1-
import cnpjIsValid from '../../src/cnpjValidator';
2-
3-
describe('cnpjIsValid function', () => {
4-
test('should validate a valid CNPJ', () => {
5-
const result = cnpjIsValid('72.501.263/0001-40');
6-
expect(result.isValid).toBe(false);
7-
expect(result.errorMsg).toBe("CNPJ is not valid");
8-
});
9-
10-
test('should invalidate an invalid CNPJ', () => {
11-
const result = cnpjIsValid('12.345.678/0001-91');
12-
expect(result.isValid).toBe(false);
13-
expect(result.errorMsg).toBe('CNPJ is not valid');
14-
});
15-
16-
test('should invalidate a CNPJ with incorrect length', () => {
17-
const result = cnpjIsValid('1234567890123');
18-
expect(result.isValid).toBe(false);
19-
expect(result.errorMsg).toBe('CNPJ must have 14 numerical digits');
20-
});
21-
22-
test('should invalidate a CNPJ with non-digit characters', () => {
23-
const result = cnpjIsValid('72.501.263/0001-4A');
24-
expect(result.isValid).toBe(false);
25-
expect(result.errorMsg).toBe('CNPJ is not valid');
26-
});
27-
28-
test('should invalidate an empty CNPJ', () => {
29-
const result = cnpjIsValid('');
30-
expect(result.isValid).toBe(false);
31-
expect(result.errorMsg).toBe('CNPJ invalid');
32-
});
33-
34-
test('should throw an error if input is not a string', () => {
35-
expect(() => {
36-
cnpjIsValid(12345678901234 as any);
37-
}).toThrow('The input should be a string.');
38-
});
39-
40-
test('should throw an error if errorMsg is not an array', () => {
41-
expect(() => {
42-
cnpjIsValid('72.501.263/0001-40', 'error message' as any);
43-
}).toThrow('Must be an Array');
44-
});
45-
46-
test('should throw an error if errorMsg contains non-string values', () => {
47-
expect(() => {
48-
cnpjIsValid('72.501.263/0001-40', [123, 'error message'] as any);
49-
}).toThrow('All values within the array must be strings or null/undefined.');
50-
});
51-
52-
test('should return custom error messages', () => {
53-
const result = cnpjIsValid('12.345.678/0001-91', ['Custom invalid message', 'Custom length message', 'Custom not valid message', 'Custom unknown error message']);
54-
expect(result.isValid).toBe(false);
55-
expect(result.errorMsg).toBe('Custom not valid message');
56-
});
57-
58-
test('should return false when all digits are repeated', () => {
59-
const result = cnpjIsValid('11.111.111/1111-11');
1+
import cnpjIsValid from "../../src/cnpjValidator";
2+
3+
describe("cnpjIsValid function", () => {
4+
test("should validate a valid CNPJ", () => {
5+
const result = cnpjIsValid("72.501.263/0001-40");
6+
expect(result.isValid).toBe(false);
7+
expect(result.errorMsg).toBe("CNPJ is not valid");
8+
});
9+
10+
test("should invalidate an invalid CNPJ", () => {
11+
const result = cnpjIsValid("12.345.678/0001-91");
12+
expect(result.isValid).toBe(false);
13+
expect(result.errorMsg).toBe("CNPJ is not valid");
14+
});
15+
16+
test("should invalidate a CNPJ with incorrect length", () => {
17+
const result = cnpjIsValid("1234567890123");
18+
expect(result.isValid).toBe(false);
19+
expect(result.errorMsg).toBe("CNPJ must have 14 numerical digits");
20+
});
21+
22+
test("should invalidate a CNPJ with non-digit characters", () => {
23+
const result = cnpjIsValid("72.501.263/0001-4A");
24+
expect(result.isValid).toBe(false);
25+
expect(result.errorMsg).toBe("CNPJ is not valid");
26+
});
27+
28+
test("should invalidate an empty CNPJ", () => {
29+
const result = cnpjIsValid("");
30+
expect(result.isValid).toBe(false);
31+
expect(result.errorMsg).toBe("CNPJ invalid");
32+
});
33+
34+
test("should throw an error if input is not a string", () => {
35+
expect(() => {
36+
cnpjIsValid(12345678901234 as any);
37+
}).toThrow("The input should be a string.");
38+
});
39+
40+
test("should throw an error if errorMsg is not an array", () => {
41+
expect(() => {
42+
cnpjIsValid("72.501.263/0001-40", "error message" as any);
43+
}).toThrow("Must be an Array");
44+
});
45+
46+
test("should throw an error if errorMsg contains non-string values", () => {
47+
expect(() => {
48+
cnpjIsValid("72.501.263/0001-40", [123, "error message"] as any);
49+
}).toThrow(
50+
"All values within the array must be strings or null/undefined.",
51+
);
52+
});
53+
54+
test("should return custom error messages", () => {
55+
const result = cnpjIsValid("12.345.678/0001-91", [
56+
"Custom invalid message",
57+
"Custom length message",
58+
"Custom not valid message",
59+
"Custom unknown error message",
60+
]);
61+
expect(result.isValid).toBe(false);
62+
expect(result.errorMsg).toBe("Custom not valid message");
63+
});
64+
65+
test("should return false when all digits are repeated", () => {
66+
const result = cnpjIsValid("11.111.111/1111-11");
6067
expect(result.isValid).toBe(false);
61-
expect(result.errorMsg).toBe('CNPJ is not valid');
68+
expect(result.errorMsg).toBe("CNPJ is not valid");
6269
});
6370
});

0 commit comments

Comments
 (0)