read-gedcom
Version:
Gedcom file reader
20 lines • 797 B
JavaScript
// TODO lightweight traversal methods
/**
* Create a Gedcom-like string representation of this Gedcom node.
* @param node The Gedcom node
*/
export const nodeToString = (node) => {
const lines = [];
const initialIndent = '';
const indent = ' ';
const lineSeparator = '\n';
const traverse = (node, totalIndent) => {
const fields = [node.tag, node.pointer, node.value ? node.value.replace(/\n/g, '\\n').replace(/\r/g, '\\r') : node.value];
const line = totalIndent + fields.filter(s => s).join(' ');
lines.push(line);
node.children.map(child => traverse(child, node.indexSource !== -1 ? totalIndent + indent : initialIndent));
};
traverse(node, initialIndent);
return lines.join(lineSeparator);
};
//# sourceMappingURL=utils.js.map