@memory-bank/mcp
Version:
Memory-enabled Co-Pilot (MCP) server for managing project documentation and context
86 lines • 2.21 kB
JavaScript
/**
* Language Domain Model
*
* Represents the concept of a language in the system with validation rules.
* Implements value object pattern - immutable and equality based on value.
*/
/**
* Language class represents a valid language in the system
*/
export class Language {
_code;
/**
* Constructor with validation
*
* @param code Language code to validate and create Language object
* @throws Error if language code is not supported
*/
constructor(code) {
if (!this.isValidLanguageCode(code)) {
throw new Error(`Unsupported language code: ${code}`);
}
this._code = code;
}
/**
* Gets the language code
*/
get code() {
return this._code;
}
/**
* Creates a Language instance, validating the code
*
* @param code Language code to validate
* @returns Language instance
* @throws Error if language code is not supported
*/
static create(code) {
return new Language(code);
}
/**
* Creates a default Language instance (English)
*
* @returns Language instance for English
*/
static default() {
return new Language('en');
}
/**
* Gets list of all supported language codes
*
* @returns Array of supported language codes
*/
static supportedLanguages() {
return ['en', 'ja', 'zh'];
}
/**
* Validates if a language code is supported
*
* @param code Language code to validate
* @returns true if supported, false otherwise
*/
isValidLanguageCode(code) {
return Language.supportedLanguages().includes(code);
}
/**
* Compare equality with another Language object
*
* @param other Another Language object to compare
* @returns true if equal, false otherwise
*/
equals(other) {
if (!other) { // Check if other is null or undefined
return false;
}
return this._code === other.code;
}
/**
* Returns string representation
*
* @returns Language code as string
*/
toString() {
return this._code;
}
}
//# sourceMappingURL=Language.js.map