namespaceForFile

tcmts.cli.mirror.namespaceForFile · #vhw4hllg · term · runs on the server

uses node:path

core/src/analyze.ts → core.analyze, store/src/index.ts → store

import path from "node:path";

export function namespaceForFile(root: string, file: string): string {
  const segs = path.relative(root, file).replace(/\.(m|c)?tsx?$/, "").split(path.sep).filter((s) => s !== "src");
  if (segs.at(-1) === "index") segs.pop();
  return segs.map((s) => s.replace(/[^\w$]/g, "_").replace(/^(\d)/, "_$1")).join(".");
}

used by