Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract credit card validation logic into a separate module #121

Open
chrisfalaska opened this issue Oct 30, 2024 · 1 comment
Open

Extract credit card validation logic into a separate module #121

chrisfalaska opened this issue Oct 30, 2024 · 1 comment

Comments

@chrisfalaska
Copy link
Contributor

chrisfalaska commented Oct 30, 2024

Consider extracting credit card validation logic into a separate module.

The credit card validation logic can be extracted to reduce complexity while maintaining functionality. For example:

// CreditCardValidator.js
export class CreditCardValidator {
  validate(value) {
    const card = this.matchCard(value);
    return {
      maxLength: card.formatLength,
      minLength: card.formatMinLength,
      icon: card.cardIcon,
      isValid: this.validateCard(value, card)
    };
  }

  matchCard(value) {
    // Credit card matching logic moved here
  }
}

// BaseInput.js
import { CreditCardValidator } from './CreditCardValidator';

export default class BaseInput extends LitElement {
  constructor() {
    super();
    this.creditCardValidator = new CreditCardValidator();
  }

  processCreditCard() {
    const result = this.creditCardValidator.validate(this.value);
    this.maxLength = result.maxLength;
    this.minLength = result.minLength;
    this.inputIconName = result.icon;
  }
}

This separates concerns while keeping all functionality intact. The credit card validation is encapsulated in its own module with a clear interface.

Originally posted by @sourcery-ai[bot] in #16 (comment)

@chrisfalaska
Copy link
Contributor Author

@jordanjones243 jordanjones243 self-assigned this Dec 16, 2024
@jordanjones243 jordanjones243 transferred this issue from AlaskaAirlines/auro-input Dec 16, 2024
@jordanjones243 jordanjones243 transferred this issue from AlaskaAirlines/auro-input Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants