@euphrasiologist/lwphylo 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1152,6 +1152,27 @@ function subTree (tree, node) {
1152
1152
  return Object.fromEntries(data.concat(filtered));
1153
1153
  }
1154
1154
 
1155
+ /**
1156
+ * Serialize a parsed tree (the parent/children node shape produced by
1157
+ * readTree() and randomTree()) back into a Newick string.
1158
+ */
1159
+
1160
+ function toNewick(node) {
1161
+ return `${serialize(node)};`;
1162
+ }
1163
+
1164
+ function serialize(node) {
1165
+ const label = node.label || '';
1166
+ const branch = node.branchLength == null ? '' : `:${node.branchLength}`;
1167
+
1168
+ if (node.children.length === 0) {
1169
+ return `${label}${branch}`;
1170
+ }
1171
+
1172
+ const children = node.children.map(serialize).join(',');
1173
+ return `(${children})${label}${branch}`;
1174
+ }
1175
+
1155
1176
  function drawPhylogeny(
1156
1177
  treeText,
1157
1178
  {
@@ -1945,5 +1966,6 @@ exports.randomTree = randomTree;
1945
1966
  exports.readTree = readTree;
1946
1967
  exports.rectangleLayout = rectangleLayout;
1947
1968
  exports.subTree = subTree;
1969
+ exports.toNewick = toNewick;
1948
1970
  exports.unrooted = unrooted;
1949
1971
  //# sourceMappingURL=index.cjs.map