hvp-shared 2.0.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/README.md +36 -0
- package/dist/constants/mexican-states.d.ts +43 -0
- package/dist/constants/mexican-states.js +46 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +33 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/types/api-response.types.d.ts +322 -0
- package/dist/types/api-response.types.js +65 -0
- package/dist/types/company-settings.types.d.ts +51 -0
- package/dist/types/company-settings.types.js +2 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +28 -0
- package/dist/validation/__tests__/address.validation.test.d.ts +1 -0
- package/dist/validation/__tests__/address.validation.test.js +143 -0
- package/dist/validation/__tests__/email.validation.test.d.ts +1 -0
- package/dist/validation/__tests__/email.validation.test.js +102 -0
- package/dist/validation/__tests__/phone.validation.test.d.ts +1 -0
- package/dist/validation/__tests__/phone.validation.test.js +75 -0
- package/dist/validation/__tests__/rfc.validation.test.d.ts +1 -0
- package/dist/validation/__tests__/rfc.validation.test.js +97 -0
- package/dist/validation/address.validation.d.ts +27 -0
- package/dist/validation/address.validation.js +51 -0
- package/dist/validation/email.validation.d.ts +20 -0
- package/dist/validation/email.validation.js +37 -0
- package/dist/validation/index.d.ts +8 -0
- package/dist/validation/index.js +24 -0
- package/dist/validation/phone.validation.d.ts +14 -0
- package/dist/validation/phone.validation.js +33 -0
- package/dist/validation/rfc.validation.d.ts +27 -0
- package/dist/validation/rfc.validation.js +41 -0
- package/package.json +30 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface ValidationResult {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
error?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Validates RFC (Mexican Tax ID) format
|
|
7
|
+
*
|
|
8
|
+
* Valid formats:
|
|
9
|
+
* - Persona Moral: 3 letters + 6 digits + 3 alphanumeric (e.g., HVP850101AB1)
|
|
10
|
+
* - Persona Física: 4 letters + 6 digits + 3 alphanumeric (e.g., GARC850101AB1)
|
|
11
|
+
*
|
|
12
|
+
* @param value - RFC to validate
|
|
13
|
+
* @returns ValidationResult with isValid flag and optional error message
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateRFC(value: string | null | undefined): ValidationResult;
|
|
16
|
+
/**
|
|
17
|
+
* Normalizes RFC to uppercase and trimmed
|
|
18
|
+
*
|
|
19
|
+
* @param value - RFC to normalize
|
|
20
|
+
* @returns Normalized RFC
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeRFC(value: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Regex pattern for RFC validation
|
|
25
|
+
* Can be used directly in form libraries that accept regex
|
|
26
|
+
*/
|
|
27
|
+
export declare const RFC_PATTERN: RegExp;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RFC_PATTERN = void 0;
|
|
4
|
+
exports.validateRFC = validateRFC;
|
|
5
|
+
exports.normalizeRFC = normalizeRFC;
|
|
6
|
+
/**
|
|
7
|
+
* Validates RFC (Mexican Tax ID) format
|
|
8
|
+
*
|
|
9
|
+
* Valid formats:
|
|
10
|
+
* - Persona Moral: 3 letters + 6 digits + 3 alphanumeric (e.g., HVP850101AB1)
|
|
11
|
+
* - Persona Física: 4 letters + 6 digits + 3 alphanumeric (e.g., GARC850101AB1)
|
|
12
|
+
*
|
|
13
|
+
* @param value - RFC to validate
|
|
14
|
+
* @returns ValidationResult with isValid flag and optional error message
|
|
15
|
+
*/
|
|
16
|
+
function validateRFC(value) {
|
|
17
|
+
if (!value || !value.trim()) {
|
|
18
|
+
return { isValid: false, error: 'RFC es requerido' };
|
|
19
|
+
}
|
|
20
|
+
const normalized = value.toUpperCase().trim();
|
|
21
|
+
// Mexican RFC format: 3-4 letters + 6 digits + 3 alphanumeric
|
|
22
|
+
const rfcPattern = /^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/;
|
|
23
|
+
if (!rfcPattern.test(normalized)) {
|
|
24
|
+
return { isValid: false, error: 'RFC inválido. Formato esperado: XXXX000000XXX' };
|
|
25
|
+
}
|
|
26
|
+
return { isValid: true };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Normalizes RFC to uppercase and trimmed
|
|
30
|
+
*
|
|
31
|
+
* @param value - RFC to normalize
|
|
32
|
+
* @returns Normalized RFC
|
|
33
|
+
*/
|
|
34
|
+
function normalizeRFC(value) {
|
|
35
|
+
return value.toUpperCase().trim();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Regex pattern for RFC validation
|
|
39
|
+
* Can be used directly in form libraries that accept regex
|
|
40
|
+
*/
|
|
41
|
+
exports.RFC_PATTERN = /^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hvp-shared",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Shared types and utilities for HVP backend and frontend",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "jest",
|
|
13
|
+
"test:watch": "jest --watch",
|
|
14
|
+
"test:coverage": "jest --coverage",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"hvp",
|
|
19
|
+
"shared",
|
|
20
|
+
"types"
|
|
21
|
+
],
|
|
22
|
+
"author": "Javier Garcia",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/jest": "^30.0.0",
|
|
26
|
+
"jest": "^30.2.0",
|
|
27
|
+
"ts-jest": "^29.4.6",
|
|
28
|
+
"typescript": "^5.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|