@lacussoft/cpf-val
Version:
Utility to validate CPF (Brazilian Individual's Taxpayer ID)
130 lines (87 loc) • 5.42 kB
Markdown
# @lacussoft/cpf-val
## 3.0.0
### 🎉 v3 at a glance 🎊
- **Class-based API** — `CpfValidator` for reusable validation; `isValid(cpfInput)` returns `true`/`false`. The `cpfVal(cpfInput)` helper remains for one-off usage.
- **Flexible input** — Accepts `string` or `readonly string[]` (formatted or raw); non-numeric characters are stripped before validation.
- **Structured errors** — Invalid input type throws `CpfValidatorInputTypeError`; invalid CPF data (wrong length, ineligible base, bad check digits) still returns `false` without throwing.
- **Explicit exports** — Package exports `cpfVal`, `CpfValidator`, `CPF_LENGTH`, exception classes, and types; uses `@lacussoft/cpf-dv` for check-digit verification.
### BREAKING CHANGES
- **Invalid input type now throws**: `cpfVal(cpfInput)` and `CpfValidator#isValid(cpfInput)` throw `CpfValidatorInputTypeError` when `cpfInput` is not a string or array of strings (e.g. `cpfVal(123)`, `cpfVal(null)`). In v2, such calls had unspecified behavior; they now fail fast with a typed error.
- **New exports**: The package now exports `CpfValidator`, `CPF_LENGTH`, `CpfValidatorTypeError`, `CpfValidatorInputTypeError`, `CpfValidatorException`, and `CpfInput`. Code that assumed only a default export or a specific bundle surface may need to be updated.
### New features
- **`CpfValidator` class**: `new CpfValidator()` with `isValid(cpfInput)`; no options (CPF is numeric-only).
- **Array input**: `CpfInput` is `string | readonly string[]`; array of strings is joined and validated like a single string.
- **Exception hierarchy**: `CpfValidatorTypeError` (base), `CpfValidatorInputTypeError` (invalid input type), `CpfValidatorException` (base for future use). Invalid CPF values still return `false`.
### Improvements
- **New PT-BR documentation**: New [README in Brazilian Portuguese](./README.pt.md).
- **Check digits**: Validation delegates to `@lacussoft/cpf-dv`; ineligible base (e.g. repeated digits) or wrong length yields `false` (no throw).
- **Platform support**: README documents Node, Bun, Deno, and browsers with a unified Platform Support table.
## 2.0.2
### Patch Changes
- ddd33b9: Update overall dependencies.
- Updated dependencies [ddd33b9]
- @lacussoft/cpf-gen@2.0.2
## 2.0.1
### Patch Changes
- 2889911: Update documentation.
- 5d9bf1d: Create a contribution guide.
- Updated dependencies [2889911]
- Updated dependencies [5d9bf1d]
- @lacussoft/cpf-gen@2.0.1
## 2.0.0
### Major Changes
- 5cfb84d: Increase version to align with `br-utils`.
### Patch Changes
- Updated dependencies [5cfb84d]
- @lacussoft/cpf-gen@2.0.0
## 1.4.4
### Patch Changes
- e3f479a: Update package description.
- 12cc5b1: Fix types declaration export.
- Updated dependencies [e3f479a]
- Updated dependencies [12cc5b1]
- @lacussoft/cpf-gen@1.5.4
## 1.4.3
### Patch Changes
- 5eb38e3: Adjust repo references from `juliolmuller` to `LacusSolutions`
- Updated dependencies [5eb38e3]
- @lacussoft/cpf-gen@1.5.3
## 1.4.2
### Patch Changes
- 7e21d87: Updated overall development dependencies
- Updated dependencies [7e21d87]
- @lacussoft/cpf-gen@1.5.2
## 1.4.1
### Patch Changes
- 23ca50d: Fixed documentation examples.
- Updated dependencies [23ca50d]
- @lacussoft/cpf-gen@1.5.1
## 1.4.0
### Minor Changes
- 7a9b0af: Configured packages entrypoints with `"exports"` option in `package.json`.
### Patch Changes
- Updated dependencies [7a9b0af]
- @lacussoft/cpf-gen@1.5.0
## 1.3.1
### Minor Changes
- 57aeab441315f39e6763f963d4144a2ad8558be6: Changed output files for built code targeting Node-based projects. Main file is now `index.cjs` instead of `index.cjs.js`. It should not break any code importing the lib by its name only.
### Patch Changes
- 4266e00609df3c003dfc4c306976856db9eac219: Added `build` script to monorepo manager.
- 6cc51d7f4750fa45f3c89f818ba7550683c2d52a: Fixed docs broken badges.
- 1a5b10306bb112965541d5a937631dc8eea0ce0a: Dropped Travis CI configuration file (`.travis.yml`).
- 4ed63f32f79d42ea25cb8881c8b0f9d4694f5438: Update monorepo scripts to use Bun's `--filter` flag to run batch routines.
- 32302142eb9f228b3c7a788321d56b83e3aa9cf1: Now the monorepo project will have the same `README` of `cpf-utils` package. Changes made in one end should also be reflected at the other automatically due to routines run by `lint-staged`.
- 8247d389e2e6003712fc52cbc4c4a8f78c4244db: Disabled TypeScript lib check for all packages.
- 167424f136c6935fe9f9f1cf9e628ec83333d244: Added tests for built files.
- 4b94608f9586acff343838df1d251452a2f84a9f: Added `type-check` script to all projects and to monorepo.
- 040852c22206b47b72444a66304bbeea4e47df3c..0914b7c70f3852ddcfe88d81c359c1b73e3e41c9: Created GitHub Actions workflow to run linting, type checking and tests in any pushed branch and PR's.
- bf00d1a0858ede64449f8d7202f9ef2969bb690e: Configured [Changesets](https://github.com/changesets/changesets) in the project.
- 8c763276b616df00a6732adc896d5497b52cef15: Set `"publishConfig"` in `package.json` for all packages.
- 583327c71f84bdd8d496bfb1f287fbf7802d729b..84cec9dee81d0af2f52b3153fa410306e2fd13c6: Created GitHub Actions workflow to create changelogs, increase versions and publish to NPM registry.
- 7ba1718: Create file to set codebase owner.
- Updated dependencies:
- @lacussoft/cpf-gen@1.4.1
- eslint@9.24.0
- eslint-config-any@1.0.6
- lint-staged@15.5.1
- typescript@5.8.3