astro-ghostcms/.pnpm-store/v3/files/3c/ebb91e11f1a0d2d0683562f8bbc...

29 lines
756 B
Plaintext
Raw Permalink Normal View History

2024-02-14 14:10:47 +00:00
import { List } from '../utils/List.js';
export function createConvertor(walk) {
return {
fromPlainObject(ast) {
walk(ast, {
enter(node) {
if (node.children && node.children instanceof List === false) {
node.children = new List().fromArray(node.children);
}
}
});
return ast;
},
toPlainObject(ast) {
walk(ast, {
leave(node) {
if (node.children && node.children instanceof List) {
node.children = node.children.toArray();
}
}
});
return ast;
}
};
};