Skip to content

createNamePolicy

Creates a name policy that transforms symbol names based on element kind.

import { createNamePolicy } from "@alloy-js/core";
function createNamePolicy<T extends string>(namer: (name: string, element: T) => string): NamePolicy<T>;
namer(name: string, element: T) => string

NamePolicy<T>

element identifies the kind of declaration (e.g., "value", "type"). The set of valid element strings is defined by the language package.

When element is undefined (outside a declaration context), [unresolved link] and [unresolved link] short-circuit and return the original name unchanged — the namer callback is not invoked. The namer therefore always receives a defined T. This means names outside a declaration context cannot be transformed by the policy.

const policy = createNamePolicy((name, element) => {
  if (element === "value") return toCamelCase(name);
  if (element === "type")  return toPascalCase(name);
  return name;
});
<Output namePolicy={policy}>...</Output>