announcedSpec

tcmts.cli.libraries.announcedSpec · #kanlrik7 · term · runs anywhere

What tcm lib add <source> [what] names as announced: @<handle or DID>/<package>[@<version>], or @<handle or DID> with the release as what. Undefined for any other source.

import { UsageError } from "#codebase/tcmts/cli/ui";

export function announcedSpec(
  source: string,
  what: string | undefined,
): { who: string; what?: string } | undefined {
  if (!source.startsWith("@")) return undefined;
  const slash = source.indexOf("/");
  const rest = slash < 0 ? undefined : source.slice(slash + 1);
  const who = slash < 0 ? source.slice(1) : source.slice(1, slash);
  if (!who) throw new UsageError(`'${source}' names no one: @<handle>/<package>[@<version>]`);
  const release = rest || what;
  return release ? { who, what: release } : { who };
}

uses

used by