soff-id 0.1.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/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/core/index.cjs +2 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +63 -0
- package/dist/core/index.d.ts +63 -0
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/ar.cjs +2 -0
- package/dist/locales/ar.cjs.map +1 -0
- package/dist/locales/ar.d.cts +42 -0
- package/dist/locales/ar.d.ts +42 -0
- package/dist/locales/ar.js +2 -0
- package/dist/locales/ar.js.map +1 -0
- package/dist/locales/br.cjs +2 -0
- package/dist/locales/br.cjs.map +1 -0
- package/dist/locales/br.d.cts +30 -0
- package/dist/locales/br.d.ts +30 -0
- package/dist/locales/br.js +2 -0
- package/dist/locales/br.js.map +1 -0
- package/dist/locales/cl.cjs +2 -0
- package/dist/locales/cl.cjs.map +1 -0
- package/dist/locales/cl.d.cts +28 -0
- package/dist/locales/cl.d.ts +28 -0
- package/dist/locales/cl.js +2 -0
- package/dist/locales/cl.js.map +1 -0
- package/dist/locales/co.cjs +2 -0
- package/dist/locales/co.cjs.map +1 -0
- package/dist/locales/co.d.cts +48 -0
- package/dist/locales/co.d.ts +48 -0
- package/dist/locales/co.js +2 -0
- package/dist/locales/co.js.map +1 -0
- package/dist/locales/mx.cjs +2 -0
- package/dist/locales/mx.cjs.map +1 -0
- package/dist/locales/mx.d.cts +38 -0
- package/dist/locales/mx.d.ts +38 -0
- package/dist/locales/mx.js +2 -0
- package/dist/locales/mx.js.map +1 -0
- package/package.json +156 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a Brazilian CPF (Individual Tax ID)
|
|
3
|
+
* @param cpf - The CPF to validate (11 digits)
|
|
4
|
+
*/
|
|
5
|
+
declare function validateCPF(cpf: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Format a CPF for display
|
|
8
|
+
* @returns Formatted CPF (e.g., "123.456.789-09")
|
|
9
|
+
*/
|
|
10
|
+
declare function formatCPF(cpf: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Clean a CPF
|
|
13
|
+
*/
|
|
14
|
+
declare function cleanCPF(cpf: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Validate a Brazilian CNPJ (Business Tax ID)
|
|
17
|
+
* @param cnpj - The CNPJ to validate (14 digits)
|
|
18
|
+
*/
|
|
19
|
+
declare function validateCNPJ(cnpj: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Format a CNPJ for display
|
|
22
|
+
* @returns Formatted CNPJ (e.g., "12.345.678/0001-95")
|
|
23
|
+
*/
|
|
24
|
+
declare function formatCNPJ(cnpj: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Clean a CNPJ
|
|
27
|
+
*/
|
|
28
|
+
declare function cleanCNPJ(cnpj: string): string;
|
|
29
|
+
|
|
30
|
+
export { cleanCNPJ, cleanCPF, formatCNPJ, formatCPF, validateCNPJ, validateCPF };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a Brazilian CPF (Individual Tax ID)
|
|
3
|
+
* @param cpf - The CPF to validate (11 digits)
|
|
4
|
+
*/
|
|
5
|
+
declare function validateCPF(cpf: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Format a CPF for display
|
|
8
|
+
* @returns Formatted CPF (e.g., "123.456.789-09")
|
|
9
|
+
*/
|
|
10
|
+
declare function formatCPF(cpf: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Clean a CPF
|
|
13
|
+
*/
|
|
14
|
+
declare function cleanCPF(cpf: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Validate a Brazilian CNPJ (Business Tax ID)
|
|
17
|
+
* @param cnpj - The CNPJ to validate (14 digits)
|
|
18
|
+
*/
|
|
19
|
+
declare function validateCNPJ(cnpj: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Format a CNPJ for display
|
|
22
|
+
* @returns Formatted CNPJ (e.g., "12.345.678/0001-95")
|
|
23
|
+
*/
|
|
24
|
+
declare function formatCNPJ(cnpj: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Clean a CNPJ
|
|
27
|
+
*/
|
|
28
|
+
declare function cleanCNPJ(cnpj: string): string;
|
|
29
|
+
|
|
30
|
+
export { cleanCNPJ, cleanCPF, formatCNPJ, formatCPF, validateCNPJ, validateCPF };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(n){return n.replace(/\D/g,"")}var o=[10,9,8,7,6,5,4,3,2],l=[11,10,9,8,7,6,5,4,3,2],a=[5,4,3,2,9,8,7,6,5,4,3,2],u=[6,5,4,3,2,9,8,7,6,5,4,3,2];function c(n,t){let r=0;for(let s=0;s<t.length;s++)r+=parseInt(n[s],10)*t[s];let i=r%11;return i<2?0:11-i}function p(n){let t=e(n);return t.length!==11||/^(\d)\1+$/.test(t)||c(t.slice(0,9),o)!==parseInt(t[9],10)?false:c(t.slice(0,10),l)===parseInt(t[10],10)}function d(n){let t=e(n).padStart(11,"0");return `${t.slice(0,3)}.${t.slice(3,6)}.${t.slice(6,9)}-${t.slice(9)}`}function m(n){return e(n)}function x(n){let t=e(n);return t.length!==14||/^(\d)\1+$/.test(t)||c(t.slice(0,12),a)!==parseInt(t[12],10)?false:c(t.slice(0,13),u)===parseInt(t[13],10)}function C(n){let t=e(n).padStart(14,"0");return `${t.slice(0,2)}.${t.slice(2,5)}.${t.slice(5,8)}/${t.slice(8,12)}-${t.slice(12)}`}function I(n){return e(n)}export{I as cleanCNPJ,m as cleanCPF,C as formatCNPJ,d as formatCPF,x as validateCNPJ,p as validateCPF};//# sourceMappingURL=br.js.map
|
|
2
|
+
//# sourceMappingURL=br.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils.ts","../../src/locales/br.ts"],"names":["cleanDigits","value","CPF_WEIGHTS_1","CPF_WEIGHTS_2","CNPJ_WEIGHTS_1","CNPJ_WEIGHTS_2","calcCheckDigit","digits","weights","sum","i","remainder","validateCPF","cpf","cleaned","formatCPF","cleanCPF","validateCNPJ","cnpj","formatCNPJ","cleanCNPJ"],"mappings":"AAUO,SAASA,CAAAA,CAAYC,CAAAA,CAAuB,CACjD,OAAOA,EAAM,OAAA,CAAQ,KAAA,CAAO,EAAE,CAChC,CCPA,IAAMC,CAAAA,CAAgB,CAAC,GAAI,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAC,EAK3CC,CAAAA,CAAgB,CAAC,EAAA,CAAI,EAAA,CAAI,EAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,EAAG,CAAA,CAAG,CAAC,CAAA,CAK/CC,CAAAA,CAAiB,CAAC,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,EAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,EAAG,CAAA,CAAG,CAAA,CAAG,CAAC,CAAA,CAKpDC,EAAiB,CAAC,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,EAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAA,CAAG,CAAC,CAAA,CAK7D,SAASC,CAAAA,CAAeC,CAAAA,CAAgBC,EAA2B,CACjE,IAAIC,CAAAA,CAAM,CAAA,CACV,IAAA,IAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIF,EAAQ,MAAA,CAAQE,CAAAA,EAAAA,CAClCD,CAAAA,EAAO,QAAA,CAASF,CAAAA,CAAOG,CAAC,CAAA,CAAG,EAAE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AAA,GAAW,IAKnB,WAAA,CAAY,IAAA,CAAKA,CAAO,CAAA,EAKbR,EAAeQ,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,EAAE,EAAGV,CAAc,CAAA,GACnD,QAAA,CAASU,CAAAA,CAAQ,EAAE,CAAA,CAAG,EAAE,CAAA,CAC9B,MAIMR,CAAAA,CAAeQ,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,EAAE,CAAA,CAAGT,CAAc,CAAA,GAChD,QAAA,CAASS,EAAQ,EAAE,CAAA,CAAG,EAAE,CAC5C,CAMO,SAASK,CAAAA,CAAWD,CAAAA,CAAsB,CAC/C,IAAMJ,CAAAA,CAAUd,CAAAA,CAAYkB,CAAI,EAAE,QAAA,CAAS,EAAA,CAAI,GAAG,CAAA,CAClD,OAAO,CAAA,EAAGJ,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,CAAC,CAAC,CAAA,CAAA,EAAIA,CAAAA,CAAQ,MAAM,CAAA,CAAG,CAAC,CAAC,CAAA,CAAA,EAAIA,EAAQ,KAAA,CAAM,CAAA,CAAG,CAAC,CAAC,IAAIA,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,EAAE,CAAC,CAAA,CAAA,EAAIA,CAAAA,CAAQ,KAAA,CAAM,EAAE,CAAC,CAAA,CAC1H,CAKO,SAASM,EAAUF,CAAAA,CAAsB,CAC9C,OAAOlB,CAAAA,CAAYkB,CAAI,CACzB","file":"br.js","sourcesContent":["/**\n * Remove all non-alphanumeric characters\n */\nexport function cleanDocument(value: string): string {\n return value.replace(/[^a-zA-Z0-9]/g, '');\n}\n\n/**\n * Remove all non-digit characters\n */\nexport function cleanDigits(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Pad a string with leading zeros\n */\nexport function padStart(value: string, length: number): string {\n return value.padStart(length, '0');\n}\n\n/**\n * Calculate modulo 11 check digit (common algorithm)\n */\nexport function mod11(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n sum += parseInt(digits[i], 10) * weights[i % weights.length];\n }\n const remainder = sum % 11;\n return remainder;\n}\n\n/**\n * Calculate modulo 10 check digit (Luhn-like algorithms)\n */\nexport function mod10(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n let product = parseInt(digits[i], 10) * weights[i % weights.length];\n if (product > 9) {\n product = Math.floor(product / 10) + (product % 10);\n }\n sum += product;\n }\n return sum % 10;\n}\n","import { cleanDigits } from '../core/utils.js';\n\n/**\n * CPF weights for first check digit\n */\nconst CPF_WEIGHTS_1 = [10, 9, 8, 7, 6, 5, 4, 3, 2];\n\n/**\n * CPF weights for second check digit\n */\nconst CPF_WEIGHTS_2 = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2];\n\n/**\n * CNPJ weights for first check digit\n */\nconst CNPJ_WEIGHTS_1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];\n\n/**\n * CNPJ weights for second check digit\n */\nconst CNPJ_WEIGHTS_2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];\n\n/**\n * Calculate CPF/CNPJ check digit using mod 11\n */\nfunction calcCheckDigit(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < weights.length; i++) {\n sum += parseInt(digits[i], 10) * weights[i];\n }\n const remainder = sum % 11;\n return remainder < 2 ? 0 : 11 - remainder;\n}\n\n/**\n * Validate a Brazilian CPF (Individual Tax ID)\n * @param cpf - The CPF to validate (11 digits)\n */\nexport function validateCPF(cpf: string): boolean {\n const cleaned = cleanDigits(cpf);\n\n if (cleaned.length !== 11) {\n return false;\n }\n\n // Check for known invalid CPFs (all same digits)\n if (/^(\\d)\\1+$/.test(cleaned)) {\n return false;\n }\n\n // Calculate first check digit\n const digit1 = calcCheckDigit(cleaned.slice(0, 9), CPF_WEIGHTS_1);\n if (digit1 !== parseInt(cleaned[9], 10)) {\n return false;\n }\n\n // Calculate second check digit\n const digit2 = calcCheckDigit(cleaned.slice(0, 10), CPF_WEIGHTS_2);\n return digit2 === parseInt(cleaned[10], 10);\n}\n\n/**\n * Format a CPF for display\n * @returns Formatted CPF (e.g., \"123.456.789-09\")\n */\nexport function formatCPF(cpf: string): string {\n const cleaned = cleanDigits(cpf).padStart(11, '0');\n return `${cleaned.slice(0, 3)}.${cleaned.slice(3, 6)}.${cleaned.slice(6, 9)}-${cleaned.slice(9)}`;\n}\n\n/**\n * Clean a CPF\n */\nexport function cleanCPF(cpf: string): string {\n return cleanDigits(cpf);\n}\n\n/**\n * Validate a Brazilian CNPJ (Business Tax ID)\n * @param cnpj - The CNPJ to validate (14 digits)\n */\nexport function validateCNPJ(cnpj: string): boolean {\n const cleaned = cleanDigits(cnpj);\n\n if (cleaned.length !== 14) {\n return false;\n }\n\n // Check for known invalid CNPJs (all same digits)\n if (/^(\\d)\\1+$/.test(cleaned)) {\n return false;\n }\n\n // Calculate first check digit\n const digit1 = calcCheckDigit(cleaned.slice(0, 12), CNPJ_WEIGHTS_1);\n if (digit1 !== parseInt(cleaned[12], 10)) {\n return false;\n }\n\n // Calculate second check digit\n const digit2 = calcCheckDigit(cleaned.slice(0, 13), CNPJ_WEIGHTS_2);\n return digit2 === parseInt(cleaned[13], 10);\n}\n\n/**\n * Format a CNPJ for display\n * @returns Formatted CNPJ (e.g., \"12.345.678/0001-95\")\n */\nexport function formatCNPJ(cnpj: string): string {\n const cleaned = cleanDigits(cnpj).padStart(14, '0');\n return `${cleaned.slice(0, 2)}.${cleaned.slice(2, 5)}.${cleaned.slice(5, 8)}/${cleaned.slice(8, 12)}-${cleaned.slice(12)}`;\n}\n\n/**\n * Clean a CNPJ\n */\nexport function cleanCNPJ(cnpj: string): string {\n return cleanDigits(cnpj);\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';function i(t){return t.replace(/[^a-zA-Z0-9]/g,"")}function s(t){return t.replace(/\D/g,"")}var l=[2,3,4,5,6,7];function a(t){let n=s(t).split("").reverse(),r=0;for(let c=0;c<n.length;c++)r+=parseInt(n[c],10)*l[c%l.length];let o=11-r%11;return o===11?"0":o===10?"K":String(o)}function u(t){let e=i(t).toUpperCase();if(e.length<8||e.length>9)return false;let n=e.slice(0,-1),r=e.slice(-1);return /^\d+$/.test(n)?a(n)===r:false}function g(t){let e=i(t).toUpperCase();if(e.length<2)return t;let n=e.slice(0,-1),r=e.slice(-1);return `${n.replace(/\B(?=(\d{3})+(?!\d))/g,".")}-${r}`}function p(t){return i(t).toUpperCase()}var d=u,x=g,h=p;exports.calculateRUTCheckDigit=a;exports.cleanRUN=h;exports.cleanRUT=p;exports.formatRUN=x;exports.formatRUT=g;exports.validateRUN=d;exports.validateRUT=u;//# sourceMappingURL=cl.cjs.map
|
|
2
|
+
//# sourceMappingURL=cl.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils.ts","../../src/locales/cl.ts"],"names":["cleanDocument","value","cleanDigits","RUT_WEIGHTS","calculateRUTCheckDigit","rut","reversed","sum","i","remainder","validateRUT","cleaned","body","checkDigit","formatRUT","cleanRUT","validateRUN","formatRUN","cleanRUN"],"mappings":"aAGO,SAASA,EAAcC,CAAAA,CAAuB,CACnD,OAAOA,CAAAA,CAAM,OAAA,CAAQ,gBAAiB,EAAE,CAC1C,CAKO,SAASC,CAAAA,CAAYD,EAAuB,CACjD,OAAOA,EAAM,OAAA,CAAQ,KAAA,CAAO,EAAE,CAChC,CCPA,IAAME,CAAAA,CAAc,CAAC,CAAA,CAAG,CAAA,CAAG,EAAG,CAAA,CAAG,CAAA,CAAG,CAAC,CAAA,CAO9B,SAASC,EAAuBC,CAAAA,CAAqB,CAE1D,IAAMC,CAAAA,CADUJ,CAAAA,CAAYG,CAAG,CAAA,CACN,KAAA,CAAM,EAAE,CAAA,CAAE,OAAA,EAAQ,CAEvCE,CAAAA,CAAM,EACV,IAAA,IAASC,CAAAA,CAAI,EAAGA,CAAAA,CAAIF,CAAAA,CAA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WH","file":"cl.cjs","sourcesContent":["/**\n * Remove all non-alphanumeric characters\n */\nexport function cleanDocument(value: string): string {\n return value.replace(/[^a-zA-Z0-9]/g, '');\n}\n\n/**\n * Remove all non-digit characters\n */\nexport function cleanDigits(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Pad a string with leading zeros\n */\nexport function padStart(value: string, length: number): string {\n return value.padStart(length, '0');\n}\n\n/**\n * Calculate modulo 11 check digit (common algorithm)\n */\nexport function mod11(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n sum += parseInt(digits[i], 10) * weights[i % weights.length];\n }\n const remainder = sum % 11;\n return remainder;\n}\n\n/**\n * Calculate modulo 10 check digit (Luhn-like algorithms)\n */\nexport function mod10(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n let product = parseInt(digits[i], 10) * weights[i % weights.length];\n if (product > 9) {\n product = Math.floor(product / 10) + (product % 10);\n }\n sum += product;\n }\n return sum % 10;\n}\n","import { cleanDocument, cleanDigits } from '../core/utils.js';\n\n/**\n * RUT/RUN validation weights\n */\nconst RUT_WEIGHTS = [2, 3, 4, 5, 6, 7];\n\n/**\n * Calculate RUT check digit\n * @param rut - The RUT body (without check digit)\n * @returns The check digit (0-9 or 'K')\n */\nexport function calculateRUTCheckDigit(rut: string): string {\n const cleaned = cleanDigits(rut);\n const reversed = cleaned.split('').reverse();\n\n let sum = 0;\n for (let i = 0; i < reversed.length; i++) {\n sum += parseInt(reversed[i], 10) * RUT_WEIGHTS[i % RUT_WEIGHTS.length];\n }\n\n const remainder = 11 - (sum % 11);\n\n if (remainder === 11) return '0';\n if (remainder === 10) return 'K';\n return String(remainder);\n}\n\n/**\n * Validate a Chilean RUT (Rol Único Tributario)\n * @param rut - The RUT to validate (e.g., \"12.345.678-5\" or \"12345678-K\")\n */\nexport function validateRUT(rut: string): boolean {\n const cleaned = cleanDocument(rut).toUpperCase();\n\n if (cleaned.length < 8 || cleaned.length > 9) {\n return false;\n }\n\n const body = cleaned.slice(0, -1);\n const checkDigit = cleaned.slice(-1);\n\n // Body must be all digits\n if (!/^\\d+$/.test(body)) {\n return false;\n }\n\n return calculateRUTCheckDigit(body) === checkDigit;\n}\n\n/**\n * Format a RUT for display\n * @returns Formatted RUT (e.g., \"12.345.678-5\")\n */\nexport function formatRUT(rut: string): string {\n const cleaned = cleanDocument(rut).toUpperCase();\n\n if (cleaned.length < 2) {\n return rut;\n }\n\n const body = cleaned.slice(0, -1);\n const checkDigit = cleaned.slice(-1);\n\n // Format with dots every 3 digits from right\n const formatted = body.replace(/\\B(?=(\\d{3})+(?!\\d))/g, '.');\n\n return `${formatted}-${checkDigit}`;\n}\n\n/**\n * Clean a RUT\n */\nexport function cleanRUT(rut: string): string {\n return cleanDocument(rut).toUpperCase();\n}\n\n/**\n * Validate a Chilean RUN (same algorithm as RUT)\n */\nexport const validateRUN = validateRUT;\nexport const formatRUN = formatRUT;\nexport const cleanRUN = cleanRUT;\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate RUT check digit
|
|
3
|
+
* @param rut - The RUT body (without check digit)
|
|
4
|
+
* @returns The check digit (0-9 or 'K')
|
|
5
|
+
*/
|
|
6
|
+
declare function calculateRUTCheckDigit(rut: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Validate a Chilean RUT (Rol Único Tributario)
|
|
9
|
+
* @param rut - The RUT to validate (e.g., "12.345.678-5" or "12345678-K")
|
|
10
|
+
*/
|
|
11
|
+
declare function validateRUT(rut: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Format a RUT for display
|
|
14
|
+
* @returns Formatted RUT (e.g., "12.345.678-5")
|
|
15
|
+
*/
|
|
16
|
+
declare function formatRUT(rut: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Clean a RUT
|
|
19
|
+
*/
|
|
20
|
+
declare function cleanRUT(rut: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Validate a Chilean RUN (same algorithm as RUT)
|
|
23
|
+
*/
|
|
24
|
+
declare const validateRUN: typeof validateRUT;
|
|
25
|
+
declare const formatRUN: typeof formatRUT;
|
|
26
|
+
declare const cleanRUN: typeof cleanRUT;
|
|
27
|
+
|
|
28
|
+
export { calculateRUTCheckDigit, cleanRUN, cleanRUT, formatRUN, formatRUT, validateRUN, validateRUT };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate RUT check digit
|
|
3
|
+
* @param rut - The RUT body (without check digit)
|
|
4
|
+
* @returns The check digit (0-9 or 'K')
|
|
5
|
+
*/
|
|
6
|
+
declare function calculateRUTCheckDigit(rut: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Validate a Chilean RUT (Rol Único Tributario)
|
|
9
|
+
* @param rut - The RUT to validate (e.g., "12.345.678-5" or "12345678-K")
|
|
10
|
+
*/
|
|
11
|
+
declare function validateRUT(rut: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Format a RUT for display
|
|
14
|
+
* @returns Formatted RUT (e.g., "12.345.678-5")
|
|
15
|
+
*/
|
|
16
|
+
declare function formatRUT(rut: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Clean a RUT
|
|
19
|
+
*/
|
|
20
|
+
declare function cleanRUT(rut: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Validate a Chilean RUN (same algorithm as RUT)
|
|
23
|
+
*/
|
|
24
|
+
declare const validateRUN: typeof validateRUT;
|
|
25
|
+
declare const formatRUN: typeof formatRUT;
|
|
26
|
+
declare const cleanRUN: typeof cleanRUT;
|
|
27
|
+
|
|
28
|
+
export { calculateRUTCheckDigit, cleanRUN, cleanRUT, formatRUN, formatRUT, validateRUN, validateRUT };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function i(t){return t.replace(/[^a-zA-Z0-9]/g,"")}function s(t){return t.replace(/\D/g,"")}var l=[2,3,4,5,6,7];function a(t){let n=s(t).split("").reverse(),r=0;for(let c=0;c<n.length;c++)r+=parseInt(n[c],10)*l[c%l.length];let o=11-r%11;return o===11?"0":o===10?"K":String(o)}function u(t){let e=i(t).toUpperCase();if(e.length<8||e.length>9)return false;let n=e.slice(0,-1),r=e.slice(-1);return /^\d+$/.test(n)?a(n)===r:false}function g(t){let e=i(t).toUpperCase();if(e.length<2)return t;let n=e.slice(0,-1),r=e.slice(-1);return `${n.replace(/\B(?=(\d{3})+(?!\d))/g,".")}-${r}`}function p(t){return i(t).toUpperCase()}var d=u,x=g,h=p;export{a as calculateRUTCheckDigit,h as cleanRUN,p as cleanRUT,x as formatRUN,g as formatRUT,d as validateRUN,u as validateRUT};//# sourceMappingURL=cl.js.map
|
|
2
|
+
//# sourceMappingURL=cl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils.ts","../../src/locales/cl.ts"],"names":["cleanDocument","value","cleanDigits","RUT_WEIGHTS","calculateRUTCheckDigit","rut","reversed","sum","i","remainder","validateRUT","cleaned","body","checkDigit","formatRUT","cleanRUT","validateRUN","formatRUN","cleanRUN"],"mappings":"AAGO,SAASA,EAAcC,CAAAA,CAAuB,CACnD,OAAOA,CAAAA,CAAM,OAAA,CAAQ,gBAAiB,EAAE,CAC1C,CAKO,SAASC,CAAAA,CAAYD,EAAuB,CACjD,OAAOA,EAAM,OAAA,CAAQ,KAAA,CAAO,EAAE,CAChC,CCPA,IAAME,CAAAA,CAAc,CAAC,CAAA,CAAG,CAAA,CAAG,EAAG,CAAA,CAAG,CAAA,CAAG,CAAC,CAAA,CAO9B,SAASC,EAAuBC,CAAAA,CAAqB,CAE1D,IAAMC,CAAAA,CADUJ,CAAAA,CAAYG,CAAG,CAAA,CACN,KAAA,CAAM,EAAE,CAAA,CAAE,OAAA,EAAQ,CAEvCE,CAAAA,CAAM,EACV,IAAA,IAASC,CAAAA,CAAI,EAAGA,CAAAA,CAAIF,CAAAA,CAAS,OAAQE,CAAAA,EAAAA,CACnCD,CAAAA,EA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eric characters\n */\nexport function cleanDocument(value: string): string {\n return value.replace(/[^a-zA-Z0-9]/g, '');\n}\n\n/**\n * Remove all non-digit characters\n */\nexport function cleanDigits(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Pad a string with leading zeros\n */\nexport function padStart(value: string, length: number): string {\n return value.padStart(length, '0');\n}\n\n/**\n * Calculate modulo 11 check digit (common algorithm)\n */\nexport function mod11(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n sum += parseInt(digits[i], 10) * weights[i % weights.length];\n }\n const remainder = sum % 11;\n return remainder;\n}\n\n/**\n * Calculate modulo 10 check digit (Luhn-like algorithms)\n */\nexport function mod10(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n let product = parseInt(digits[i], 10) * weights[i % weights.length];\n if (product > 9) {\n product = Math.floor(product / 10) + (product % 10);\n }\n sum += product;\n }\n return sum % 10;\n}\n","import { cleanDocument, cleanDigits } from '../core/utils.js';\n\n/**\n * RUT/RUN validation weights\n */\nconst RUT_WEIGHTS = [2, 3, 4, 5, 6, 7];\n\n/**\n * Calculate RUT check digit\n * @param rut - The RUT body (without check digit)\n * @returns The check digit (0-9 or 'K')\n */\nexport function calculateRUTCheckDigit(rut: string): string {\n const cleaned = cleanDigits(rut);\n const reversed = cleaned.split('').reverse();\n\n let sum = 0;\n for (let i = 0; i < reversed.length; i++) {\n sum += parseInt(reversed[i], 10) * RUT_WEIGHTS[i % RUT_WEIGHTS.length];\n }\n\n const remainder = 11 - (sum % 11);\n\n if (remainder === 11) return '0';\n if (remainder === 10) return 'K';\n return String(remainder);\n}\n\n/**\n * Validate a Chilean RUT (Rol Único Tributario)\n * @param rut - The RUT to validate (e.g., \"12.345.678-5\" or \"12345678-K\")\n */\nexport function validateRUT(rut: string): boolean {\n const cleaned = cleanDocument(rut).toUpperCase();\n\n if (cleaned.length < 8 || cleaned.length > 9) {\n return false;\n }\n\n const body = cleaned.slice(0, -1);\n const checkDigit = cleaned.slice(-1);\n\n // Body must be all digits\n if (!/^\\d+$/.test(body)) {\n return false;\n }\n\n return calculateRUTCheckDigit(body) === checkDigit;\n}\n\n/**\n * Format a RUT for display\n * @returns Formatted RUT (e.g., \"12.345.678-5\")\n */\nexport function formatRUT(rut: string): string {\n const cleaned = cleanDocument(rut).toUpperCase();\n\n if (cleaned.length < 2) {\n return rut;\n }\n\n const body = cleaned.slice(0, -1);\n const checkDigit = cleaned.slice(-1);\n\n // Format with dots every 3 digits from right\n const formatted = body.replace(/\\B(?=(\\d{3})+(?!\\d))/g, '.');\n\n return `${formatted}-${checkDigit}`;\n}\n\n/**\n * Clean a RUT\n */\nexport function cleanRUT(rut: string): string {\n return cleanDocument(rut).toUpperCase();\n}\n\n/**\n * Validate a Chilean RUN (same algorithm as RUT)\n */\nexport const validateRUN = validateRUT;\nexport const formatRUN = formatRUT;\nexport const cleanRUN = cleanRUT;\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';function e(n){return n.replace(/\D/g,"")}var l=[3,7,13,17,19,23,29,37,41,43,47,53,59,67,71];function s(n){let t=e(n);if(t.length<8||t.length>15)throw new Error("NIT must be between 8 and 15 digits");let r=0,o=t.split("").reverse();for(let c=0;c<o.length;c++)r+=parseInt(o[c],10)*l[c];let i=r%11;return i===0?"0":i===1?"1":String(11-i)}function u(n){let t=e(n);if(t.length<9||t.length>16)return false;let r=t.slice(0,-1),o=t.slice(-1);try{return s(r)===o}catch{return false}}function f(n){let t=e(n);if(t.length<9)return n;let r=t.slice(0,-1),o=t.slice(-1);return `${r.replace(/\B(?=(\d{3})+(?!\d))/g,".")}-${o}`}function d(n){return e(n)}function p(n){let t=e(n);return t.length>=6&&t.length<=10}function m(n){return e(n).replace(/\B(?=(\d{3})+(?!\d))/g,".")}function h(n){return e(n)}function x(n){let t=e(n);return t.length>=6&&t.length<=10}function b(n){let t=e(n);return t.length>=10&&t.length<=11}exports.calculateNITCheckDigit=s;exports.cleanCC=h;exports.cleanNIT=d;exports.formatCC=m;exports.formatNIT=f;exports.validateCC=p;exports.validateCE=x;exports.validateNIT=u;exports.validateTI=b;//# sourceMappingURL=co.cjs.map
|
|
2
|
+
//# sourceMappingURL=co.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils.ts","../../src/locales/co.ts"],"names":["cleanDigits","value","NIT_WEIGHTS","calculateNITCheckDigit","nit","cleaned","sum","reversed","i","remainder","validateNIT","body","checkDigit","formatNIT","cleanNIT","validateCC","cc","formatCC","cleanCC","validateCE","ce","validateTI","ti"],"mappings":"aAUO,SAASA,CAAAA,CAAYC,CAAAA,CAAuB,CACjD,OAAOA,CAAAA,CAAM,OAAA,CAAQ,KAAA,CAAO,EAAE,CAChC,CCNA,IAAMC,CAAAA,CAAc,CAAC,CAAA,CAAG,CAAA,CAAG,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAE,CAAA,CAOtE,SAASC,CAAAA,CAAuBC,CAAAA,CAAqB,CAC1D,IAAMC,CAAAA,CAAUL,CAAAA,CAAYI,CAAG,CAAA,CAE/B,GAAIC,CAAAA,CAAQ,MAAA,CAAS,CAAA,EAAKA,CAAAA,CAAQ,MAAA,CAAS,EAAA,CACzC,MAAM,IAAI,KAAA,CAAM,qCAAqC,CAAA,CAGvD,IAAIC,CAAAA,CAAM,CAAA,CACJC,CAAAA,CAAWF,CAAAA,CAAQ,KAAA,CAAM,EAAE,CAAA,CAAE,OAAA,EAAQ,CAE3C,IAAA,IAASG,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAID,CAAAA,CAAS,MAAA,CAAQC,CAAAA,EAAAA,CACnCF,CAAAA,EAAO,QAAA,CAASC,CAAAA,CAASC,CAAC,CAAA,CAAG,EAAE,CAAA,CAAIN,CAAA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AA,CAC9B,OAAOX,CAAAA,CAAQ,MAAA,EAAU,CAAA,EAAKA,CAAAA,CAAQ,MAAA,EAAU,EAClD,CAKO,SAASY,CAAAA,CAASD,CAAAA,CAAoB,CAE3C,OADgBhB,CAAAA,CAAYgB,CAAE,CAAA,CACf,OAAA,CAAQ,uBAAA,CAAyB,GAAG,CACrD,CAKO,SAASE,CAAAA,CAAQF,CAAAA,CAAoB,CAC1C,OAAOhB,CAAAA,CAAYgB,CAAE,CACvB,CAMO,SAASG,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,IAAMf,CAAAA,CAAUL,CAAAA,CAAYoB,CAAE,CAAA,CAC9B,OAAOf,CAAAA,CAAQ,MAAA,EAAU,CAAA,EAAKA,CAAAA,CAAQ,MAAA,EAAU,EAClD,CAMO,SAASgB,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,IAAMjB,CAAAA,CAAUL,CAAAA,CAAYsB,CAAE,CAAA,CAC9B,OAAOjB,CAAAA,CAAQ,MAAA,EAAU,EAAA,EAAMA,CAAAA,CAAQ,QAAU,EACnD","file":"co.cjs","sourcesContent":["/**\n * Remove all non-alphanumeric characters\n */\nexport function cleanDocument(value: string): string {\n return value.replace(/[^a-zA-Z0-9]/g, '');\n}\n\n/**\n * Remove all non-digit characters\n */\nexport function cleanDigits(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Pad a string with leading zeros\n */\nexport function padStart(value: string, length: number): string {\n return value.padStart(length, '0');\n}\n\n/**\n * Calculate modulo 11 check digit (common algorithm)\n */\nexport function mod11(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n sum += parseInt(digits[i], 10) * weights[i % weights.length];\n }\n const remainder = sum % 11;\n return remainder;\n}\n\n/**\n * Calculate modulo 10 check digit (Luhn-like algorithms)\n */\nexport function mod10(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n let product = parseInt(digits[i], 10) * weights[i % weights.length];\n if (product > 9) {\n product = Math.floor(product / 10) + (product % 10);\n }\n sum += product;\n }\n return sum % 10;\n}\n","import { cleanDigits } from '../core/utils.js';\n\n/**\n * NIT verification weights (Colombian tax ID)\n * Algorithm: Multiply each digit by its weight, sum, mod 11\n */\nconst NIT_WEIGHTS = [3, 7, 13, 17, 19, 23, 29, 37, 41, 43, 47, 53, 59, 67, 71];\n\n/**\n * Calculate the NIT check digit\n * @param nit - The NIT without check digit (8-15 digits)\n * @returns The check digit (0-9)\n */\nexport function calculateNITCheckDigit(nit: string): string {\n const cleaned = cleanDigits(nit);\n\n if (cleaned.length < 8 || cleaned.length > 15) {\n throw new Error('NIT must be between 8 and 15 digits');\n }\n\n let sum = 0;\n const reversed = cleaned.split('').reverse();\n\n for (let i = 0; i < reversed.length; i++) {\n sum += parseInt(reversed[i], 10) * NIT_WEIGHTS[i];\n }\n\n const remainder = sum % 11;\n\n if (remainder === 0) return '0';\n if (remainder === 1) return '1';\n return String(11 - remainder);\n}\n\n/**\n * Validate a Colombian NIT\n * @param nit - The NIT to validate (with or without check digit)\n * @returns true if valid\n */\nexport function validateNIT(nit: string): boolean {\n const cleaned = cleanDigits(nit);\n\n if (cleaned.length < 9 || cleaned.length > 16) {\n return false;\n }\n\n const body = cleaned.slice(0, -1);\n const checkDigit = cleaned.slice(-1);\n\n try {\n return calculateNITCheckDigit(body) === checkDigit;\n } catch {\n return false;\n }\n}\n\n/**\n * Format a NIT for display\n * @param nit - The NIT to format\n * @returns Formatted NIT (e.g., \"900.123.456-7\")\n */\nexport function formatNIT(nit: string): string {\n const cleaned = cleanDigits(nit);\n\n if (cleaned.length < 9) {\n return nit;\n }\n\n const body = cleaned.slice(0, -1);\n const checkDigit = cleaned.slice(-1);\n\n // Format with dots every 3 digits from right\n const formatted = body.replace(/\\B(?=(\\d{3})+(?!\\d))/g, '.');\n\n return `${formatted}-${checkDigit}`;\n}\n\n/**\n * Clean a NIT (remove all formatting)\n */\nexport function cleanNIT(nit: string): string {\n return cleanDigits(nit);\n}\n\n/**\n * Validate a Colombian Cédula de Ciudadanía (CC)\n * @param cc - The CC number (6-10 digits)\n * @returns true if valid format\n */\nexport function validateCC(cc: string): boolean {\n const cleaned = cleanDigits(cc);\n return cleaned.length >= 6 && cleaned.length <= 10;\n}\n\n/**\n * Format a Cédula for display\n */\nexport function formatCC(cc: string): string {\n const cleaned = cleanDigits(cc);\n return cleaned.replace(/\\B(?=(\\d{3})+(?!\\d))/g, '.');\n}\n\n/**\n * Clean a Cédula\n */\nexport function cleanCC(cc: string): string {\n return cleanDigits(cc);\n}\n\n/**\n * Validate a Cédula de Extranjería (CE)\n * @param ce - The CE number (6-10 digits)\n */\nexport function validateCE(ce: string): boolean {\n const cleaned = cleanDigits(ce);\n return cleaned.length >= 6 && cleaned.length <= 10;\n}\n\n/**\n * Validate a Tarjeta de Identidad (TI)\n * @param ti - The TI number (10-11 digits)\n */\nexport function validateTI(ti: string): boolean {\n const cleaned = cleanDigits(ti);\n return cleaned.length >= 10 && cleaned.length <= 11;\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the NIT check digit
|
|
3
|
+
* @param nit - The NIT without check digit (8-15 digits)
|
|
4
|
+
* @returns The check digit (0-9)
|
|
5
|
+
*/
|
|
6
|
+
declare function calculateNITCheckDigit(nit: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Validate a Colombian NIT
|
|
9
|
+
* @param nit - The NIT to validate (with or without check digit)
|
|
10
|
+
* @returns true if valid
|
|
11
|
+
*/
|
|
12
|
+
declare function validateNIT(nit: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Format a NIT for display
|
|
15
|
+
* @param nit - The NIT to format
|
|
16
|
+
* @returns Formatted NIT (e.g., "900.123.456-7")
|
|
17
|
+
*/
|
|
18
|
+
declare function formatNIT(nit: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Clean a NIT (remove all formatting)
|
|
21
|
+
*/
|
|
22
|
+
declare function cleanNIT(nit: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Validate a Colombian Cédula de Ciudadanía (CC)
|
|
25
|
+
* @param cc - The CC number (6-10 digits)
|
|
26
|
+
* @returns true if valid format
|
|
27
|
+
*/
|
|
28
|
+
declare function validateCC(cc: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Format a Cédula for display
|
|
31
|
+
*/
|
|
32
|
+
declare function formatCC(cc: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Clean a Cédula
|
|
35
|
+
*/
|
|
36
|
+
declare function cleanCC(cc: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Validate a Cédula de Extranjería (CE)
|
|
39
|
+
* @param ce - The CE number (6-10 digits)
|
|
40
|
+
*/
|
|
41
|
+
declare function validateCE(ce: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Validate a Tarjeta de Identidad (TI)
|
|
44
|
+
* @param ti - The TI number (10-11 digits)
|
|
45
|
+
*/
|
|
46
|
+
declare function validateTI(ti: string): boolean;
|
|
47
|
+
|
|
48
|
+
export { calculateNITCheckDigit, cleanCC, cleanNIT, formatCC, formatNIT, validateCC, validateCE, validateNIT, validateTI };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the NIT check digit
|
|
3
|
+
* @param nit - The NIT without check digit (8-15 digits)
|
|
4
|
+
* @returns The check digit (0-9)
|
|
5
|
+
*/
|
|
6
|
+
declare function calculateNITCheckDigit(nit: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Validate a Colombian NIT
|
|
9
|
+
* @param nit - The NIT to validate (with or without check digit)
|
|
10
|
+
* @returns true if valid
|
|
11
|
+
*/
|
|
12
|
+
declare function validateNIT(nit: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Format a NIT for display
|
|
15
|
+
* @param nit - The NIT to format
|
|
16
|
+
* @returns Formatted NIT (e.g., "900.123.456-7")
|
|
17
|
+
*/
|
|
18
|
+
declare function formatNIT(nit: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Clean a NIT (remove all formatting)
|
|
21
|
+
*/
|
|
22
|
+
declare function cleanNIT(nit: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Validate a Colombian Cédula de Ciudadanía (CC)
|
|
25
|
+
* @param cc - The CC number (6-10 digits)
|
|
26
|
+
* @returns true if valid format
|
|
27
|
+
*/
|
|
28
|
+
declare function validateCC(cc: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Format a Cédula for display
|
|
31
|
+
*/
|
|
32
|
+
declare function formatCC(cc: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Clean a Cédula
|
|
35
|
+
*/
|
|
36
|
+
declare function cleanCC(cc: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Validate a Cédula de Extranjería (CE)
|
|
39
|
+
* @param ce - The CE number (6-10 digits)
|
|
40
|
+
*/
|
|
41
|
+
declare function validateCE(ce: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Validate a Tarjeta de Identidad (TI)
|
|
44
|
+
* @param ti - The TI number (10-11 digits)
|
|
45
|
+
*/
|
|
46
|
+
declare function validateTI(ti: string): boolean;
|
|
47
|
+
|
|
48
|
+
export { calculateNITCheckDigit, cleanCC, cleanNIT, formatCC, formatNIT, validateCC, validateCE, validateNIT, validateTI };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(n){return n.replace(/\D/g,"")}var l=[3,7,13,17,19,23,29,37,41,43,47,53,59,67,71];function s(n){let t=e(n);if(t.length<8||t.length>15)throw new Error("NIT must be between 8 and 15 digits");let r=0,o=t.split("").reverse();for(let c=0;c<o.length;c++)r+=parseInt(o[c],10)*l[c];let i=r%11;return i===0?"0":i===1?"1":String(11-i)}function u(n){let t=e(n);if(t.length<9||t.length>16)return false;let r=t.slice(0,-1),o=t.slice(-1);try{return s(r)===o}catch{return false}}function f(n){let t=e(n);if(t.length<9)return n;let r=t.slice(0,-1),o=t.slice(-1);return `${r.replace(/\B(?=(\d{3})+(?!\d))/g,".")}-${o}`}function d(n){return e(n)}function p(n){let t=e(n);return t.length>=6&&t.length<=10}function m(n){return e(n).replace(/\B(?=(\d{3})+(?!\d))/g,".")}function h(n){return e(n)}function x(n){let t=e(n);return t.length>=6&&t.length<=10}function b(n){let t=e(n);return t.length>=10&&t.length<=11}export{s as calculateNITCheckDigit,h as cleanCC,d as cleanNIT,m as formatCC,f as formatNIT,p as validateCC,x as validateCE,u as validateNIT,b as validateTI};//# sourceMappingURL=co.js.map
|
|
2
|
+
//# sourceMappingURL=co.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils.ts","../../src/locales/co.ts"],"names":["cleanDigits","value","NIT_WEIGHTS","calculateNITCheckDigit","nit","cleaned","sum","reversed","i","remainder","validateNIT","body","checkDigit","formatNIT","cleanNIT","validateCC","cc","formatCC","cleanCC","validateCE","ce","validateTI","ti"],"mappings":"AAUO,SAASA,CAAAA,CAAYC,CAAAA,CAAuB,CACjD,OAAOA,CAAAA,CAAM,OAAA,CAAQ,KAAA,CAAO,EAAE,CAChC,CCNA,IAAMC,CAAAA,CAAc,CAAC,CAAA,CAAG,CAAA,CAAG,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAA,CAAI,EAAE,CAAA,CAOtE,SAASC,CAAAA,CAAuBC,CAAAA,CAAqB,CAC1D,IAAMC,CAAAA,CAAUL,CAAAA,CAAYI,CAAG,CAAA,CAE/B,GAAIC,CAAAA,CAAQ,MAAA,CAAS,CAAA,EAAKA,CAAAA,CAAQ,MAAA,CAAS,EAAA,CACzC,MAAM,IAAI,KAAA,CAAM,qCAAqC,CAAA,CAGvD,IAAIC,CAAAA,CAAM,CAAA,CACJC,CAAAA,CAAWF,CAAAA,CAAQ,KAAA,CAAM,EAAE,CAAA,CAAE,OAAA,EAAQ,C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AAA,CACnC,CAKO,SAASE,CAAAA,CAASV,CAAAA,CAAqB,CAC5C,OAAOJ,CAAAA,CAAYI,CAAG,CACxB,CAOO,SAASW,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,IAAMX,CAAAA,CAAUL,CAAAA,CAAYgB,CAAE,CAAA,CAC9B,OAAOX,CAAAA,CAAQ,MAAA,EAAU,CAAA,EAAKA,CAAAA,CAAQ,MAAA,EAAU,EAClD,CAKO,SAASY,CAAAA,CAASD,CAAAA,CAAoB,CAE3C,OADgBhB,CAAAA,CAAYgB,CAAE,CAAA,CACf,OAAA,CAAQ,uBAAA,CAAyB,GAAG,CACrD,CAKO,SAASE,CAAAA,CAAQF,CAAAA,CAAoB,CAC1C,OAAOhB,CAAAA,CAAYgB,CAAE,CACvB,CAMO,SAASG,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,IAAMf,CAAAA,CAAUL,CAAAA,CAAYoB,CAAE,CAAA,CAC9B,OAAOf,CAAAA,CAAQ,MAAA,EAAU,CAAA,EAAKA,CAAAA,CAAQ,MAAA,EAAU,EAClD,CAMO,SAASgB,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,IAAMjB,CAAAA,CAAUL,CAAAA,CAAYsB,CAAE,CAAA,CAC9B,OAAOjB,CAAAA,CAAQ,MAAA,EAAU,EAAA,EAAMA,CAAAA,CAAQ,QAAU,EACnD","file":"co.js","sourcesContent":["/**\n * Remove all non-alphanumeric characters\n */\nexport function cleanDocument(value: string): string {\n return value.replace(/[^a-zA-Z0-9]/g, '');\n}\n\n/**\n * Remove all non-digit characters\n */\nexport function cleanDigits(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Pad a string with leading zeros\n */\nexport function padStart(value: string, length: number): string {\n return value.padStart(length, '0');\n}\n\n/**\n * Calculate modulo 11 check digit (common algorithm)\n */\nexport function mod11(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n sum += parseInt(digits[i], 10) * weights[i % weights.length];\n }\n const remainder = sum % 11;\n return remainder;\n}\n\n/**\n * Calculate modulo 10 check digit (Luhn-like algorithms)\n */\nexport function mod10(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n let product = parseInt(digits[i], 10) * weights[i % weights.length];\n if (product > 9) {\n product = Math.floor(product / 10) + (product % 10);\n }\n sum += product;\n }\n return sum % 10;\n}\n","import { cleanDigits } from '../core/utils.js';\n\n/**\n * NIT verification weights (Colombian tax ID)\n * Algorithm: Multiply each digit by its weight, sum, mod 11\n */\nconst NIT_WEIGHTS = [3, 7, 13, 17, 19, 23, 29, 37, 41, 43, 47, 53, 59, 67, 71];\n\n/**\n * Calculate the NIT check digit\n * @param nit - The NIT without check digit (8-15 digits)\n * @returns The check digit (0-9)\n */\nexport function calculateNITCheckDigit(nit: string): string {\n const cleaned = cleanDigits(nit);\n\n if (cleaned.length < 8 || cleaned.length > 15) {\n throw new Error('NIT must be between 8 and 15 digits');\n }\n\n let sum = 0;\n const reversed = cleaned.split('').reverse();\n\n for (let i = 0; i < reversed.length; i++) {\n sum += parseInt(reversed[i], 10) * NIT_WEIGHTS[i];\n }\n\n const remainder = sum % 11;\n\n if (remainder === 0) return '0';\n if (remainder === 1) return '1';\n return String(11 - remainder);\n}\n\n/**\n * Validate a Colombian NIT\n * @param nit - The NIT to validate (with or without check digit)\n * @returns true if valid\n */\nexport function validateNIT(nit: string): boolean {\n const cleaned = cleanDigits(nit);\n\n if (cleaned.length < 9 || cleaned.length > 16) {\n return false;\n }\n\n const body = cleaned.slice(0, -1);\n const checkDigit = cleaned.slice(-1);\n\n try {\n return calculateNITCheckDigit(body) === checkDigit;\n } catch {\n return false;\n }\n}\n\n/**\n * Format a NIT for display\n * @param nit - The NIT to format\n * @returns Formatted NIT (e.g., \"900.123.456-7\")\n */\nexport function formatNIT(nit: string): string {\n const cleaned = cleanDigits(nit);\n\n if (cleaned.length < 9) {\n return nit;\n }\n\n const body = cleaned.slice(0, -1);\n const checkDigit = cleaned.slice(-1);\n\n // Format with dots every 3 digits from right\n const formatted = body.replace(/\\B(?=(\\d{3})+(?!\\d))/g, '.');\n\n return `${formatted}-${checkDigit}`;\n}\n\n/**\n * Clean a NIT (remove all formatting)\n */\nexport function cleanNIT(nit: string): string {\n return cleanDigits(nit);\n}\n\n/**\n * Validate a Colombian Cédula de Ciudadanía (CC)\n * @param cc - The CC number (6-10 digits)\n * @returns true if valid format\n */\nexport function validateCC(cc: string): boolean {\n const cleaned = cleanDigits(cc);\n return cleaned.length >= 6 && cleaned.length <= 10;\n}\n\n/**\n * Format a Cédula for display\n */\nexport function formatCC(cc: string): string {\n const cleaned = cleanDigits(cc);\n return cleaned.replace(/\\B(?=(\\d{3})+(?!\\d))/g, '.');\n}\n\n/**\n * Clean a Cédula\n */\nexport function cleanCC(cc: string): string {\n return cleanDigits(cc);\n}\n\n/**\n * Validate a Cédula de Extranjería (CE)\n * @param ce - The CE number (6-10 digits)\n */\nexport function validateCE(ce: string): boolean {\n const cleaned = cleanDigits(ce);\n return cleaned.length >= 6 && cleaned.length <= 10;\n}\n\n/**\n * Validate a Tarjeta de Identidad (TI)\n * @param ti - The TI number (10-11 digits)\n */\nexport function validateTI(ti: string): boolean {\n const cleaned = cleanDigits(ti);\n return cleaned.length >= 10 && cleaned.length <= 11;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';function n(t){return t.replace(/[^a-zA-Z0-9]/g,"")}var u=/^[A-ZÑ&]{4}\d{6}[A-Z0-9]{3}$/,c=/^[A-ZÑ&]{3}\d{6}[A-Z0-9]{3}$/,p=/^[A-Z]{4}\d{6}[HM][A-Z]{5}[A-Z0-9]\d$/;function d(t){let e=n(t).toUpperCase();return e.length!==12&&e.length!==13?false:e.length===13?u.test(e):c.test(e)}function m(t){return n(t).toUpperCase()}function h(t){return n(t).toUpperCase()}function R(t){let e=n(t).toUpperCase();return e.length!==18||!p.test(e)?false:g(e)}function g(t){let e="0123456789ABCDEFGHIJKLMN\xD1OPQRSTUVWXYZ",r=0;for(let o=0;o<17;o++){let l=t[o],s=e.indexOf(l);if(s===-1)return false;r+=s*(18-o);}return (10-r%10)%10===parseInt(t[17],10)}function U(t){return n(t).toUpperCase()}function x(t){return n(t).toUpperCase()}function A(t){let e=n(t).toUpperCase();if(e.length<11)return null;let r=e[10];return r==="H"?"M":r==="M"?"F":null}function D(t){let e=n(t).toUpperCase();if(e.length<10)return null;let r=e.slice(4,6),i=e.slice(6,8),o=e.slice(8,10),l=e[16],s;/\d/.test(l)?s=1900+parseInt(r,10):s=2e3+parseInt(r,10);let a=new Date(s,parseInt(i,10)-1,parseInt(o,10));return a.getFullYear()!==s||a.getMonth()!==parseInt(i,10)-1||a.getDate()!==parseInt(o,10)?null:a}exports.cleanCURP=x;exports.cleanRFC=h;exports.formatCURP=U;exports.formatRFC=m;exports.getCURPBirthDate=D;exports.getCURPGender=A;exports.validateCURP=R;exports.validateRFC=d;//# sourceMappingURL=mx.cjs.map
|
|
2
|
+
//# sourceMappingURL=mx.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils.ts","../../src/locales/mx.ts"],"names":["cleanDocument","value","RFC_PATTERN_FISICA","RFC_PATTERN_MORAL","CURP_PATTERN","validateRFC","rfc","cleaned","formatRFC","cleanRFC","validateCURP","curp","validateCURPCheckDigit","dictionary","sum","i","char","formatCURP","cleanCURP","getCURPGender","genderChar","getCURPBirthDate","yearPart","month","day","centuryChar","year","date"],"mappings":"aAGO,SAASA,CAAAA,CAAcC,CAAAA,CAAuB,CACnD,OAAOA,EAAM,OAAA,CAAQ,eAAA,CAAiB,EAAE,CAC1C,CCEA,IAAMC,CAAAA,CAAqB,8BAAA,CACrBC,EAAoB,8BAAA,CAMpBC,CAAAA,CAAe,uCAAA,CAMd,SAASC,CAAAA,CAAYC,CAAAA,CAAsB,CAChD,IAAMC,EAAUP,CAAAA,CAAcM,CAAG,CAAA,CAAE,WAAA,EAAY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AGtE,OACEG,EAAK,WAAA,EAAY,GAAMD,CAAAA,EACvBC,CAAAA,CAAK,QAAA,EAAS,GAAM,QAAA,CAASJ,CAAAA,CAAO,EAAE,CAAA,CAAI,CAAA,EAC1CI,CAAAA,CAAK,OAAA,KAAc,QAAA,CAASH,CAAAA,CAAK,EAAE,CAAA,CAE5B,KAGFG,CACT","file":"mx.cjs","sourcesContent":["/**\n * Remove all non-alphanumeric characters\n */\nexport function cleanDocument(value: string): string {\n return value.replace(/[^a-zA-Z0-9]/g, '');\n}\n\n/**\n * Remove all non-digit characters\n */\nexport function cleanDigits(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Pad a string with leading zeros\n */\nexport function padStart(value: string, length: number): string {\n return value.padStart(length, '0');\n}\n\n/**\n * Calculate modulo 11 check digit (common algorithm)\n */\nexport function mod11(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n sum += parseInt(digits[i], 10) * weights[i % weights.length];\n }\n const remainder = sum % 11;\n return remainder;\n}\n\n/**\n * Calculate modulo 10 check digit (Luhn-like algorithms)\n */\nexport function mod10(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n let product = parseInt(digits[i], 10) * weights[i % weights.length];\n if (product > 9) {\n product = Math.floor(product / 10) + (product % 10);\n }\n sum += product;\n }\n return sum % 10;\n}\n","import { cleanDocument } from '../core/utils.js';\n\n/**\n * Valid RFC patterns\n * - Persona física: 4 letters + 6 digits + 3 alphanumeric (homoclave)\n * - Persona moral: 3 letters + 6 digits + 3 alphanumeric (homoclave)\n */\nconst RFC_PATTERN_FISICA = /^[A-ZÑ&]{4}\\d{6}[A-Z0-9]{3}$/;\nconst RFC_PATTERN_MORAL = /^[A-ZÑ&]{3}\\d{6}[A-Z0-9]{3}$/;\n\n/**\n * CURP pattern\n * 18 characters: 4 letters + 6 digits + 6 letters + 2 alphanumeric\n */\nconst CURP_PATTERN = /^[A-Z]{4}\\d{6}[HM][A-Z]{5}[A-Z0-9]\\d$/;\n\n/**\n * Validate a Mexican RFC (Registro Federal de Contribuyentes)\n * @param rfc - The RFC to validate\n */\nexport function validateRFC(rfc: string): boolean {\n const cleaned = cleanDocument(rfc).toUpperCase();\n\n if (cleaned.length !== 12 && cleaned.length !== 13) {\n return false;\n }\n\n // 12 chars = Persona moral, 13 chars = Persona física\n if (cleaned.length === 13) {\n return RFC_PATTERN_FISICA.test(cleaned);\n }\n\n return RFC_PATTERN_MORAL.test(cleaned);\n}\n\n/**\n * Format an RFC for display (uppercase, no separators)\n */\nexport function formatRFC(rfc: string): string {\n return cleanDocument(rfc).toUpperCase();\n}\n\n/**\n * Clean an RFC\n */\nexport function cleanRFC(rfc: string): string {\n return cleanDocument(rfc).toUpperCase();\n}\n\n/**\n * Validate a Mexican CURP (Clave Única de Registro de Población)\n * @param curp - The CURP to validate (18 characters)\n */\nexport function validateCURP(curp: string): boolean {\n const cleaned = cleanDocument(curp).toUpperCase();\n\n if (cleaned.length !== 18) {\n return false;\n }\n\n if (!CURP_PATTERN.test(cleaned)) {\n return false;\n }\n\n // Validate check digit\n return validateCURPCheckDigit(cleaned);\n}\n\n/**\n * CURP check digit validation\n */\nfunction validateCURPCheckDigit(curp: string): boolean {\n const dictionary = '0123456789ABCDEFGHIJKLMNÑOPQRSTUVWXYZ';\n let sum = 0;\n\n for (let i = 0; i < 17; i++) {\n const char = curp[i];\n const value = dictionary.indexOf(char);\n if (value === -1) return false;\n sum += value * (18 - i);\n }\n\n const checkDigit = (10 - (sum % 10)) % 10;\n return checkDigit === parseInt(curp[17], 10);\n}\n\n/**\n * Format a CURP for display\n */\nexport function formatCURP(curp: string): string {\n return cleanDocument(curp).toUpperCase();\n}\n\n/**\n * Clean a CURP\n */\nexport function cleanCURP(curp: string): string {\n return cleanDocument(curp).toUpperCase();\n}\n\n/**\n * Get the gender from a CURP\n * @returns 'M' for male, 'F' for female, or null if invalid\n */\nexport function getCURPGender(curp: string): 'M' | 'F' | null {\n const cleaned = cleanDocument(curp).toUpperCase();\n if (cleaned.length < 11) return null;\n\n const genderChar = cleaned[10];\n if (genderChar === 'H') return 'M';\n if (genderChar === 'M') return 'F';\n return null;\n}\n\n/**\n * Get the birth date from a CURP\n * @returns Date object or null if invalid\n */\nexport function getCURPBirthDate(curp: string): Date | null {\n const cleaned = cleanDocument(curp).toUpperCase();\n if (cleaned.length < 10) return null;\n\n const yearPart = cleaned.slice(4, 6);\n const month = cleaned.slice(6, 8);\n const day = cleaned.slice(8, 10);\n\n // Determine century based on position 17 (digit for century)\n // 0-9 for people born 1900-1999, A for 2000+\n const centuryChar = cleaned[16];\n let year: number;\n\n if (/\\d/.test(centuryChar)) {\n year = 1900 + parseInt(yearPart, 10);\n } else {\n year = 2000 + parseInt(yearPart, 10);\n }\n\n const date = new Date(year, parseInt(month, 10) - 1, parseInt(day, 10));\n\n // Validate the date is real\n if (\n date.getFullYear() !== year ||\n date.getMonth() !== parseInt(month, 10) - 1 ||\n date.getDate() !== parseInt(day, 10)\n ) {\n return null;\n }\n\n return date;\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a Mexican RFC (Registro Federal de Contribuyentes)
|
|
3
|
+
* @param rfc - The RFC to validate
|
|
4
|
+
*/
|
|
5
|
+
declare function validateRFC(rfc: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Format an RFC for display (uppercase, no separators)
|
|
8
|
+
*/
|
|
9
|
+
declare function formatRFC(rfc: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Clean an RFC
|
|
12
|
+
*/
|
|
13
|
+
declare function cleanRFC(rfc: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Validate a Mexican CURP (Clave Única de Registro de Población)
|
|
16
|
+
* @param curp - The CURP to validate (18 characters)
|
|
17
|
+
*/
|
|
18
|
+
declare function validateCURP(curp: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Format a CURP for display
|
|
21
|
+
*/
|
|
22
|
+
declare function formatCURP(curp: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Clean a CURP
|
|
25
|
+
*/
|
|
26
|
+
declare function cleanCURP(curp: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Get the gender from a CURP
|
|
29
|
+
* @returns 'M' for male, 'F' for female, or null if invalid
|
|
30
|
+
*/
|
|
31
|
+
declare function getCURPGender(curp: string): 'M' | 'F' | null;
|
|
32
|
+
/**
|
|
33
|
+
* Get the birth date from a CURP
|
|
34
|
+
* @returns Date object or null if invalid
|
|
35
|
+
*/
|
|
36
|
+
declare function getCURPBirthDate(curp: string): Date | null;
|
|
37
|
+
|
|
38
|
+
export { cleanCURP, cleanRFC, formatCURP, formatRFC, getCURPBirthDate, getCURPGender, validateCURP, validateRFC };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a Mexican RFC (Registro Federal de Contribuyentes)
|
|
3
|
+
* @param rfc - The RFC to validate
|
|
4
|
+
*/
|
|
5
|
+
declare function validateRFC(rfc: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Format an RFC for display (uppercase, no separators)
|
|
8
|
+
*/
|
|
9
|
+
declare function formatRFC(rfc: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Clean an RFC
|
|
12
|
+
*/
|
|
13
|
+
declare function cleanRFC(rfc: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Validate a Mexican CURP (Clave Única de Registro de Población)
|
|
16
|
+
* @param curp - The CURP to validate (18 characters)
|
|
17
|
+
*/
|
|
18
|
+
declare function validateCURP(curp: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Format a CURP for display
|
|
21
|
+
*/
|
|
22
|
+
declare function formatCURP(curp: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Clean a CURP
|
|
25
|
+
*/
|
|
26
|
+
declare function cleanCURP(curp: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Get the gender from a CURP
|
|
29
|
+
* @returns 'M' for male, 'F' for female, or null if invalid
|
|
30
|
+
*/
|
|
31
|
+
declare function getCURPGender(curp: string): 'M' | 'F' | null;
|
|
32
|
+
/**
|
|
33
|
+
* Get the birth date from a CURP
|
|
34
|
+
* @returns Date object or null if invalid
|
|
35
|
+
*/
|
|
36
|
+
declare function getCURPBirthDate(curp: string): Date | null;
|
|
37
|
+
|
|
38
|
+
export { cleanCURP, cleanRFC, formatCURP, formatRFC, getCURPBirthDate, getCURPGender, validateCURP, validateRFC };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function n(t){return t.replace(/[^a-zA-Z0-9]/g,"")}var u=/^[A-ZÑ&]{4}\d{6}[A-Z0-9]{3}$/,c=/^[A-ZÑ&]{3}\d{6}[A-Z0-9]{3}$/,p=/^[A-Z]{4}\d{6}[HM][A-Z]{5}[A-Z0-9]\d$/;function d(t){let e=n(t).toUpperCase();return e.length!==12&&e.length!==13?false:e.length===13?u.test(e):c.test(e)}function m(t){return n(t).toUpperCase()}function h(t){return n(t).toUpperCase()}function R(t){let e=n(t).toUpperCase();return e.length!==18||!p.test(e)?false:g(e)}function g(t){let e="0123456789ABCDEFGHIJKLMN\xD1OPQRSTUVWXYZ",r=0;for(let o=0;o<17;o++){let l=t[o],s=e.indexOf(l);if(s===-1)return false;r+=s*(18-o);}return (10-r%10)%10===parseInt(t[17],10)}function U(t){return n(t).toUpperCase()}function x(t){return n(t).toUpperCase()}function A(t){let e=n(t).toUpperCase();if(e.length<11)return null;let r=e[10];return r==="H"?"M":r==="M"?"F":null}function D(t){let e=n(t).toUpperCase();if(e.length<10)return null;let r=e.slice(4,6),i=e.slice(6,8),o=e.slice(8,10),l=e[16],s;/\d/.test(l)?s=1900+parseInt(r,10):s=2e3+parseInt(r,10);let a=new Date(s,parseInt(i,10)-1,parseInt(o,10));return a.getFullYear()!==s||a.getMonth()!==parseInt(i,10)-1||a.getDate()!==parseInt(o,10)?null:a}export{x as cleanCURP,h as cleanRFC,U as formatCURP,m as formatRFC,D as getCURPBirthDate,A as getCURPGender,R as validateCURP,d as validateRFC};//# sourceMappingURL=mx.js.map
|
|
2
|
+
//# sourceMappingURL=mx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils.ts","../../src/locales/mx.ts"],"names":["cleanDocument","value","RFC_PATTERN_FISICA","RFC_PATTERN_MORAL","CURP_PATTERN","validateRFC","rfc","cleaned","formatRFC","cleanRFC","validateCURP","curp","validateCURPCheckDigit","dictionary","sum","i","char","formatCURP","cleanCURP","getCURPGender","genderChar","getCURPBirthDate","yearPart","month","day","centuryChar","year","date"],"mappings":"AAGO,SAASA,CAAAA,CAAcC,CAAAA,CAAuB,CACnD,OAAOA,EAAM,OAAA,CAAQ,eAAA,CAAiB,EAAE,CAC1C,CCEA,IAAMC,CAAAA,CAAqB,8BAAA,CACrBC,EAAoB,8BAAA,CAMpBC,CAAAA,CAAe,uCAAA,CAMd,SAASC,CAAAA,CAAYC,CAAAA,CAAsB,CAChD,IAAMC,EAAUP,CAAAA,CAAcM,CAAG,CAAA,CAAE,WAAA,EAAY,CAE/C,OAAIC,CAAAA,CAAQ,MAAA,GAAW,IAAMA,CAAAA,CAAQ,MAAA,GAAW,EAAA,CACvC,KAAA,CAILA,CAAAA,CAAQ,MAAA,GAAW,EAAA,CACdL,CAAAA,CAAmB,KAAKK,CAAO,CAAA,CAGjCJ,CAAAA,CAAkB,IAAA,CAAKI,CAAO,CACvC,CAKO,SAASC,EAAUF,CAAAA,CAAqB,CAC7C,OAAON,CAAAA,CAAcM,CAAG,CAAA,CAAE,WAAA,EAC5B,CAKO,SAASG,CAAAA,CAASH,CAAAA,CAAqB,CAC5C,OAAON,CAAAA,CAAcM,CAAG,CAAA,CAAE,WAAA,EAC5B,CAMO,SAASI,CAAAA,CAAaC,CAAAA,CAAuB,CAClD,IAAMJ,CAAAA,CAAUP,CAAAA,CAAcW,CAAI,CAAA,CAAE,WAAA,EAAY,CAMhD,OAJIJ,CAAAA,CAAQ,MA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Y,CAChD,GAAIJ,CAAAA,CAAQ,OAAS,EAAA,CAAI,OAAO,IAAA,CAEhC,IAAMe,EAAWf,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,CAAC,CAAA,CAC7BgB,CAAAA,CAAQhB,CAAAA,CAAQ,KAAA,CAAM,EAAG,CAAC,CAAA,CAC1BiB,CAAAA,CAAMjB,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,EAAE,CAAA,CAIzBkB,EAAclB,CAAAA,CAAQ,EAAE,CAAA,CAC1BmB,CAAAA,CAEA,IAAA,CAAK,IAAA,CAAKD,CAAW,CAAA,CACvBC,EAAO,IAAA,CAAO,QAAA,CAASJ,CAAAA,CAAU,EAAE,EAEnCI,CAAAA,CAAO,GAAA,CAAO,QAAA,CAASJ,CAAAA,CAAU,EAAE,CAAA,CAGrC,IAAMK,CAAAA,CAAO,IAAI,IAAA,CAAKD,CAAAA,CAAM,QAAA,CAASH,CAAAA,CAAO,EAAE,CAAA,CAAI,CAAA,CAAG,QAAA,CAASC,CAAAA,CAAK,EAAE,CAAC,CAAA,CAGtE,OACEG,EAAK,WAAA,EAAY,GAAMD,CAAAA,EACvBC,CAAAA,CAAK,QAAA,EAAS,GAAM,QAAA,CAASJ,CAAAA,CAAO,EAAE,CAAA,CAAI,CAAA,EAC1CI,CAAAA,CAAK,OAAA,KAAc,QAAA,CAASH,CAAAA,CAAK,EAAE,CAAA,CAE5B,KAGFG,CACT","file":"mx.js","sourcesContent":["/**\n * Remove all non-alphanumeric characters\n */\nexport function cleanDocument(value: string): string {\n return value.replace(/[^a-zA-Z0-9]/g, '');\n}\n\n/**\n * Remove all non-digit characters\n */\nexport function cleanDigits(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Pad a string with leading zeros\n */\nexport function padStart(value: string, length: number): string {\n return value.padStart(length, '0');\n}\n\n/**\n * Calculate modulo 11 check digit (common algorithm)\n */\nexport function mod11(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n sum += parseInt(digits[i], 10) * weights[i % weights.length];\n }\n const remainder = sum % 11;\n return remainder;\n}\n\n/**\n * Calculate modulo 10 check digit (Luhn-like algorithms)\n */\nexport function mod10(digits: string, weights: number[]): number {\n let sum = 0;\n for (let i = 0; i < digits.length; i++) {\n let product = parseInt(digits[i], 10) * weights[i % weights.length];\n if (product > 9) {\n product = Math.floor(product / 10) + (product % 10);\n }\n sum += product;\n }\n return sum % 10;\n}\n","import { cleanDocument } from '../core/utils.js';\n\n/**\n * Valid RFC patterns\n * - Persona física: 4 letters + 6 digits + 3 alphanumeric (homoclave)\n * - Persona moral: 3 letters + 6 digits + 3 alphanumeric (homoclave)\n */\nconst RFC_PATTERN_FISICA = /^[A-ZÑ&]{4}\\d{6}[A-Z0-9]{3}$/;\nconst RFC_PATTERN_MORAL = /^[A-ZÑ&]{3}\\d{6}[A-Z0-9]{3}$/;\n\n/**\n * CURP pattern\n * 18 characters: 4 letters + 6 digits + 6 letters + 2 alphanumeric\n */\nconst CURP_PATTERN = /^[A-Z]{4}\\d{6}[HM][A-Z]{5}[A-Z0-9]\\d$/;\n\n/**\n * Validate a Mexican RFC (Registro Federal de Contribuyentes)\n * @param rfc - The RFC to validate\n */\nexport function validateRFC(rfc: string): boolean {\n const cleaned = cleanDocument(rfc).toUpperCase();\n\n if (cleaned.length !== 12 && cleaned.length !== 13) {\n return false;\n }\n\n // 12 chars = Persona moral, 13 chars = Persona física\n if (cleaned.length === 13) {\n return RFC_PATTERN_FISICA.test(cleaned);\n }\n\n return RFC_PATTERN_MORAL.test(cleaned);\n}\n\n/**\n * Format an RFC for display (uppercase, no separators)\n */\nexport function formatRFC(rfc: string): string {\n return cleanDocument(rfc).toUpperCase();\n}\n\n/**\n * Clean an RFC\n */\nexport function cleanRFC(rfc: string): string {\n return cleanDocument(rfc).toUpperCase();\n}\n\n/**\n * Validate a Mexican CURP (Clave Única de Registro de Población)\n * @param curp - The CURP to validate (18 characters)\n */\nexport function validateCURP(curp: string): boolean {\n const cleaned = cleanDocument(curp).toUpperCase();\n\n if (cleaned.length !== 18) {\n return false;\n }\n\n if (!CURP_PATTERN.test(cleaned)) {\n return false;\n }\n\n // Validate check digit\n return validateCURPCheckDigit(cleaned);\n}\n\n/**\n * CURP check digit validation\n */\nfunction validateCURPCheckDigit(curp: string): boolean {\n const dictionary = '0123456789ABCDEFGHIJKLMNÑOPQRSTUVWXYZ';\n let sum = 0;\n\n for (let i = 0; i < 17; i++) {\n const char = curp[i];\n const value = dictionary.indexOf(char);\n if (value === -1) return false;\n sum += value * (18 - i);\n }\n\n const checkDigit = (10 - (sum % 10)) % 10;\n return checkDigit === parseInt(curp[17], 10);\n}\n\n/**\n * Format a CURP for display\n */\nexport function formatCURP(curp: string): string {\n return cleanDocument(curp).toUpperCase();\n}\n\n/**\n * Clean a CURP\n */\nexport function cleanCURP(curp: string): string {\n return cleanDocument(curp).toUpperCase();\n}\n\n/**\n * Get the gender from a CURP\n * @returns 'M' for male, 'F' for female, or null if invalid\n */\nexport function getCURPGender(curp: string): 'M' | 'F' | null {\n const cleaned = cleanDocument(curp).toUpperCase();\n if (cleaned.length < 11) return null;\n\n const genderChar = cleaned[10];\n if (genderChar === 'H') return 'M';\n if (genderChar === 'M') return 'F';\n return null;\n}\n\n/**\n * Get the birth date from a CURP\n * @returns Date object or null if invalid\n */\nexport function getCURPBirthDate(curp: string): Date | null {\n const cleaned = cleanDocument(curp).toUpperCase();\n if (cleaned.length < 10) return null;\n\n const yearPart = cleaned.slice(4, 6);\n const month = cleaned.slice(6, 8);\n const day = cleaned.slice(8, 10);\n\n // Determine century based on position 17 (digit for century)\n // 0-9 for people born 1900-1999, A for 2000+\n const centuryChar = cleaned[16];\n let year: number;\n\n if (/\\d/.test(centuryChar)) {\n year = 1900 + parseInt(yearPart, 10);\n } else {\n year = 2000 + parseInt(yearPart, 10);\n }\n\n const date = new Date(year, parseInt(month, 10) - 1, parseInt(day, 10));\n\n // Validate the date is real\n if (\n date.getFullYear() !== year ||\n date.getMonth() !== parseInt(month, 10) - 1 ||\n date.getDate() !== parseInt(day, 10)\n ) {\n return null;\n }\n\n return date;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "soff-id",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "LATAM document validation library - Validate NIT, RUT, CPF, CUIT, and more",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./core": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/core/index.d.ts",
|
|
24
|
+
"default": "./dist/core/index.js"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/core/index.d.cts",
|
|
28
|
+
"default": "./dist/core/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./locales/co": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/locales/co.d.ts",
|
|
34
|
+
"default": "./dist/locales/co.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/locales/co.d.cts",
|
|
38
|
+
"default": "./dist/locales/co.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./locales/br": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/locales/br.d.ts",
|
|
44
|
+
"default": "./dist/locales/br.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/locales/br.d.cts",
|
|
48
|
+
"default": "./dist/locales/br.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./locales/ar": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/locales/ar.d.ts",
|
|
54
|
+
"default": "./dist/locales/ar.js"
|
|
55
|
+
},
|
|
56
|
+
"require": {
|
|
57
|
+
"types": "./dist/locales/ar.d.cts",
|
|
58
|
+
"default": "./dist/locales/ar.cjs"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"./locales/cl": {
|
|
62
|
+
"import": {
|
|
63
|
+
"types": "./dist/locales/cl.d.ts",
|
|
64
|
+
"default": "./dist/locales/cl.js"
|
|
65
|
+
},
|
|
66
|
+
"require": {
|
|
67
|
+
"types": "./dist/locales/cl.d.cts",
|
|
68
|
+
"default": "./dist/locales/cl.cjs"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"./locales/mx": {
|
|
72
|
+
"import": {
|
|
73
|
+
"types": "./dist/locales/mx.d.ts",
|
|
74
|
+
"default": "./dist/locales/mx.js"
|
|
75
|
+
},
|
|
76
|
+
"require": {
|
|
77
|
+
"types": "./dist/locales/mx.d.cts",
|
|
78
|
+
"default": "./dist/locales/mx.cjs"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"files": [
|
|
83
|
+
"dist"
|
|
84
|
+
],
|
|
85
|
+
"scripts": {
|
|
86
|
+
"build": "tsup",
|
|
87
|
+
"dev": "tsup --watch",
|
|
88
|
+
"test": "vitest run",
|
|
89
|
+
"test:watch": "vitest",
|
|
90
|
+
"test:coverage": "vitest --coverage",
|
|
91
|
+
"type-check": "tsc --noEmit",
|
|
92
|
+
"lint": "eslint .",
|
|
93
|
+
"lint:fix": "eslint . --fix",
|
|
94
|
+
"clean": "rimraf dist coverage .turbo",
|
|
95
|
+
"format": "prettier --write .",
|
|
96
|
+
"prepublishOnly": "npm run build",
|
|
97
|
+
"version": "npm run build",
|
|
98
|
+
"postversion": "git push && git push --tags"
|
|
99
|
+
},
|
|
100
|
+
"lint-staged": {
|
|
101
|
+
"*.{ts,tsx,js,jsx}": [
|
|
102
|
+
"eslint --fix",
|
|
103
|
+
"prettier --write"
|
|
104
|
+
],
|
|
105
|
+
"*.{json,md,yml,yaml}": [
|
|
106
|
+
"prettier --write"
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
"keywords": [
|
|
110
|
+
"validation",
|
|
111
|
+
"documents",
|
|
112
|
+
"nit",
|
|
113
|
+
"rut",
|
|
114
|
+
"cpf",
|
|
115
|
+
"cnpj",
|
|
116
|
+
"cuit",
|
|
117
|
+
"cedula",
|
|
118
|
+
"typescript",
|
|
119
|
+
"tree-shaking",
|
|
120
|
+
"latam",
|
|
121
|
+
"colombia",
|
|
122
|
+
"chile",
|
|
123
|
+
"brazil",
|
|
124
|
+
"argentina",
|
|
125
|
+
"mexico",
|
|
126
|
+
"lightweight"
|
|
127
|
+
],
|
|
128
|
+
"author": "Luis C. Rojas",
|
|
129
|
+
"license": "MIT",
|
|
130
|
+
"repository": {
|
|
131
|
+
"type": "git",
|
|
132
|
+
"url": "git+https://github.com/bledxs/soff-monorepo.git",
|
|
133
|
+
"directory": "packages/soff-id"
|
|
134
|
+
},
|
|
135
|
+
"bugs": {
|
|
136
|
+
"url": "https://github.com/bledxs/soff-monorepo/issues"
|
|
137
|
+
},
|
|
138
|
+
"homepage": "https://github.com/bledxs/soff-monorepo/tree/main/packages/soff-id#readme",
|
|
139
|
+
"engines": {
|
|
140
|
+
"node": ">=20"
|
|
141
|
+
},
|
|
142
|
+
"devDependencies": {
|
|
143
|
+
"@eslint/js": "^9.39.1",
|
|
144
|
+
"@soff/tsconfig": "*",
|
|
145
|
+
"@vitest/coverage-v8": "^4.0.14",
|
|
146
|
+
"eslint": "^9.39.1",
|
|
147
|
+
"eslint-config-prettier": "^10.1.8",
|
|
148
|
+
"globals": "^16.5.0",
|
|
149
|
+
"prettier": "^3.7.3",
|
|
150
|
+
"rimraf": "^6.0.1",
|
|
151
|
+
"tsup": "^8.5.1",
|
|
152
|
+
"typescript": "^5.9.3",
|
|
153
|
+
"typescript-eslint": "^8.48.0",
|
|
154
|
+
"vitest": "^4.0.14"
|
|
155
|
+
}
|
|
156
|
+
}
|