@astral/validations 2.10.4 → 2.11.0

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/index.d.ts CHANGED
@@ -17,3 +17,4 @@ export * from './isDate';
17
17
  export * from './isSNILS';
18
18
  export * from './composeSome';
19
19
  export * from './isEmail';
20
+ export * from './isKPP';
package/index.js CHANGED
@@ -17,3 +17,4 @@ export * from './isDate';
17
17
  export * from './isSNILS';
18
18
  export * from './composeSome';
19
19
  export * from './isEmail';
20
+ export * from './isKPP';
@@ -1,5 +1,5 @@
1
1
  import { createRule } from '../createRule';
2
- import { isEmptyString } from '../utils';
2
+ import { isEmptyString, isStringOfZeros } from '../utils';
3
3
  export const IS_INNIP_DEFAULT_MESSAGE = 'Некорректный ИНН ИП';
4
4
  const INNIP_LENGTH = 12;
5
5
  const FIRST_INN_UL_DECODING = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
@@ -22,6 +22,9 @@ export const isINNIP = createRule(({ message = IS_INNIP_DEFAULT_MESSAGE } = {})
22
22
  if (isEmptyString(value)) {
23
23
  return undefined;
24
24
  }
25
+ if (isStringOfZeros(value)) {
26
+ return message;
27
+ }
25
28
  if (typeof value === 'string') {
26
29
  if (value.length !== INNIP_LENGTH) {
27
30
  return message;
@@ -1,5 +1,5 @@
1
1
  import { createRule } from '../createRule';
2
- import { isEmptyString } from '../utils';
2
+ import { isEmptyString, isStringOfZeros } from '../utils';
3
3
  export const IS_INNUL_DEFAULT_MESSAGE = 'Некорректный ИНН ЮЛ';
4
4
  const INNUL_LENGTH = 10;
5
5
  const INN_UL_DECODING = [2, 4, 10, 3, 5, 9, 4, 6, 8];
@@ -16,6 +16,9 @@ export const isINNUL = createRule(({ message = IS_INNUL_DEFAULT_MESSAGE } = {})
16
16
  if (isEmptyString(value)) {
17
17
  return undefined;
18
18
  }
19
+ if (isStringOfZeros(value)) {
20
+ return message;
21
+ }
19
22
  if (typeof value === 'string') {
20
23
  if (value.length !== INNUL_LENGTH) {
21
24
  return message;
@@ -0,0 +1 @@
1
+ export * from './isKPP';
package/isKPP/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './isKPP';
@@ -0,0 +1,7 @@
1
+ export declare const IS_KPP_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u041A\u041F\u041F";
2
+ export declare const KPP_REGEX: RegExp;
3
+ export declare const isKPP: (params?: ({
4
+ message?: string | undefined;
5
+ } & {
6
+ exclude?: ((value: unknown) => boolean) | undefined;
7
+ }) | undefined) => import("..").InitializedRule;
package/isKPP/isKPP.js ADDED
@@ -0,0 +1,19 @@
1
+ import { createRule } from '../createRule';
2
+ import { isEmptyString, isStringOfZeros } from '../utils';
3
+ export const IS_KPP_DEFAULT_MESSAGE = 'Некорректный КПП';
4
+ export const KPP_REGEX = /^(\d{4}([A-Z]|\d){2}\d{3})$/;
5
+ export const isKPP = createRule(({ message = IS_KPP_DEFAULT_MESSAGE } = {}) => (value) => {
6
+ if (isEmptyString(value)) {
7
+ return undefined;
8
+ }
9
+ if (isStringOfZeros(value)) {
10
+ return message;
11
+ }
12
+ if (typeof value !== 'string') {
13
+ return message;
14
+ }
15
+ if (!KPP_REGEX.test(value)) {
16
+ return message;
17
+ }
18
+ return undefined;
19
+ });
@@ -1,5 +1,5 @@
1
1
  import { createRule } from '../createRule';
2
- import { isEmptyString } from '../utils';
2
+ import { isEmptyString, isStringOfZeros } from '../utils';
3
3
  export const IS_OGRNIP_DEFAULT_MESSAGE = 'Некорректный ОГРН ИП';
4
4
  const OGRNIP_LENGTH = 15;
5
5
  /**
@@ -10,6 +10,9 @@ export const isOGRNIP = createRule(({ message = IS_OGRNIP_DEFAULT_MESSAGE } = {}
10
10
  if (isEmptyString(value)) {
11
11
  return undefined;
12
12
  }
13
+ if (isStringOfZeros(value)) {
14
+ return message;
15
+ }
13
16
  if (typeof value === 'string') {
14
17
  if (value.length !== OGRNIP_LENGTH) {
15
18
  return message;
@@ -1,5 +1,5 @@
1
1
  import { createRule } from '../createRule';
2
- import { isEmptyString } from '../utils';
2
+ import { isEmptyString, isStringOfZeros } from '../utils';
3
3
  export const IS_OGRNUL_DEFAULT_MESSAGE = 'Некорректный ОГРН ЮЛ';
4
4
  const OGRNUL_LENGTH = 13;
5
5
  /**
@@ -10,6 +10,9 @@ export const isOGRNUL = createRule(({ message = IS_OGRNUL_DEFAULT_MESSAGE } = {}
10
10
  if (isEmptyString(value)) {
11
11
  return undefined;
12
12
  }
13
+ if (isStringOfZeros(value)) {
14
+ return message;
15
+ }
13
16
  if (typeof value === 'string') {
14
17
  if (value.length !== OGRNUL_LENGTH) {
15
18
  return message;
@@ -1,5 +1,5 @@
1
1
  import { createRule } from '../createRule';
2
- import { isEmptyString } from '../utils';
2
+ import { isEmptyString, isStringOfZeros } from '../utils';
3
3
  export const IS_SNILS_DEFAULT_MESSAGE = 'Некорректный СНИЛС';
4
4
  const RESTRICTED_VALUES = ['00000000000'];
5
5
  const DEFAULT_CHECKED_SUM = [0, 100, 101];
@@ -24,6 +24,9 @@ export const isSNILS = createRule(({ message = IS_SNILS_DEFAULT_MESSAGE } = {})
24
24
  if (isEmptyString(value)) {
25
25
  return undefined;
26
26
  }
27
+ if (isStringOfZeros(value)) {
28
+ return message;
29
+ }
27
30
  if (typeof value !== 'string') {
28
31
  return message;
29
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astral/validations",
3
- "version": "2.10.4",
3
+ "version": "2.11.0",
4
4
  "browser": "./index.js",
5
5
  "main": "./index.js",
6
6
  "dependencies": {
package/utils/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './isEmptyString';
2
+ export * from './isStringOfZeros';
package/utils/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from './isEmptyString';
2
+ export * from './isStringOfZeros';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @description Используется для проверки того, состоит ли строка целиком из 0
3
+ */
4
+ export declare const isStringOfZeros: (value: unknown) => boolean;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description Используется для проверки того, состоит ли строка целиком из 0
3
+ */
4
+ export const isStringOfZeros = (value) => {
5
+ if (value && typeof value === 'string') {
6
+ return !Boolean(value.replaceAll('0', ''));
7
+ }
8
+ return false;
9
+ };