@invoicebox/ui 0.1.0-alpha.131 → 0.1.0-alpha.133
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/index.d.ts
CHANGED
|
@@ -51,3 +51,4 @@ export { useInputFocus } from './hooks/useInputFocus';
|
|
|
51
51
|
export { useUnupdatableHandler } from './hooks/useUnupdatableHandler';
|
|
52
52
|
export { breakpoints } from './breakpoints';
|
|
53
53
|
export { useMobile, useTablet, useLargeTablet, useMiniLaptop } from './hooks/useMedia';
|
|
54
|
+
export { validate } from './validate';
|
package/dist/index.js
CHANGED
|
@@ -267,6 +267,12 @@ Object.defineProperty(exports, "useUnupdatableHandler", {
|
|
|
267
267
|
return _useUnupdatableHandler.useUnupdatableHandler;
|
|
268
268
|
}
|
|
269
269
|
});
|
|
270
|
+
Object.defineProperty(exports, "validate", {
|
|
271
|
+
enumerable: true,
|
|
272
|
+
get: function get() {
|
|
273
|
+
return _validate.validate;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
270
276
|
var _Skeleton = require("./components/common/Skeleton");
|
|
271
277
|
var _InvoiceboxLoader = require("./components/common/InvoiceboxLoader");
|
|
272
278
|
var _Typography = require("./components/common/Typography");
|
|
@@ -304,6 +310,7 @@ var _useInputFocus = require("./hooks/useInputFocus");
|
|
|
304
310
|
var _useUnupdatableHandler = require("./hooks/useUnupdatableHandler");
|
|
305
311
|
var _breakpoints = require("./breakpoints");
|
|
306
312
|
var _useMedia = require("./hooks/useMedia");
|
|
313
|
+
var _validate = require("./validate");
|
|
307
314
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,no-undef
|
|
308
315
|
var fromEntries = require('object.fromentries');
|
|
309
316
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,no-undef
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
declare class Validate {
|
|
3
|
+
static vatNumber(value: string, path: string, countryId: string, createError: (params?: yup.CreateErrorOptions) => yup.ValidationError): true | yup.ValidationError;
|
|
4
|
+
static taxRegistrationReasonCode(value: string, path: string, createError: (params?: yup.CreateErrorOptions) => yup.ValidationError): true | yup.ValidationError;
|
|
5
|
+
}
|
|
6
|
+
export declare const validate: Validate;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validate = void 0;
|
|
7
|
+
var _vatNumberValidateHelpers = require("./utils/vatNumberValidateHelpers");
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
10
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
11
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
13
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
+
var Validate = /*#__PURE__*/function () {
|
|
15
|
+
function Validate() {
|
|
16
|
+
_classCallCheck(this, Validate);
|
|
17
|
+
}
|
|
18
|
+
return _createClass(Validate, null, [{
|
|
19
|
+
key: "vatNumber",
|
|
20
|
+
value: function vatNumber(value, path, countryId, createError) {
|
|
21
|
+
switch (countryId) {
|
|
22
|
+
case 'KAZ':
|
|
23
|
+
{
|
|
24
|
+
return (0, _vatNumberValidateHelpers.KAZValidate)(value, path, createError);
|
|
25
|
+
}
|
|
26
|
+
case 'BLR':
|
|
27
|
+
{
|
|
28
|
+
return (0, _vatNumberValidateHelpers.BLRValidate)(value, path, createError);
|
|
29
|
+
}
|
|
30
|
+
case 'MDA':
|
|
31
|
+
{
|
|
32
|
+
return (0, _vatNumberValidateHelpers.MDAValidate)(value, path, createError);
|
|
33
|
+
}
|
|
34
|
+
case 'AZE':
|
|
35
|
+
{
|
|
36
|
+
return (0, _vatNumberValidateHelpers.AZEValidate)(value, path, createError);
|
|
37
|
+
}
|
|
38
|
+
case 'ARM':
|
|
39
|
+
{
|
|
40
|
+
return (0, _vatNumberValidateHelpers.ARMValidate)(value, path, createError);
|
|
41
|
+
}
|
|
42
|
+
case 'UZB':
|
|
43
|
+
{
|
|
44
|
+
return (0, _vatNumberValidateHelpers.UZBValidate)(value, path, createError);
|
|
45
|
+
}
|
|
46
|
+
case 'TJK':
|
|
47
|
+
{
|
|
48
|
+
return (0, _vatNumberValidateHelpers.TJKValidate)(value, path, createError);
|
|
49
|
+
}
|
|
50
|
+
case 'KGZ':
|
|
51
|
+
{
|
|
52
|
+
return (0, _vatNumberValidateHelpers.KGZValidate)(value, path, createError);
|
|
53
|
+
}
|
|
54
|
+
default:
|
|
55
|
+
return (0, _vatNumberValidateHelpers.RUSValidate)(value, path, createError);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "taxRegistrationReasonCode",
|
|
60
|
+
value: function taxRegistrationReasonCode(value, path, createError) {
|
|
61
|
+
if (value === '') {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (value.length !== 9) {
|
|
65
|
+
return createError({
|
|
66
|
+
path: path,
|
|
67
|
+
message: 'КПП может состоять только из 9 знаков'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (!/^[0-9]{4}[0-9A-Z]{2}[0-9]{3}$/.test(value)) {
|
|
71
|
+
return createError({
|
|
72
|
+
path: path,
|
|
73
|
+
message: 'Неправильный формат КПП'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}]);
|
|
79
|
+
}();
|
|
80
|
+
var validate = exports.validate = new Validate();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
export declare const LENGTH_RUS_INDIVIDUAL_ENTREPRENEUR = 12;
|
|
3
|
+
export declare const LENGTH_RUS_LEGAL_ENTREPRENEUR = 10;
|
|
4
|
+
export declare const LENGTH_BLR_VAT_NUMBER = 9;
|
|
5
|
+
export declare const LENGTH_KAZ_VAT_NUMBER = 12;
|
|
6
|
+
export declare const LENGTH_AZE_VAT_NUMBER = 10;
|
|
7
|
+
export declare const LENGTH_ARM_VAT_NUMBER = 8;
|
|
8
|
+
export declare const LENGTH_KGZ_VAT_NUMBER = 14;
|
|
9
|
+
export declare const LENGTH_MDA_VAT_NUMBER = 13;
|
|
10
|
+
export declare const LENGTH_TJK_VAT_NUMBER_SHORT = 9;
|
|
11
|
+
export declare const LENGTH_TJK_VAT_NUMBER_LONG = 10;
|
|
12
|
+
export declare const LENGTH_UZB_VAT_NUMBER = 9;
|
|
13
|
+
export declare const BLRValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
14
|
+
export declare const AZEValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
15
|
+
export declare const MDAValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
16
|
+
export declare const KAZValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
17
|
+
export declare const ARMValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
18
|
+
export declare const UZBValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
19
|
+
export declare const TJKValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
20
|
+
export declare const KGZValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
21
|
+
export declare const RUSValidate: (value: string, path: string, createError: (params?: yup.CreateErrorOptions | undefined) => yup.ValidationError) => true | yup.ValidationError;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UZBValidate = exports.TJKValidate = exports.RUSValidate = exports.MDAValidate = exports.LENGTH_UZB_VAT_NUMBER = exports.LENGTH_TJK_VAT_NUMBER_SHORT = exports.LENGTH_TJK_VAT_NUMBER_LONG = exports.LENGTH_RUS_LEGAL_ENTREPRENEUR = exports.LENGTH_RUS_INDIVIDUAL_ENTREPRENEUR = exports.LENGTH_MDA_VAT_NUMBER = exports.LENGTH_KGZ_VAT_NUMBER = exports.LENGTH_KAZ_VAT_NUMBER = exports.LENGTH_BLR_VAT_NUMBER = exports.LENGTH_AZE_VAT_NUMBER = exports.LENGTH_ARM_VAT_NUMBER = exports.KGZValidate = exports.KAZValidate = exports.BLRValidate = exports.AZEValidate = exports.ARMValidate = void 0;
|
|
7
|
+
var LENGTH_RUS_INDIVIDUAL_ENTREPRENEUR = exports.LENGTH_RUS_INDIVIDUAL_ENTREPRENEUR = 12;
|
|
8
|
+
var LENGTH_RUS_LEGAL_ENTREPRENEUR = exports.LENGTH_RUS_LEGAL_ENTREPRENEUR = 10;
|
|
9
|
+
var LENGTH_BLR_VAT_NUMBER = exports.LENGTH_BLR_VAT_NUMBER = 9;
|
|
10
|
+
var LENGTH_KAZ_VAT_NUMBER = exports.LENGTH_KAZ_VAT_NUMBER = 12;
|
|
11
|
+
var LENGTH_AZE_VAT_NUMBER = exports.LENGTH_AZE_VAT_NUMBER = 10;
|
|
12
|
+
var LENGTH_ARM_VAT_NUMBER = exports.LENGTH_ARM_VAT_NUMBER = 8;
|
|
13
|
+
var LENGTH_KGZ_VAT_NUMBER = exports.LENGTH_KGZ_VAT_NUMBER = 14;
|
|
14
|
+
var LENGTH_MDA_VAT_NUMBER = exports.LENGTH_MDA_VAT_NUMBER = 13;
|
|
15
|
+
var LENGTH_TJK_VAT_NUMBER_SHORT = exports.LENGTH_TJK_VAT_NUMBER_SHORT = 9;
|
|
16
|
+
var LENGTH_TJK_VAT_NUMBER_LONG = exports.LENGTH_TJK_VAT_NUMBER_LONG = 10;
|
|
17
|
+
var LENGTH_UZB_VAT_NUMBER = exports.LENGTH_UZB_VAT_NUMBER = 9;
|
|
18
|
+
var checkDigitFunc = function checkDigitFunc(inn, coefficients, valueDigit) {
|
|
19
|
+
return coefficients.reduce(function (sum, current, index) {
|
|
20
|
+
return sum + current * Number(inn[index]);
|
|
21
|
+
}, 0) % valueDigit;
|
|
22
|
+
};
|
|
23
|
+
var checkKaz = function checkKaz(value, path, createError) {
|
|
24
|
+
var checkNumber = checkDigitFunc(value, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 11);
|
|
25
|
+
if (checkNumber === 10) {
|
|
26
|
+
var replyCheckNumber = checkDigitFunc(value, [3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2], 11);
|
|
27
|
+
if (replyCheckNumber === 10 || replyCheckNumber !== Number(value[11])) {
|
|
28
|
+
return createError({
|
|
29
|
+
path: path,
|
|
30
|
+
message: 'Неверное контрольное число'
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (checkNumber !== Number(value[11])) {
|
|
36
|
+
return createError({
|
|
37
|
+
path: path,
|
|
38
|
+
message: 'Неверное контрольное число'
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
var BLRValidate = exports.BLRValidate = function BLRValidate(value, path, createError) {
|
|
44
|
+
if (value.length !== LENGTH_BLR_VAT_NUMBER) {
|
|
45
|
+
return createError({
|
|
46
|
+
path: path,
|
|
47
|
+
message: 'УНБ должен состоять из 9 цифр'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (checkDigitFunc(value, [29, 23, 19, 17, 13, 7, 5, 3], 11) === Number(value[8])) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return createError({
|
|
54
|
+
path: path,
|
|
55
|
+
message: 'Неверное контрольное число'
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
var AZEValidate = exports.AZEValidate = function AZEValidate(value, path, createError) {
|
|
59
|
+
if (value.length !== LENGTH_AZE_VAT_NUMBER) {
|
|
60
|
+
return createError({
|
|
61
|
+
path: path,
|
|
62
|
+
message: 'ИНН должен состоять из 10 цифр'
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (Number(value[value.length - 1]) === 1) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return createError({
|
|
69
|
+
path: path,
|
|
70
|
+
message: 'Неверное контрольное число'
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
var MDAValidate = exports.MDAValidate = function MDAValidate(value, path, createError) {
|
|
74
|
+
if (value.length !== LENGTH_MDA_VAT_NUMBER) {
|
|
75
|
+
return createError({
|
|
76
|
+
path: path,
|
|
77
|
+
message: 'IDNO должен состоять из 13 цифр'
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (Number(value[0]) === 1 && checkDigitFunc(value, [7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1], 10) === Number(value[12])) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return createError({
|
|
84
|
+
path: path,
|
|
85
|
+
message: 'Неверное контрольное число'
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
var KAZValidate = exports.KAZValidate = function KAZValidate(value, path, createError) {
|
|
89
|
+
if (value.length !== LENGTH_KAZ_VAT_NUMBER) {
|
|
90
|
+
return createError({
|
|
91
|
+
path: path,
|
|
92
|
+
message: 'ИИН/БИН должен состоять из 12 цифр'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
var iinFourthValue = ['0', '1', '2', '3'];
|
|
96
|
+
var binFourthValue = ['4', '5', '6'];
|
|
97
|
+
if (iinFourthValue.includes(value[4])) {
|
|
98
|
+
var centuryBirthdayCode = value[6];
|
|
99
|
+
if (Number(centuryBirthdayCode) > 6 || Number(value.substring(2, 3)) > 12 || Number(value.substring(0, 1)) > 31) {
|
|
100
|
+
return createError({
|
|
101
|
+
path: path,
|
|
102
|
+
message: 'Неверное контрольное число'
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return checkKaz(value, path, createError);
|
|
106
|
+
}
|
|
107
|
+
if (binFourthValue.includes(value[4])) {
|
|
108
|
+
return checkKaz(value, path, createError);
|
|
109
|
+
}
|
|
110
|
+
return createError({
|
|
111
|
+
path: path,
|
|
112
|
+
message: 'Неверное контрольное число'
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
var ARMValidate = exports.ARMValidate = function ARMValidate(value, path, createError) {
|
|
116
|
+
if (value.length !== LENGTH_ARM_VAT_NUMBER) {
|
|
117
|
+
return createError({
|
|
118
|
+
path: path,
|
|
119
|
+
message: 'УНН должен состоять из 8 цифр'
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
};
|
|
124
|
+
var UZBValidate = exports.UZBValidate = function UZBValidate(value, path, createError) {
|
|
125
|
+
if (value.length !== LENGTH_UZB_VAT_NUMBER) {
|
|
126
|
+
return createError({
|
|
127
|
+
path: path,
|
|
128
|
+
message: 'ИНН должен состоять из 9 цифр'
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
};
|
|
133
|
+
var TJKValidate = exports.TJKValidate = function TJKValidate(value, path, createError) {
|
|
134
|
+
if (value.length !== LENGTH_TJK_VAT_NUMBER_LONG && value.length !== LENGTH_TJK_VAT_NUMBER_SHORT) {
|
|
135
|
+
return createError({
|
|
136
|
+
path: path,
|
|
137
|
+
message: 'ИНН должен состоять из 9 или 10 цифр'
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
142
|
+
var KGZValidate = exports.KGZValidate = function KGZValidate(value, path, createError) {
|
|
143
|
+
if (value.length !== LENGTH_KGZ_VAT_NUMBER) {
|
|
144
|
+
return createError({
|
|
145
|
+
path: path,
|
|
146
|
+
message: 'ИНН должен состоять из 14 цифр'
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
};
|
|
151
|
+
var RUSValidate = exports.RUSValidate = function RUSValidate(value, path, createError) {
|
|
152
|
+
if ([LENGTH_RUS_LEGAL_ENTREPRENEUR, LENGTH_RUS_INDIVIDUAL_ENTREPRENEUR].indexOf(value.length) === -1) {
|
|
153
|
+
return createError({
|
|
154
|
+
path: path,
|
|
155
|
+
message: 'ИНН должен состоять из 10 или 12 цифр'
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
switch (value.length) {
|
|
159
|
+
case LENGTH_RUS_LEGAL_ENTREPRENEUR:
|
|
160
|
+
{
|
|
161
|
+
var n10 = checkDigitFunc(value, [2, 4, 10, 3, 5, 9, 4, 6, 8], 11) % 10;
|
|
162
|
+
if (n10 === parseInt(value[9], 10)) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case LENGTH_RUS_INDIVIDUAL_ENTREPRENEUR:
|
|
168
|
+
{
|
|
169
|
+
var n11 = checkDigitFunc(value, [7, 2, 4, 10, 3, 5, 9, 4, 6, 8], 11) % 10;
|
|
170
|
+
var n12 = checkDigitFunc(value, [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8], 11) % 10;
|
|
171
|
+
if (n11 === parseInt(value[10], 10) && n12 === parseInt(value[11], 10)) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
return createError({
|
|
178
|
+
path: path,
|
|
179
|
+
message: 'Неверное контрольное число'
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return createError({
|
|
183
|
+
path: path,
|
|
184
|
+
message: 'Неверное контрольное число'
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@invoicebox/ui",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.133",
|
|
4
4
|
"description": "Invoicebox UI",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -63,7 +63,8 @@
|
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"react": "^18.2.0",
|
|
66
|
-
"styled-components": "^6.1.8"
|
|
66
|
+
"styled-components": "^6.1.8",
|
|
67
|
+
"yup": "^0.32.11"
|
|
67
68
|
},
|
|
68
69
|
"engines": {
|
|
69
70
|
"node": ">=16.0.0"
|