Skip to content

Latest commit

 

History

History

zip-code

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@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.


Installation

Install rich-domain and @type-ddd/zip-code with your favorite package manager

npm i rich-domain @type-ddd/zip-code

# OR

yarn add rich-domain @type-ddd/zip-code

Usage

Don't worry about removing special characters; they are automatically stripped from all instances.

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();

Check string is valid zipCode

Don't worry about removing special characters; they are automatically stripped from all instances.

const result = ZipCode.isValid('75520140');
// Output: true

Special chars

If you need the value with the mask, you can use the toPattern method:

zipCode.toPattern();

// Output: 75520-140

Or if you need to apply mask from a string value you may use addMask method

ZipCode.addMask('75520140');

// Output: 75520-140