SerializerFactory
@blobs/sdk / serializers / SerializerFactory
Defined in: serializers/SerializerFactory.ts:30
Caching factory for IContentSerializer instances.
Implements a flyweight pattern: serializers are cached by
(format, config) so the same combination always reuses the same
instance. Custom serializers can be registered via
SerializerFactory.register to override built-ins for a format.
Example
const md = serializerFactory.getSerializer('markdown');const { html, styles } = md.toHTML('# Hello');Implements
Constructors
Constructor
new SerializerFactory(
defaultConfig?):SerializerFactory
Defined in: serializers/SerializerFactory.ts:43
Parameters
defaultConfig?
Optional defaults applied to every new serializer.
Returns
SerializerFactory
Methods
getSerializer()
getSerializer(
format,config?):IContentSerializer
Defined in: serializers/SerializerFactory.ts:55
Returns a serializer for the given format, creating and caching one on first request.
Parameters
format
The ContentFormat to serialize.
config?
Optional config merged over the factory defaults.
Returns
A cached IContentSerializer instance.
Implementation of
ISerializerFactory.getSerializer
clearCache()
clearCache():
void
Defined in: serializers/SerializerFactory.ts:76
Empties the serializer cache. Useful in tests or after registering a custom serializer for a format that was already cached.
Returns
void
Implementation of
register()
register(
format,SerializerClass):void
Defined in: serializers/SerializerFactory.ts:88
Registers a custom serializer class for a format. Any cached serializers for that format are dropped so subsequent requests receive the new implementation.
Parameters
format
The ContentFormat to register against.
SerializerClass
(config?) => IContentSerializer
A constructor matching the serializer interface.
Returns
void
Implementation of
setDefaultConfig()
setDefaultConfig(
config):void
Defined in: serializers/SerializerFactory.ts:104
Merges new defaults into the factory; only affects serializers created after the change.
Parameters
config
Partial defaults to apply.
Returns
void