CastingManager API Reference
Constructor
javascript
const castingManager = new CastingManager();Creates a new casting manager with built-in casters.
Methods
register(type, castFn, serializeFn?)
Registers a new caster function for the specified type.
type(string): The name of the typecastFn(function): Function that converts values to the specified typeserializeFn(function, optional): Function that serializes values of this type
registerModel(type, ModelClass, CollectionClass?)
Registers a model class for casting and (optionally) a collection class. More on this in the BaseModel and BaseCollection documentation.
type(string): The type nameModelClass(class): The model class (typically extends BaseModel)CollectionClass(class, optional): Collection class for arrays of this model
cast(value, typeSpec)
Casts a value to the specified type.
value(any): The value to casttypeSpec(string): Type specification (e.g., 'number', 'decimal:2', 'array:string')
serialize(value, typeSpec)
Serializes a complex value back to a simpler representation.
value(any): The value to serializetypeSpec(string): Type specification
