Readme

Count Tana Nodes

This is an express endpoint used in a Tana.inc commands to count children of a node sent in the request. I've also created a Tana template that includes the two commands.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { countFirstChildren } from "https://esm.town/v/nbbaier/countFirstChildren";
import { countAllChildren } from "https://esm.town/v/nbbaier/countAllChildren";
import { filterFields } from "https://esm.town/v/nbbaier/filterFields";
export const countTanaNodes = (req: express.Request, res: express.Response) => {
const { type, node } = req.body;
const lines = filterFields(node);
console.log(lines, lines.length);
const root = lines[0].substring(2);
let count: number;
switch (type) {
case "all":
count = countAllChildren(lines);
res.send(String(count));
break;
case "first":
count = countFirstChildren(lines);
res.send(String(count));
break;
}
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023