@ttoss/forms 0.23.0 → 0.23.2
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/dist/Brazil/index.d.mts +2 -1
- package/dist/Brazil/index.d.ts +2 -1
- package/dist/Brazil/index.js +54 -6
- package/dist/MultistepForm/index.d.mts +1 -0
- package/dist/MultistepForm/index.d.ts +1 -0
- package/dist/MultistepForm/index.js +177 -124
- package/dist/esm/Brazil/index.js +8 -39
- package/dist/esm/MultistepForm/index.js +1 -1
- package/dist/esm/{chunk-5SH4STWG.js → chunk-J6VGD2RH.js} +141 -60
- package/dist/esm/index.js +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +130 -77
- package/dist/typings.d-KteERiXO.d.mts +12 -0
- package/dist/typings.d-KteERiXO.d.ts +12 -0
- package/package.json +12 -12
- package/src/Brazil/FormFieldCNPJ.tsx +56 -0
- package/src/Brazil/index.ts +1 -0
- package/src/index.ts +1 -3
- package/src/yup/schema.ts +12 -0
- package/src/yup/typings.d.ts +14 -0
- package/src/yup/yup.ts +4 -0
- /package/src/{i18n.ts → yup/i18n.ts} +0 -0
|
@@ -7,6 +7,62 @@ export type FormFieldCNPJProps = {
|
|
|
7
7
|
name: string;
|
|
8
8
|
} & Partial<PatternFormatProps>;
|
|
9
9
|
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
export const isCnpjValid = (cnpj: any) => {
|
|
12
|
+
if (cnpj?.length != 14) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (
|
|
17
|
+
cnpj == '00000000000000' ||
|
|
18
|
+
cnpj == '11111111111111' ||
|
|
19
|
+
cnpj == '22222222222222' ||
|
|
20
|
+
cnpj == '33333333333333' ||
|
|
21
|
+
cnpj == '44444444444444' ||
|
|
22
|
+
cnpj == '55555555555555' ||
|
|
23
|
+
cnpj == '66666666666666' ||
|
|
24
|
+
cnpj == '77777777777777' ||
|
|
25
|
+
cnpj == '88888888888888' ||
|
|
26
|
+
cnpj == '99999999999999'
|
|
27
|
+
) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Valida DVs
|
|
32
|
+
let size = cnpj.length - 2;
|
|
33
|
+
let numbers = cnpj.substring(0, size);
|
|
34
|
+
const digits = cnpj.substring(size);
|
|
35
|
+
let soma = 0;
|
|
36
|
+
let pos = size - 7;
|
|
37
|
+
for (let i = size; i >= 1; i--) {
|
|
38
|
+
soma += numbers.charAt(size - i) * pos--;
|
|
39
|
+
if (pos < 2) {
|
|
40
|
+
pos = 9;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
let result = soma % 11 < 2 ? 0 : 11 - (soma % 11);
|
|
44
|
+
if (result != digits.charAt(0)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
size = size + 1;
|
|
49
|
+
numbers = cnpj.substring(0, size);
|
|
50
|
+
soma = 0;
|
|
51
|
+
pos = size - 7;
|
|
52
|
+
for (let i = size; i >= 1; i--) {
|
|
53
|
+
soma += numbers.charAt(size - i) * pos--;
|
|
54
|
+
if (pos < 2) {
|
|
55
|
+
pos = 9;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
result = soma % 11 < 2 ? 0 : 11 - (soma % 11);
|
|
59
|
+
if (result != digits.charAt(1)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
|
|
10
66
|
export const FormFieldCNPJ = ({
|
|
11
67
|
label,
|
|
12
68
|
name,
|
package/src/Brazil/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { isCnpjValid } from '../Brazil/FormFieldCNPJ';
|
|
3
|
+
/**
|
|
4
|
+
* Need this import to extend yup types on build time.
|
|
5
|
+
*/
|
|
6
|
+
import './typings.d';
|
|
7
|
+
|
|
8
|
+
yup.addMethod(yup.string, 'cnpj', function () {
|
|
9
|
+
return this.test('valid-cnpj', 'Invalid CNPJ', (value) => {
|
|
10
|
+
return isCnpjValid(value);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnyObject, Flags, Maybe, Schema } from 'yup';
|
|
2
|
+
|
|
3
|
+
declare module 'yup' {
|
|
4
|
+
interface StringSchema<
|
|
5
|
+
TType extends Maybe<string> = string | undefined,
|
|
6
|
+
TContext extends AnyObject = AnyObject,
|
|
7
|
+
TDefault = undefined,
|
|
8
|
+
TFlags extends Flags = '',
|
|
9
|
+
> extends Schema<TType, TContext, TDefault, TFlags> {
|
|
10
|
+
cnpj(): this;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {};
|
package/src/yup/yup.ts
ADDED
|
File without changes
|