@mmb-digital/shared-libs-auto 0.0.20 → 0.0.22
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/README.md +19 -0
- package/dist/formatters/formatBytes/formatBytes.js +6 -0
- package/dist/formatters/formatBytes/formatBytes.test.js +9 -0
- package/dist/formatters/formatCZSKPhoneNumber/formatCZSKPhoneNumber.js +1 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types/Prettify/Prettify.d.ts +19 -0
- package/dist/types/Prettify/Prettify.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/arrayBufferToBase64/arrayBufferToBase64.js +1 -1
- package/dist/utils/base64ToArrayBuffer/base64ToArrayBuffer.js +1 -1
- package/dist/utils/chunkArray/chunkArray.d.ts +1 -1
- package/dist/utils/downloadFile/downloadFile.test.js +25 -25
- package/dist/utils/downloadFile/utils/processDownload.js +5 -5
- package/dist/utils/joinBy/joinBy.d.ts +1 -1
- package/dist/utils/joinBy/joinBy.js +1 -1
- package/dist/utils/mapObjectKeys/mapObjectKeys.js +1 -1
- package/dist/utils/mapObjectKeys/mapObjectKeys.test.js +7 -0
- package/dist/utils/mergeDeep/mergeDeep.js +2 -3
- package/dist/utils/openFile/openFile.test.js +7 -7
- package/dist/utils/openFile/utils/innerOpenFile.js +2 -2
- package/dist/utils/scrollToBottom/scrollToBottom.js +3 -3
- package/dist/utils/scrollToBottom/scrollToBottom.test.js +4 -4
- package/dist/utils/scrollToTop/scrollToTop.js +2 -2
- package/dist/utils/scrollToTop/scrollToTop.test.js +3 -3
- package/dist/utils/setObjectValue/setObjectValue.js +40 -7
- package/dist/utils/setObjectValue/setObjectValue.test.js +26 -0
- package/dist/validators/index.d.ts +1 -0
- package/dist/validators/index.js +1 -0
- package/dist/validators/isEmpty/isEmpty.d.ts +7 -0
- package/dist/validators/isEmpty/isEmpty.js +7 -0
- package/dist/validators/isFile/isFile.d.ts +4 -0
- package/dist/validators/isFile/isFile.js +4 -0
- package/dist/validators/isFile/isFile.test.d.ts +1 -0
- package/dist/validators/isFile/isFile.test.js +37 -0
- package/dist/validators/isValidDate/isValidDate.d.ts +13 -0
- package/dist/validators/isValidDate/isValidDate.js +39 -3
- package/dist/validators/isValidDate/isValidDate.test.js +13 -15
- package/dist/yup/index.d.ts +12 -0
- package/dist/yup/index.js +12 -0
- package/dist/yup/isBirthNumber/isBirthNumberYupTest.d.ts +12 -0
- package/dist/yup/isBirthNumber/isBirthNumberYupTest.js +24 -0
- package/dist/yup/isBirthNumber/isBirthNumberYupTest.test.d.ts +1 -0
- package/dist/yup/isBirthNumber/isBirthNumberYupTest.test.js +34 -0
- package/dist/yup/isDICYup/isDICYupTest.d.ts +12 -0
- package/dist/yup/isDICYup/isDICYupTest.js +24 -0
- package/dist/yup/isDICYup/isDICYupTest.test.d.ts +1 -0
- package/dist/yup/isDICYup/isDICYupTest.test.js +36 -0
- package/dist/yup/isDate/isDateYupTest.d.ts +12 -0
- package/dist/yup/isDate/isDateYupTest.js +25 -0
- package/dist/yup/isDate/isDateYupTest.test.d.ts +1 -0
- package/dist/yup/isDate/isDateYupTest.test.js +41 -0
- package/dist/yup/isDateSameOrAfter/isDateSameOrAfterYupTest.d.ts +2 -0
- package/dist/yup/isDateSameOrAfter/isDateSameOrAfterYupTest.js +26 -0
- package/dist/yup/isDateSameOrAfter/isDateSameOrAfterYupTest.test.d.ts +1 -0
- package/dist/yup/isDateSameOrAfter/isDateSameOrAfterYupTest.test.js +32 -0
- package/dist/yup/isDateSameOrAfter/isDateSameOrAfterYupWhen.d.ts +13 -0
- package/dist/yup/isDateSameOrAfter/isDateSameOrAfterYupWhen.js +13 -0
- package/dist/yup/isDateSameOrAfter/isDateSameOrAfterYupWhen.test.d.ts +1 -0
- package/dist/yup/isDateSameOrAfter/isDateSameOrAfterYupWhen.test.js +28 -0
- package/dist/yup/isDateSameOrBefore/isDateSameOrBeforeYupTest.d.ts +2 -0
- package/dist/yup/isDateSameOrBefore/isDateSameOrBeforeYupTest.js +26 -0
- package/dist/yup/isDateSameOrBefore/isDateSameOrBeforeYupTest.test.d.ts +1 -0
- package/dist/yup/isDateSameOrBefore/isDateSameOrBeforeYupTest.test.js +32 -0
- package/dist/yup/isDateSameOrBefore/isDateSameOrBeforeYupWhen.d.ts +13 -0
- package/dist/yup/isDateSameOrBefore/isDateSameOrBeforeYupWhen.js +13 -0
- package/dist/yup/isDateSameOrBefore/isDateSameOrBeforeYupWhen.test.d.ts +1 -0
- package/dist/yup/isDateSameOrBefore/isDateSameOrBeforeYupWhen.test.js +28 -0
- package/dist/yup/isEmail/isEmailYupTest.d.ts +12 -0
- package/dist/yup/isEmail/isEmailYupTest.js +24 -0
- package/dist/yup/isEmail/isEmailYupTest.test.d.ts +1 -0
- package/dist/yup/isEmail/isEmailYupTest.test.js +36 -0
- package/dist/yup/isICO/isICOYupTest.d.ts +12 -0
- package/dist/yup/isICO/isICOYupTest.js +24 -0
- package/dist/yup/isICO/isICOYupTest.test.d.ts +1 -0
- package/dist/yup/isICO/isICOYupTest.test.js +36 -0
- package/dist/yup/isModulo11/isModulo11YupTest.d.ts +12 -0
- package/dist/yup/isModulo11/isModulo11YupTest.js +24 -0
- package/dist/yup/isModulo11/isModulo11YupTest.test.d.ts +1 -0
- package/dist/yup/isModulo11/isModulo11YupTest.test.js +28 -0
- package/dist/yup/isNumberSameOrGreater/isNumberSameOrGreaterYupTest.d.ts +2 -0
- package/dist/yup/isNumberSameOrGreater/isNumberSameOrGreaterYupTest.js +23 -0
- package/dist/yup/isNumberSameOrGreater/isNumberSameOrGreaterYupTest.test.d.ts +1 -0
- package/dist/yup/isNumberSameOrGreater/isNumberSameOrGreaterYupTest.test.js +32 -0
- package/dist/yup/isNumberSameOrGreater/isNumberSameOrGreaterYupWhen.d.ts +13 -0
- package/dist/yup/isNumberSameOrGreater/isNumberSameOrGreaterYupWhen.js +13 -0
- package/dist/yup/isNumberSameOrGreater/isNumberSameOrGreaterYupWhen.test.d.ts +1 -0
- package/dist/yup/isNumberSameOrGreater/isNumberSameOrGreaterYupWhen.test.js +28 -0
- package/dist/yup/isNumberSameOrLower/isNumberSameOrLowerYupTest.d.ts +2 -0
- package/dist/yup/isNumberSameOrLower/isNumberSameOrLowerYupTest.js +23 -0
- package/dist/yup/isNumberSameOrLower/isNumberSameOrLowerYupTest.test.d.ts +1 -0
- package/dist/yup/isNumberSameOrLower/isNumberSameOrLowerYupTest.test.js +32 -0
- package/dist/yup/isNumberSameOrLower/isNumberSameOrLowerYupWhen.d.ts +13 -0
- package/dist/yup/isNumberSameOrLower/isNumberSameOrLowerYupWhen.js +13 -0
- package/dist/yup/isNumberSameOrLower/isNumberSameOrLowerYupWhen.test.d.ts +1 -0
- package/dist/yup/isNumberSameOrLower/isNumberSameOrLowerYupWhen.test.js +28 -0
- package/dist/yup/maxDigitsLength/maxDigitsLengthYupTest.d.ts +14 -0
- package/dist/yup/maxDigitsLength/maxDigitsLengthYupTest.js +24 -0
- package/dist/yup/maxDigitsLength/maxDigitsLengthYupTest.test.d.ts +1 -0
- package/dist/yup/maxDigitsLength/maxDigitsLengthYupTest.test.js +24 -0
- package/dist/yup/minDigitsLength/minDigitsLengthYupTest.d.ts +14 -0
- package/dist/yup/minDigitsLength/minDigitsLengthYupTest.js +24 -0
- package/dist/yup/minDigitsLength/minDigitsLengthYupTest.test.d.ts +1 -0
- package/dist/yup/minDigitsLength/minDigitsLengthYupTest.test.js +24 -0
- package/package.json +15 -12
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { isDateSameOrBeforeYupTest } from './isDateSameOrBeforeYupTest.js';
|
|
3
|
+
import { isDateSameOrBeforeYupWhen } from './isDateSameOrBeforeYupWhen.js';
|
|
4
|
+
vi.mock('./isDateSameOrBeforeYupTest.js', () => ({
|
|
5
|
+
isDateSameOrBeforeYupTest: vi.fn()
|
|
6
|
+
}));
|
|
7
|
+
describe('isDateSameOrBeforeYupWhen', () => {
|
|
8
|
+
test('should create a schema callback that passes generated test config to schema.test', () => {
|
|
9
|
+
const message = 'Invalid date';
|
|
10
|
+
const minDate = [new Date('2026-04-02')];
|
|
11
|
+
const generatedTestConfig = {
|
|
12
|
+
name: 'isDateSameOrBefore',
|
|
13
|
+
exclusive: true,
|
|
14
|
+
message,
|
|
15
|
+
test: () => true
|
|
16
|
+
};
|
|
17
|
+
vi.mocked(isDateSameOrBeforeYupTest).mockReturnValue(generatedTestConfig);
|
|
18
|
+
const schemaTestResult = { marker: 'schema-test-result' };
|
|
19
|
+
const schema = {
|
|
20
|
+
test: vi.fn().mockReturnValue(schemaTestResult)
|
|
21
|
+
};
|
|
22
|
+
const whenCallback = isDateSameOrBeforeYupWhen(message);
|
|
23
|
+
const result = whenCallback(minDate, schema);
|
|
24
|
+
expect(isDateSameOrBeforeYupTest).toHaveBeenCalledWith(minDate, message);
|
|
25
|
+
expect(schema.test).toHaveBeenCalledWith(generatedTestConfig);
|
|
26
|
+
expect(result).toBe(schemaTestResult);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TestConfig } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid e-mail.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'email': yup.string().test(isEmailYupTest(i18n.t('Invalid e-mail')))
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const isEmailYupTest: (message: string) => TestConfig<string | null | undefined>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isEmail } from '../../validators/isEmail/isEmail.js';
|
|
2
|
+
import { isNullOrUndefined } from '../../validators/isNullOrUndefined/isNullOrUndefined.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Yup test configuration for validating if a value is a valid e-mail.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```
|
|
8
|
+
* const yupSchema = yup.object().shape({
|
|
9
|
+
* 'email': yup.string().test(isEmailYupTest(i18n.t('Invalid e-mail')))
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const isEmailYupTest = (message) => {
|
|
14
|
+
return {
|
|
15
|
+
name: 'isEmail',
|
|
16
|
+
exclusive: true,
|
|
17
|
+
message,
|
|
18
|
+
test: (value) => {
|
|
19
|
+
if (isNullOrUndefined(value))
|
|
20
|
+
return true;
|
|
21
|
+
return isEmail(value);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { isEmailYupTest } from './isEmailYupTest.js';
|
|
3
|
+
describe('isEmailYupTest', () => {
|
|
4
|
+
const testMessage = 'Invalid e-mail';
|
|
5
|
+
const testConfig = isEmailYupTest(testMessage);
|
|
6
|
+
const mockContext = {};
|
|
7
|
+
test('should return a TestConfig object', () => {
|
|
8
|
+
expect(testConfig).toBeDefined();
|
|
9
|
+
expect(testConfig.name).toBe('isEmail');
|
|
10
|
+
expect(testConfig.exclusive).toBe(true);
|
|
11
|
+
expect(testConfig.message).toBe(testMessage);
|
|
12
|
+
expect(testConfig.test).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
test('should return true for null', () => {
|
|
15
|
+
expect(testConfig.test.call(mockContext, null, mockContext)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
test('should return true for undefined', () => {
|
|
18
|
+
expect(testConfig.test.call(mockContext, undefined, mockContext)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
test('should return true for valid e-mail values', () => {
|
|
21
|
+
expect(testConfig.test.call(mockContext, 'test@example.com', mockContext)).toBe(true);
|
|
22
|
+
expect(testConfig.test.call(mockContext, 'user.name+tag+sorting@example.co.uk', mockContext)).toBe(true);
|
|
23
|
+
expect(testConfig.test.call(mockContext, 'a@b.cz', mockContext)).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
test('should return false for invalid e-mail values', () => {
|
|
26
|
+
expect(testConfig.test.call(mockContext, '', mockContext)).toBe(false);
|
|
27
|
+
expect(testConfig.test.call(mockContext, 'plainaddress', mockContext)).toBe(false);
|
|
28
|
+
expect(testConfig.test.call(mockContext, 'user@com', mockContext)).toBe(false);
|
|
29
|
+
expect(testConfig.test.call(mockContext, 'user@domain.123', mockContext)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
test('should accept custom error message', () => {
|
|
32
|
+
const customMessage = 'Custom e-mail validation message';
|
|
33
|
+
const customTestConfig = isEmailYupTest(customMessage);
|
|
34
|
+
expect(customTestConfig.message).toBe(customMessage);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TestConfig } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid ICO.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'ico': yup.string().test(isICOYupTest(i18n.t('Invalid ICO')))
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const isICOYupTest: (message: string) => TestConfig<string | null | undefined>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isICO } from '../../validators/isICO/isICO.js';
|
|
2
|
+
import { isNullOrUndefined } from '../../validators/isNullOrUndefined/isNullOrUndefined.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Yup test configuration for validating if a value is a valid ICO.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```
|
|
8
|
+
* const yupSchema = yup.object().shape({
|
|
9
|
+
* 'ico': yup.string().test(isICOYupTest(i18n.t('Invalid ICO')))
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const isICOYupTest = (message) => {
|
|
14
|
+
return {
|
|
15
|
+
name: 'isICO',
|
|
16
|
+
exclusive: true,
|
|
17
|
+
message,
|
|
18
|
+
test: (value) => {
|
|
19
|
+
if (isNullOrUndefined(value))
|
|
20
|
+
return true;
|
|
21
|
+
return isICO(value);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { isICOYupTest } from './isICOYupTest.js';
|
|
3
|
+
describe('isICOYupTest', () => {
|
|
4
|
+
const testMessage = 'Invalid ICO';
|
|
5
|
+
const testConfig = isICOYupTest(testMessage);
|
|
6
|
+
const mockContext = {};
|
|
7
|
+
test('should return a TestConfig object', () => {
|
|
8
|
+
expect(testConfig).toBeDefined();
|
|
9
|
+
expect(testConfig.name).toBe('isICO');
|
|
10
|
+
expect(testConfig.exclusive).toBe(true);
|
|
11
|
+
expect(testConfig.message).toBe(testMessage);
|
|
12
|
+
expect(testConfig.test).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
test('should return true for null', () => {
|
|
15
|
+
expect(testConfig.test.call(mockContext, null, mockContext)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
test('should return true for undefined', () => {
|
|
18
|
+
expect(testConfig.test.call(mockContext, undefined, mockContext)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
test('should return true for valid ICO values', () => {
|
|
21
|
+
expect(testConfig.test.call(mockContext, '27074358', mockContext)).toBe(true);
|
|
22
|
+
expect(testConfig.test.call(mockContext, '46345965', mockContext)).toBe(true);
|
|
23
|
+
expect(testConfig.test.call(mockContext, '05584205', mockContext)).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
test('should return false for invalid ICO values', () => {
|
|
26
|
+
expect(testConfig.test.call(mockContext, '', mockContext)).toBe(false);
|
|
27
|
+
expect(testConfig.test.call(mockContext, '12345678', mockContext)).toBe(false);
|
|
28
|
+
expect(testConfig.test.call(mockContext, '27074359', mockContext)).toBe(false);
|
|
29
|
+
expect(testConfig.test.call(mockContext, 'abcdefgh', mockContext)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
test('should accept custom error message', () => {
|
|
32
|
+
const customMessage = 'Custom ICO validation message';
|
|
33
|
+
const customTestConfig = isICOYupTest(customMessage);
|
|
34
|
+
expect(customTestConfig.message).toBe(customMessage);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TestConfig } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid modulo 11 number.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'bankAccount': yup.number().test(isModulo11YupTest(i18n.t('Invalid bank account number')))
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const isModulo11YupTest: (message: string) => TestConfig<number | null | undefined>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isModulo11 } from '../../validators/isModulo11/isModulo11.js';
|
|
2
|
+
import { isNullOrUndefined } from '../../validators/isNullOrUndefined/isNullOrUndefined.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Yup test configuration for validating if a value is a valid modulo 11 number.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```
|
|
8
|
+
* const yupSchema = yup.object().shape({
|
|
9
|
+
* 'bankAccount': yup.number().test(isModulo11YupTest(i18n.t('Invalid bank account number')))
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const isModulo11YupTest = (message) => {
|
|
14
|
+
return {
|
|
15
|
+
name: 'isModulo11',
|
|
16
|
+
exclusive: true,
|
|
17
|
+
message,
|
|
18
|
+
test: (value) => {
|
|
19
|
+
if (isNullOrUndefined(value))
|
|
20
|
+
return true;
|
|
21
|
+
return isModulo11(value);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { isModulo11YupTest } from './isModulo11YupTest.js';
|
|
3
|
+
describe('isModulo11YupTest', () => {
|
|
4
|
+
const testMessage = 'Invalid bank account number';
|
|
5
|
+
const testConfig = isModulo11YupTest(testMessage);
|
|
6
|
+
const mockContext = {};
|
|
7
|
+
test('should return a TestConfig object', () => {
|
|
8
|
+
expect(testConfig).toBeDefined();
|
|
9
|
+
expect(testConfig.name).toBe('isModulo11');
|
|
10
|
+
expect(testConfig.exclusive).toBe(true);
|
|
11
|
+
expect(testConfig.message).toBe(testMessage);
|
|
12
|
+
expect(testConfig.test).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
test('should return true for null', () => {
|
|
15
|
+
expect(testConfig.test.call(mockContext, null, mockContext)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
test('should return true for undefined', () => {
|
|
18
|
+
expect(testConfig.test.call(mockContext, undefined, mockContext)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
test('should return true for valid modulo11 values', () => {
|
|
21
|
+
expect(testConfig.test.call(mockContext, 123, mockContext)).toBe(true);
|
|
22
|
+
expect(testConfig.test.call(mockContext, 0, mockContext)).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
test('should return false for invalid modulo11 values', () => {
|
|
25
|
+
expect(testConfig.test.call(mockContext, 12345678901, mockContext)).toBe(false);
|
|
26
|
+
expect(testConfig.test.call(mockContext, 9876543210, mockContext)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getNumber } from '../../utils/getNumber/getNumber.js';
|
|
2
|
+
import { isEmpty } from '../../validators/isEmpty/isEmpty.js';
|
|
3
|
+
import { isNullOrUndefined } from '../../validators/isNullOrUndefined/isNullOrUndefined.js';
|
|
4
|
+
import { isNumber } from '../../validators/isNumber/isNumber.js';
|
|
5
|
+
export const isNumberSameOrGreaterYupTest = (max, message) => {
|
|
6
|
+
return {
|
|
7
|
+
name: 'isNumberSameOrGreater',
|
|
8
|
+
exclusive: true,
|
|
9
|
+
params: { max },
|
|
10
|
+
message,
|
|
11
|
+
test: (value) => {
|
|
12
|
+
if (isEmpty(value))
|
|
13
|
+
return true;
|
|
14
|
+
if (!Array.isArray(max) || max.length === 0)
|
|
15
|
+
return true;
|
|
16
|
+
const maxValue = max[0];
|
|
17
|
+
const valueNumber = getNumber(value);
|
|
18
|
+
if (isNullOrUndefined(valueNumber) || isNullOrUndefined(maxValue) || !isNumber(maxValue))
|
|
19
|
+
return true;
|
|
20
|
+
return valueNumber <= maxValue;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { isNumberSameOrGreaterYupTest } from './isNumberSameOrGreaterYupTest.js';
|
|
3
|
+
describe('isNumberSameOrGreaterYupTest', () => {
|
|
4
|
+
const message = 'Invalid number range';
|
|
5
|
+
const mockContext = {};
|
|
6
|
+
test('should return a TestConfig object', () => {
|
|
7
|
+
const max = [10];
|
|
8
|
+
const testConfig = isNumberSameOrGreaterYupTest(max, message);
|
|
9
|
+
expect(testConfig.name).toBe('isNumberSameOrGreater');
|
|
10
|
+
expect(testConfig.exclusive).toBe(true);
|
|
11
|
+
expect(testConfig.params).toEqual({ max });
|
|
12
|
+
expect(testConfig.message).toBe(message);
|
|
13
|
+
expect(testConfig.test).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
test('should return true for empty values', () => {
|
|
16
|
+
expect(isNumberSameOrGreaterYupTest([10], message).test.call(mockContext, null, mockContext)).toBe(true);
|
|
17
|
+
expect(isNumberSameOrGreaterYupTest([10], message).test.call(mockContext, undefined, mockContext)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
test('should return true when max argument is not array', () => {
|
|
20
|
+
const testConfig = isNumberSameOrGreaterYupTest('invalid', message);
|
|
21
|
+
expect(testConfig.test.call(mockContext, 5, mockContext)).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
test('should return true when max value is not a number', () => {
|
|
24
|
+
const testConfig = isNumberSameOrGreaterYupTest(['abc'], message);
|
|
25
|
+
expect(testConfig.test.call(mockContext, 5, mockContext)).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
test('should compare value as same or lower than max', () => {
|
|
28
|
+
expect(isNumberSameOrGreaterYupTest([10], message).test.call(mockContext, 10, mockContext)).toBe(true);
|
|
29
|
+
expect(isNumberSameOrGreaterYupTest([10], message).test.call(mockContext, 9, mockContext)).toBe(true);
|
|
30
|
+
expect(isNumberSameOrGreaterYupTest([10], message).test.call(mockContext, 11, mockContext)).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NumberSchema } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid number that is the same or greater than a reference number.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'yearFrom': yup.number().when(['yearTo'], isNumberSameOrGreaterYupWhen(i18n.t('Invalid year'))),
|
|
9
|
+
* 'yearTo': yup.number().when(['yearFrom'], isNumberSameOrLowerYupWhen(i18n.t('Invalid year')))
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const isNumberSameOrGreaterYupWhen: (message: string) => (max: unknown[], schema: NumberSchema) => NumberSchema<number | undefined, import("yup").AnyObject, undefined, "">;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isNumberSameOrGreaterYupTest } from './isNumberSameOrGreaterYupTest.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid number that is the same or greater than a reference number.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'yearFrom': yup.number().when(['yearTo'], isNumberSameOrGreaterYupWhen(i18n.t('Invalid year'))),
|
|
9
|
+
* 'yearTo': yup.number().when(['yearFrom'], isNumberSameOrLowerYupWhen(i18n.t('Invalid year')))
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const isNumberSameOrGreaterYupWhen = (message) => (max, schema) => schema.test(isNumberSameOrGreaterYupTest(max, message));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { isNumberSameOrGreaterYupTest } from './isNumberSameOrGreaterYupTest.js';
|
|
3
|
+
import { isNumberSameOrGreaterYupWhen } from './isNumberSameOrGreaterYupWhen.js';
|
|
4
|
+
vi.mock('./isNumberSameOrGreaterYupTest.js', () => ({
|
|
5
|
+
isNumberSameOrGreaterYupTest: vi.fn()
|
|
6
|
+
}));
|
|
7
|
+
describe('isNumberSameOrGreaterYupWhen', () => {
|
|
8
|
+
test('should create a schema callback that passes generated test config to schema.test', () => {
|
|
9
|
+
const message = 'Invalid year';
|
|
10
|
+
const max = [2026];
|
|
11
|
+
const generatedTestConfig = {
|
|
12
|
+
name: 'isNumberSameOrGreater',
|
|
13
|
+
exclusive: true,
|
|
14
|
+
message,
|
|
15
|
+
test: () => true
|
|
16
|
+
};
|
|
17
|
+
vi.mocked(isNumberSameOrGreaterYupTest).mockReturnValue(generatedTestConfig);
|
|
18
|
+
const schemaTestResult = { marker: 'schema-test-result' };
|
|
19
|
+
const schema = {
|
|
20
|
+
test: vi.fn().mockReturnValue(schemaTestResult)
|
|
21
|
+
};
|
|
22
|
+
const whenCallback = isNumberSameOrGreaterYupWhen(message);
|
|
23
|
+
const result = whenCallback(max, schema);
|
|
24
|
+
expect(isNumberSameOrGreaterYupTest).toHaveBeenCalledWith(max, message);
|
|
25
|
+
expect(schema.test).toHaveBeenCalledWith(generatedTestConfig);
|
|
26
|
+
expect(result).toBe(schemaTestResult);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getNumber } from '../../utils/getNumber/getNumber.js';
|
|
2
|
+
import { isEmpty } from '../../validators/isEmpty/isEmpty.js';
|
|
3
|
+
import { isNullOrUndefined } from '../../validators/isNullOrUndefined/isNullOrUndefined.js';
|
|
4
|
+
import { isNumber } from '../../validators/isNumber/isNumber.js';
|
|
5
|
+
export const isNumberSameOrLowerYupTest = (min, message) => {
|
|
6
|
+
return {
|
|
7
|
+
name: 'isNumberSameOrLower',
|
|
8
|
+
exclusive: true,
|
|
9
|
+
params: { min },
|
|
10
|
+
message,
|
|
11
|
+
test: (value) => {
|
|
12
|
+
if (isEmpty(value))
|
|
13
|
+
return true;
|
|
14
|
+
if (!Array.isArray(min) || min.length === 0)
|
|
15
|
+
return true;
|
|
16
|
+
const minValue = min[0];
|
|
17
|
+
const valueNumber = getNumber(value);
|
|
18
|
+
if (isNullOrUndefined(valueNumber) || isNullOrUndefined(minValue) || !isNumber(minValue))
|
|
19
|
+
return true;
|
|
20
|
+
return valueNumber >= minValue;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { isNumberSameOrLowerYupTest } from './isNumberSameOrLowerYupTest.js';
|
|
3
|
+
describe('isNumberSameOrLowerYupTest', () => {
|
|
4
|
+
const message = 'Invalid number range';
|
|
5
|
+
const mockContext = {};
|
|
6
|
+
test('should return a TestConfig object', () => {
|
|
7
|
+
const min = [10];
|
|
8
|
+
const testConfig = isNumberSameOrLowerYupTest(min, message);
|
|
9
|
+
expect(testConfig.name).toBe('isNumberSameOrLower');
|
|
10
|
+
expect(testConfig.exclusive).toBe(true);
|
|
11
|
+
expect(testConfig.params).toEqual({ min });
|
|
12
|
+
expect(testConfig.message).toBe(message);
|
|
13
|
+
expect(testConfig.test).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
test('should return true for empty values', () => {
|
|
16
|
+
expect(isNumberSameOrLowerYupTest([10], message).test.call(mockContext, null, mockContext)).toBe(true);
|
|
17
|
+
expect(isNumberSameOrLowerYupTest([10], message).test.call(mockContext, undefined, mockContext)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
test('should return true when min argument is not array', () => {
|
|
20
|
+
const testConfig = isNumberSameOrLowerYupTest('invalid', message);
|
|
21
|
+
expect(testConfig.test.call(mockContext, 5, mockContext)).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
test('should return true when min value is not a number', () => {
|
|
24
|
+
const testConfig = isNumberSameOrLowerYupTest(['abc'], message);
|
|
25
|
+
expect(testConfig.test.call(mockContext, 5, mockContext)).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
test('should compare value as same or greater than min', () => {
|
|
28
|
+
expect(isNumberSameOrLowerYupTest([10], message).test.call(mockContext, 10, mockContext)).toBe(true);
|
|
29
|
+
expect(isNumberSameOrLowerYupTest([10], message).test.call(mockContext, 11, mockContext)).toBe(true);
|
|
30
|
+
expect(isNumberSameOrLowerYupTest([10], message).test.call(mockContext, 9, mockContext)).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NumberSchema } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid number that is the same or greater than a reference number.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'yearFrom': yup.number().when(['yearTo'], isNumberSameOrGreaterYupWhen(i18n.t('Invalid year'))),
|
|
9
|
+
* 'yearTo': yup.number().when(['yearFrom'], isNumberSameOrLowerYupWhen(i18n.t('Invalid year')))
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const isNumberSameOrLowerYupWhen: (message: string) => (min: unknown[], schema: NumberSchema) => NumberSchema<number | undefined, import("yup").AnyObject, undefined, "">;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isNumberSameOrLowerYupTest } from './isNumberSameOrLowerYupTest.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid number that is the same or greater than a reference number.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'yearFrom': yup.number().when(['yearTo'], isNumberSameOrGreaterYupWhen(i18n.t('Invalid year'))),
|
|
9
|
+
* 'yearTo': yup.number().when(['yearFrom'], isNumberSameOrLowerYupWhen(i18n.t('Invalid year')))
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const isNumberSameOrLowerYupWhen = (message) => (min, schema) => schema.test(isNumberSameOrLowerYupTest(min, message));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { isNumberSameOrLowerYupTest } from './isNumberSameOrLowerYupTest.js';
|
|
3
|
+
import { isNumberSameOrLowerYupWhen } from './isNumberSameOrLowerYupWhen.js';
|
|
4
|
+
vi.mock('./isNumberSameOrLowerYupTest.js', () => ({
|
|
5
|
+
isNumberSameOrLowerYupTest: vi.fn()
|
|
6
|
+
}));
|
|
7
|
+
describe('isNumberSameOrLowerYupWhen', () => {
|
|
8
|
+
test('should create a schema callback that passes generated test config to schema.test', () => {
|
|
9
|
+
const message = 'Invalid year';
|
|
10
|
+
const min = [2026];
|
|
11
|
+
const generatedTestConfig = {
|
|
12
|
+
name: 'isNumberSameOrLower',
|
|
13
|
+
exclusive: true,
|
|
14
|
+
message,
|
|
15
|
+
test: () => true
|
|
16
|
+
};
|
|
17
|
+
vi.mocked(isNumberSameOrLowerYupTest).mockReturnValue(generatedTestConfig);
|
|
18
|
+
const schemaTestResult = { marker: 'schema-test-result' };
|
|
19
|
+
const schema = {
|
|
20
|
+
test: vi.fn().mockReturnValue(schemaTestResult)
|
|
21
|
+
};
|
|
22
|
+
const whenCallback = isNumberSameOrLowerYupWhen(message);
|
|
23
|
+
const result = whenCallback(min, schema);
|
|
24
|
+
expect(isNumberSameOrLowerYupTest).toHaveBeenCalledWith(min, message);
|
|
25
|
+
expect(schema.test).toHaveBeenCalledWith(generatedTestConfig);
|
|
26
|
+
expect(result).toBe(schemaTestResult);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TestConfig } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid number has a maximum number of digits.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'number': yup.number().test(maxDigitsLengthYupTest(5, i18n.t('Invalid number with more than 5 digits')))
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const maxDigitsLengthYupTest: (max: number, message: (params: {
|
|
13
|
+
max: number;
|
|
14
|
+
}) => string) => TestConfig<number | null | undefined>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isNullOrUndefined } from '../../validators/isNullOrUndefined/isNullOrUndefined.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid number has a maximum number of digits.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'number': yup.number().test(maxDigitsLengthYupTest(5, i18n.t('Invalid number with more than 5 digits')))
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const maxDigitsLengthYupTest = (max, message) => {
|
|
13
|
+
return {
|
|
14
|
+
name: 'maxDigits',
|
|
15
|
+
exclusive: true,
|
|
16
|
+
params: { max },
|
|
17
|
+
message,
|
|
18
|
+
test: (value) => {
|
|
19
|
+
if (isNullOrUndefined(value))
|
|
20
|
+
return true;
|
|
21
|
+
return value.toString().length <= max;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { maxDigitsLengthYupTest } from './maxDigitsLengthYupTest.js';
|
|
3
|
+
describe('maxDigitsLengthYupTest', () => {
|
|
4
|
+
const max = 5;
|
|
5
|
+
const message = ({ max: maxValue }) => `Invalid number with more than ${maxValue} digits`;
|
|
6
|
+
const testConfig = maxDigitsLengthYupTest(max, message);
|
|
7
|
+
const mockContext = {};
|
|
8
|
+
test('should return a TestConfig object', () => {
|
|
9
|
+
expect(testConfig.name).toBe('maxDigits');
|
|
10
|
+
expect(testConfig.exclusive).toBe(true);
|
|
11
|
+
expect(testConfig.params).toEqual({ max });
|
|
12
|
+
expect(testConfig.message).toBe(message);
|
|
13
|
+
expect(testConfig.test).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
test('should return true for null and undefined', () => {
|
|
16
|
+
expect(testConfig.test.call(mockContext, null, mockContext)).toBe(true);
|
|
17
|
+
expect(testConfig.test.call(mockContext, undefined, mockContext)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
test('should validate digit length using max value', () => {
|
|
20
|
+
expect(testConfig.test.call(mockContext, 12345, mockContext)).toBe(true);
|
|
21
|
+
expect(testConfig.test.call(mockContext, 1234, mockContext)).toBe(true);
|
|
22
|
+
expect(testConfig.test.call(mockContext, 123456, mockContext)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TestConfig } from 'yup';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid number has a minimum number of digits.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'number': yup.number().test(minDigitsLengthYupTest(5, i18n.t('Invalid number with less than 5 digits')))
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const minDigitsLengthYupTest: (min: number, message: (params: {
|
|
13
|
+
min: number;
|
|
14
|
+
}) => string) => TestConfig<number | null | undefined>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isNullOrUndefined } from '../../validators/isNullOrUndefined/isNullOrUndefined.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Yup test configuration for validating if a value is a valid number has a minimum number of digits.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* const yupSchema = yup.object().shape({
|
|
8
|
+
* 'number': yup.number().test(minDigitsLengthYupTest(5, i18n.t('Invalid number with less than 5 digits')))
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const minDigitsLengthYupTest = (min, message) => {
|
|
13
|
+
return {
|
|
14
|
+
name: 'minDigits',
|
|
15
|
+
exclusive: true,
|
|
16
|
+
params: { min },
|
|
17
|
+
message,
|
|
18
|
+
test(value) {
|
|
19
|
+
if (isNullOrUndefined(value))
|
|
20
|
+
return true;
|
|
21
|
+
return value.toString().length >= min;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|