This repository is my personal implementation of the E-Commerce Project studied at Clean Code & Clean Architecture Course.
The main goal here is to create a simple e-commerce implementation using SOLID principles,Object Oriented Programming, Refactoring Techniques", Clean Architecture, Domain Driven Design, Test Driven Development and some Design Patterns.
- Conventional Commits Pattern
- Enforced with: Git Commit Message Linter
- No test breaking commits
- Helped by: Lint Staged
- Enforced by: Husky
- Eslint
- Airbnb Typescript
- Personal Rules
- Prettier
- Default
- Jest
- Mapped Paths
- Ts-Jest
- Test Patterns
- Mocks
- Spies
- System Under Test (SUT)
- GitHub Actions
- Jobs:
- Test
- Eslint
- Coveralls
- Jobs:
- Refactor challenge:
- Obs: The results are accessible in the refactor/cpf-challenge branch into the SRC folder
- "FirstRefactor.ts" is the first result using functions
- "CpfValidation.ts" is the last result using Typescript with Classes and Interfaces
// @ts-nocheck
export function validate(str) {
if (str !== null) {
if (str !== undefined) {
if (str.length >= 11 || str.length <= 14) {
str = str
.replace('.', '')
.replace('.', '')
.replace('-', '')
.replace(' ', '')
if (!str.split('').every((c) => c === str[0])) {
try {
let d1
let d2
let dg1
let dg2
let rest
let digito
let nDigResult
d1 = d2 = 0
dg1 = dg2 = rest = 0
for (
let nCount = 1;
nCount < str.length - 1;
nCount++
) {
// if (isNaN(parseInt(str.substring(nCount -1, nCount)))) {
// return false;
// } else {
digito = parseInt(str.substring(nCount - 1, nCount))
d1 += (11 - nCount) * digito
d2 += (12 - nCount) * digito
// }
}
rest = d1 % 11
dg1 = rest < 2 ? (dg1 = 0) : 11 - rest
d2 += 2 * dg1
rest = d2 % 11
if (rest < 2) {
dg2 = 0
} else {
dg2 = 11 - rest
}
const nDigVerific = str.substring(
str.length - 2,
str.length
)
nDigResult = `${dg1}${dg2}`
return nDigVerific == nDigResult
} catch (e) {
console.error(`Erro !${e}`)
return false
}
} else return false
} else return false
}
} else return false
}