mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-27 23:06:54 +05:00
feat(guardian): add guardian package - code quality analyzer
Add @puaros/guardian package v0.1.0 - code quality guardian for vibe coders and enterprise teams. Features: - Hardcode detection (magic numbers, magic strings) - Circular dependency detection - Naming convention enforcement (Clean Architecture) - Architecture violation detection - CLI tool with comprehensive reporting - 159 tests with 80%+ coverage - Smart suggestions for fixes - Built for AI-assisted development Built with Clean Architecture and DDD principles. Works with Claude, GPT, Copilot, Cursor, and any AI coding assistant.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { ValueObject } from "../../../../src/domain/value-objects/ValueObject"
|
||||
|
||||
interface EmailProps {
|
||||
readonly value: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Email Value Object
|
||||
*
|
||||
* DDD Pattern: Value Object
|
||||
* - Immutable
|
||||
* - Self-validating
|
||||
* - No identity
|
||||
* - Equality by value
|
||||
*
|
||||
* Clean Code:
|
||||
* - Single Responsibility: represents email
|
||||
* - Meaningful name: clearly email
|
||||
* - No magic values: validation rules as constants
|
||||
*/
|
||||
export class Email extends ValueObject<EmailProps> {
|
||||
private static readonly EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||
private static readonly MAX_LENGTH = 255
|
||||
|
||||
private constructor(props: EmailProps) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
public static create(email: string): Email {
|
||||
const trimmed = email.trim().toLowerCase()
|
||||
|
||||
if (!trimmed) {
|
||||
throw new Error("Email cannot be empty")
|
||||
}
|
||||
|
||||
if (trimmed.length > Email.MAX_LENGTH) {
|
||||
throw new Error(`Email must be less than ${Email.MAX_LENGTH} characters`)
|
||||
}
|
||||
|
||||
if (!Email.EMAIL_REGEX.test(trimmed)) {
|
||||
throw new Error(`Invalid email format: ${email}`)
|
||||
}
|
||||
|
||||
return new Email({ value: trimmed })
|
||||
}
|
||||
|
||||
public get value(): string {
|
||||
return this.props.value
|
||||
}
|
||||
|
||||
public getDomain(): string {
|
||||
return this.props.value.split("@")[1]
|
||||
}
|
||||
|
||||
public isFromDomain(domain: string): boolean {
|
||||
return this.getDomain() === domain.toLowerCase()
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return this.props.value
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user