This package provides TypeScript type definitions for handling Brazilian Zip Code in Domain-Driven Design contexts
npm install @type-ddd/zip-code@type-ddd/zip-code> The @type-ddd/cpf library provides TypeScript type definitions for handling ZipCode in Domain-Driven Design contexts. It facilitates the validation and manipulation of ZipCode numbers, ensuring they adhere to the Brazilian legal standards.
---
Install rich-domain and @type-ddd/zip-code with your favorite package manager
``sh
npm i rich-domain @type-ddd/zip-code
yarn add rich-domain @type-ddd/zip-code
`
Don't worry about removing special characters; they are automatically stripped from all instances.
`ts
import { ZipCode } from '@type-ddd/zip-code'
// Instance of zipCode or throws an error if provide an invalid value
const zipCode = ZipCode.init('75520140');
// OR
// Result of zipCode (Check Result pattern docs)
const result = ZipCode.create('75520140');
result.isOk(); // true
// zipCode instance or null if provide an invalid value
const zipCode = result.value();
`
Don't worry about removing special characters; they are automatically stripped from all instances.
`ts
const result = ZipCode.isValid('75520140');
// Output: true
`
If you need the value with the mask, you can use the toPattern method:
`ts
zipCode.toPattern();
// Output: 75520-140
`
Or if you need to apply mask from a string value you may use addMask method
`ts
ZipCode.addMask('75520140');
// Output: 75520-140
``