```ts
export function matchSetting(rules: Record<string, string>, name: string): string | null {
  if (typeof name !== 'string' || name === '' || name.includes('*')) {
    throw new Error('Invalid name');
  }

  let bestMatch: [number, string] | null = null;

  for (const selector in rules) {
    const value = rules[selector];
    if (typeof value !== 'string') {
      throw new Error('Invalid rule value');
    }

    if (selector === name) {
      return value;
    } else if (selector.endsWith('.*')) {
      const prefix = selector.slice(0, -2);
      if (name.startsWith(prefix)) {
        const length = prefix.length;
        if (!bestMatch || length > bestMatch[0]) {
          bestMatch = [length, value];
        }
      }
    } else if (selector === '*') {
      if (!bestMatch) {
        bestMatch = [0, value];
      }
    }
  }

  return bestMatch ? bestMatch[1] : null;
}
```