```ts
export function matchSetting(rules: Record<string, string>, name: string): string | null {
  if (typeof name !== "string" || name === "" || name.includes("*")) {
    throw new Error("name must be a star-free non-empty string");
  }

  let bestMatch: { selector: string; value: string } | null = null;

  for (const [selector, value] of Object.entries(rules)) {
    if (typeof value !== "string") {
      throw new Error("rule values must be strings");
    }

    if (selector === name) {
      return value;
    } else if (
      selector.endsWith(".*") &&
      name.startsWith(selector.slice(0, -2))
    ) {
      if (!bestMatch || selector.length > bestMatch.selector.length) {
        bestMatch = { selector, value };
      }
    }
  }

  return bestMatch ? bestMatch.value : null;
}
```