```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 match: { selector: string; value: string } | null = null;

  for (const [selector, value] of Object.entries(rules)) {
    if (typeof value !== "string") {
      throw new Error(`rule value "${value}" must be a string`);
    }
    if (selector === name) {
      return value;
    }
    if (selector.endsWith(".*")) {
      const prefix = selector.slice(0, -2);
      if (name.startsWith(prefix)) {
        if (!match || match.selector.length < selector.length) {
          match = { selector, value };
        }
      }
    }
  }

  if (match) {
    return match.value;
  } else if ( "*" in rules ) {
    return rules["*"];
  }

  return null;
}
```