read-gedcom
Version:
Gedcom file reader
24 lines • 935 B
JavaScript
;
// TODO lightweight traversal methods
Object.defineProperty(exports, "__esModule", { value: true });
exports.nodeToString = void 0;
/**
* Create a Gedcom-like string representation of this Gedcom node.
* @param node The Gedcom node
*/
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);
};
exports.nodeToString = nodeToString;
//# sourceMappingURL=utils.js.map