simc-ast-builder
Version:
Parser and AST generator for SimulationCraft files
106 lines • 2.99 kB
JavaScript
"use strict";
/**
* Field utilities for the simc-ast-builder
* Provides a type-safe, immutable Field class for representing field definitions
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Field = void 0;
/**
* Immutable Field class for representing field definitions
*/
class Field {
/**
* Create a new Field
* @param name Name of the field
* @param options Options for the field
*/
constructor(name, options = {}) {
this.name = name;
this.displayName = options.displayName || name;
this.negatedName = options.negatedName || name;
this.type = options.type || "neutral";
}
/**
* Check if the field is a boolean field
* @returns True if the field is a boolean field
*/
isBoolean() {
return this.type === "boolean";
}
/**
* Check if the field is a neutral field
* @returns True if the field is a neutral field
*/
isNeutral() {
return this.type === "neutral";
}
/**
* Check if the field is a numeric field
* @returns True if the field is a numeric field
*/
isNumeric() {
return this.type === "numeric";
}
/**
* Convert the Field to a JSON object
* @returns A JSON representation of the Field
*/
toJSON() {
return {
displayName: this.displayName,
name: this.name,
negatedName: this.negatedName,
type: this.type,
};
}
/**
* Create a new Field with a different display name
* @param displayName New display name for the field
* @returns A new Field with the updated display name
*/
withDisplayName(displayName) {
return new Field(this.name, {
displayName,
negatedName: this.negatedName,
type: this.type,
});
}
/**
* Create a new Field with a different name
* @param name New name for the field
* @returns A new Field with the updated name
*/
withName(name) {
return new Field(name, {
displayName: this.displayName,
negatedName: this.negatedName,
type: this.type,
});
}
/**
* Create a new Field with a different negated name
* @param negatedName New negated name for the field
* @returns A new Field with the updated negated name
*/
withNegatedName(negatedName) {
return new Field(this.name, {
displayName: this.displayName,
negatedName,
type: this.type,
});
}
/**
* Create a new Field with a different type
* @param type New type for the field
* @returns A new Field with the updated type
*/
withType(type) {
return new Field(this.name, {
displayName: this.displayName,
negatedName: this.negatedName,
type,
});
}
}
exports.Field = Field;
//# sourceMappingURL=Field.js.map