diff --git a/README.md b/README.md index 748d8e3..ff52b5d 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The following set of extra asserts are provided by this package: | [CaZipCode](#cazipcode) | | | [CpfNumber](#cpfnumber) | [`cpf`][cpf-url] | | [CreditCard](#creditcard) | [`creditcard`][creditcard-url] | -| [CurpNumber](#curpnumber) | [`curp`][curp-url] | +| [CurpNumber](#curpnumber) | [`@randyd45/curp-validation`][curp-url] | | [Date](#date) | [`moment`][moment-url] | | [DateDiffGreaterThan](#datediffgreaterthan) | [`moment`][moment-url] | | [DateDiffGreaterThanOrEqualTo](#datediffgreaterthanorequalto) | [`moment`][moment-url] | @@ -402,7 +402,7 @@ MIT [callback-url]: https://www.npmjs.com/package/callback [cpf-url]: https://www.npmjs.com/package/cpf [creditcard-url]: https://www.npmjs.com/package/creditcard -[curp-url]: https://www.npmjs.com/package/curp +[curp-url]: https://www.npmjs.com/package/@randyd45/curp-validation [google-libphonenumber-url]: https://www.npmjs.com/package/google-libphonenumber [iban-url]: https://www.npmjs.com/package/iban [isoc-url]: https://www.npmjs.com/package/isoc diff --git a/package.json b/package.json index 646f691..3c062b1 100644 --- a/package.json +++ b/package.json @@ -51,12 +51,12 @@ }, "devDependencies": { "@fastify/pre-commit": "^2.2.0", + "@randyd45/curp-validation": "1.0.4", "@uphold/github-changelog-generator": "^4.0.2", "abavalidator": "^2.0.2", "bignumber.js": "^9.3.0", "cpf": "^2.0.1", "creditcard": "^0.1.3", - "curp": "^1.3.1", "eslint": "~9.28.0", "eslint-config-uphold": "^6.5.2", "google-libphonenumber": "^3.2.41", @@ -73,11 +73,11 @@ "validator.js": "^2.0.0" }, "peerDependencies": { + "@randyd45/curp-validation": "1.0.4", "abavalidator": "^2.0.0", "bignumber.js": ">=7 || <=9.3.0", "cpf": "^2.0.1", "creditcard": ">=0.0.1 <1.0.0", - "curp": "^1.2.3", "google-libphonenumber": ">=1 <4", "iban": ">=0.0.6 <1.0.0", "isoc": ">=0.0.1 <1.0.0", @@ -90,6 +90,9 @@ "validator.js": "^2.0.0" }, "peerDependenciesMeta": { + "@randyd45/curp-validation": { + "optional": true + }, "abavalidator": { "optional": true }, @@ -102,9 +105,6 @@ "creditcard": { "optional": true }, - "curp": { - "optional": true - }, "google-libphonenumber": { "optional": true }, @@ -137,11 +137,11 @@ "node": ">=20" }, "optionalPeerDependencies": { + "@randyd45/curp-validation": "1.0.4", "abavalidator": ">=2 <3", "bignumber.js": ">=7 <=9.3.0", "cpf": "^2.0.1", "creditcard": ">=0.0.1 <1.0.0", - "curp": "^1.2.3", "google-libphonenumber": ">=1 <4", "iban": ">=0.0.6 <1.0.0", "isoc": ">=0.0.1 <1.0.0", diff --git a/src/asserts/curp-number-assert.js b/src/asserts/curp-number-assert.js index cd6c8cb..e335b6a 100644 --- a/src/asserts/curp-number-assert.js +++ b/src/asserts/curp-number-assert.js @@ -6,14 +6,14 @@ const { Validator, Violation } = require('validator.js'); const _ = require('lodash'); -let curp; +let CURP; /** * Optional peer dependencies. */ try { - curp = require('curp'); + ({ CURP } = require('@randyd45/curp-validation')); // eslint-disable-next-line no-empty } catch {} @@ -22,8 +22,8 @@ try { */ module.exports = function curpNumberAssert() { - if (!curp) { - throw new Error('curp is not installed'); + if (!CURP) { + throw new Error('@randyd45/curp-validation is not installed'); } /** @@ -41,7 +41,7 @@ module.exports = function curpNumberAssert() { throw new Violation(this, value, { value: Validator.errorCode.must_be_a_string }); } - if (!curp.validar(value)) { + if (!new CURP(value).isFormatValid()) { throw new Violation(this, value, { value: 'must_be_a_valid_curp_number' }); } diff --git a/src/types/index.d.ts b/src/types/index.d.ts index e56251d..aacb162 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -74,7 +74,7 @@ export interface ValidatorJSAsserts { /** * Valid Mexican CURP number. - * @requires curp + * @requires @randyd45/curp-validation */ curpNumber(): AssertInstance; diff --git a/yarn.lock b/yarn.lock index 17462b7..3ef6906 100644 --- a/yarn.lock +++ b/yarn.lock @@ -629,6 +629,11 @@ resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.2.7.tgz#eb5014dfd0b03e7f3ba2eeeff506eed89b028058" integrity sha512-YLT9Zo3oNPJoBjBc4q8G2mjU4tqIbf5CEOORbUUr48dCD9q3umJ3IPlVqOqDakPfd2HuwccBaqlGhN4Gmr5OWg== +"@randyd45/curp-validation@1.0.4": + version "1.0.4" + resolved "https://registry.yarnpkg.com/@randyd45/curp-validation/-/curp-validation-1.0.4.tgz#61212285894f772821ef1685fd22514150896839" + integrity sha512-UcmKskORce983tbpoS9bUESBUIYRjBPZ9bWPpY5S2fkXX0ImkVKCzSvWaqIfS6DPphmNtHyF+ifT9srqzs0EvA== + "@stylistic/eslint-plugin@^4.4.0": version "4.4.1" resolved "https://registry.yarnpkg.com/@stylistic/eslint-plugin/-/eslint-plugin-4.4.1.tgz#410ac332887fb3d61cad1df4e6b55ae35d87c632" @@ -1012,11 +1017,6 @@ cross-spawn@^7.0.3, cross-spawn@^7.0.6: shebang-command "^2.0.0" which "^2.0.1" -curp@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/curp/-/curp-1.3.1.tgz#6b944d490f5fcd1b60cf59951235b2c075737f9b" - integrity sha512-DoUGrXK7qe6qnSgumTGa9yULrMJy/1Npsgt0LkGkjWXfL/xVyJPcAQgyEJpNaJQjOlCvdEZWJ2K9vNlTmYrHHw== - data-uri-to-buffer@^6.0.2: version "6.0.2" resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz#8a58bb67384b261a38ef18bea1810cb01badd28b"