UNPKG

1.01 kBTypeScriptView Raw
1const formatToList = (items: string[]) =>
2 items.map((key) => `- ${key}`).join('\n');
3
4export default function validatePathConfig(config: any, root = true) {
5 const validKeys = ['initialRouteName', 'screens'];
6
7 if (!root) {
8 validKeys.push('path', 'exact', 'stringify', 'parse');
9 }
10
11 const invalidKeys = Object.keys(config).filter(
12 (key) => !validKeys.includes(key)
13 );
14
15 if (invalidKeys.length) {
16 throw new Error(
17 `Found invalid properties in the configuration:\n${formatToList(
18 invalidKeys
19 )}\n\nDid you forget to specify them under a 'screens' property?\n\nYou can only specify the following properties:\n${formatToList(
20 validKeys
21 )}\n\nSee https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`
22 );
23 }
24
25 if (config.screens) {
26 Object.entries(config.screens).forEach(([_, value]) => {
27 if (typeof value !== 'string') {
28 validatePathConfig(value, false);
29 }
30 });
31 }
32}