feat: add converter registry
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
let entries = new Map();
|
||||
|
||||
function key(sourceFormat, targetFormat) {
|
||||
return `${sourceFormat}->${targetFormat}`;
|
||||
}
|
||||
|
||||
export function register({ family, sourceFormat, targetFormat, convert }) {
|
||||
entries.set(key(sourceFormat, targetFormat), { family, convert });
|
||||
}
|
||||
|
||||
export function resolve(sourceFormat, targetFormat) {
|
||||
return entries.get(key(sourceFormat, targetFormat)) ?? null;
|
||||
}
|
||||
|
||||
export function listTargetFormats(sourceFormat) {
|
||||
const prefix = `${sourceFormat}->`;
|
||||
return [...entries.keys()]
|
||||
.filter((k) => k.startsWith(prefix))
|
||||
.map((k) => k.slice(prefix.length));
|
||||
}
|
||||
|
||||
export function _resetForTests() {
|
||||
entries = new Map();
|
||||
}
|
||||
Reference in New Issue
Block a user