```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");
  }

  const isExactSelector = (selector: string) => selector.endsWith(".*");

  const getMatchingRule = (rules: Record<string, string>, name: string): [string, string] | null => {
    for (const [selector, value] of Object.entries(rules)) {
      if (name === selector || (isExactSelector(selector) && name.startsWith(selector))) {
        return [selector, value];
      }
    }
    return null;
  };

  const matchingRule = getMatchingRule(rules, name);

  if (!matchingRule) {
    return null;
  }

  return matchingRule[1];
}
```