simc-ast-builder
Version:
Parser and AST generator for SimulationCraft files
82 lines • 2.76 kB
JavaScript
;
/**
* Factory for creating Field instances
* Provides helper methods for creating fields with appropriate defaults
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldFactory = void 0;
const Field_1 = require("./Field");
/**
* Factory for creating Field instances
*/
class FieldFactory {
/**
* Create a boolean field
* @param name Name of the field
* @param options Additional options for the field
* @returns A new boolean Field
*/
static boolean(name, options = {}) {
return new Field_1.Field(name, Object.assign(Object.assign({}, options), { type: "boolean" }));
}
/**
* Create a field from an existing field definition
* @param def Existing field definition
* @returns A new Field based on the definition
*/
static fromDefinition(def) {
return new Field_1.Field(def.name, {
displayName: def.displayName,
negatedName: def.negatedName,
type: def.type,
});
}
/**
* Create a field from a partial field definition
* @param partialDef Partial field definition
* @returns A new Field based on the partial definition
*/
static fromPartial(partialDef) {
const options = {};
if (partialDef.displayName) {
options.displayName = partialDef.displayName;
}
if (partialDef.negatedName) {
options.negatedName = partialDef.negatedName;
}
if (partialDef.type) {
options.type = partialDef.type;
}
return new Field_1.Field(partialDef.name, options);
}
/**
* Create a neutral field
* @param name Name of the field
* @param options Additional options for the field
* @returns A new neutral Field
*/
static neutral(name, options = {}) {
return new Field_1.Field(name, Object.assign(Object.assign({}, options), { type: "neutral" }));
}
/**
* Create a numeric field
* @param name Name of the field
* @param options Additional options for the field
* @returns A new numeric Field
*/
static numeric(name, options = {}) {
return new Field_1.Field(name, Object.assign(Object.assign({}, options), { type: "numeric" }));
}
/**
* Create a field with a specific type
* @param name Name of the field
* @param type Type of the field
* @param options Additional options for the field
* @returns A new Field with the specified type
*/
static withType(name, type, options = {}) {
return new Field_1.Field(name, Object.assign(Object.assign({}, options), { type }));
}
}
exports.FieldFactory = FieldFactory;
//# sourceMappingURL=FieldFactory.js.map