@elsikora/commitizen-plugin-commitlint-ai
Version:
AI-powered Commitizen adapter with Commitlint integration
50 lines (47 loc) • 1.4 kB
JavaScript
import { MIN_API_KEY_LENGTH, REDACTED_LENGTH } from '../constant/numeric.constant.js';
/**
* Value object representing an API key
*/
class ApiKey {
VALUE;
constructor(value) {
if (!value || value.trim().length === 0) {
throw new Error("API key cannot be empty");
}
this.VALUE = value.trim();
}
/**
* Check if two API keys are equal
* @param {ApiKey} other - The other API key to compare with
* @returns {boolean} True if the API keys are equal
*/
equals(other) {
return this.VALUE === other.VALUE;
}
/**
* Get the API key value
* @returns {string} The API key value
*/
getValue() {
return this.VALUE;
}
/**
* Check if the API key is valid
* @returns {boolean} True if the API key appears to be valid
*/
isValid() {
// Basic validation - just check it's not a placeholder
return this.VALUE.length > MIN_API_KEY_LENGTH && !this.VALUE.includes("your-api-key");
}
/**
* Get a redacted version of the API key for display
* @returns {string} Redacted API key
*/
toRedacted() {
if (this.VALUE.length <= REDACTED_LENGTH)
return "****";
return this.VALUE.slice(0, REDACTED_LENGTH) + "..." + this.VALUE.slice(-4);
}
}
export { ApiKey };
//# sourceMappingURL=api-key.value-object.js.map