| 4 | |
| 5 | |
| 6 | export function verifyPaths(paths) { |
| 7 | if (Object.keys(paths).length === 0){ |
| 8 | return true; |
| 9 | } |
| 10 | // must end with '*' or not have '*' at all |
| 11 | const errors = [] |
| 12 | for (const path of Object.keys(paths)){ |
| 13 | const stars = path.match(/\*/g); |
| 14 | if (stars?.length > 1){ |
| 15 | errors.push(`Path has more then one "*" token: ${paths}`); |
| 16 | continue; |
| 17 | } else if (stars?.length === 1){ |
| 18 | if (!path.endsWith('*')){ |
| 19 | errors.push(`Path "*" token not at the end of path: ${path}`); |
| 20 | continue; |
| 21 | } |
| 22 | } else { |
| 23 | // exact paths must have only one entry |
| 24 | if (paths[path].length !== 1){ |
| 25 | errors.push(`exact path aliases must have only one value: [${path}] has ${paths[path].length} values`); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | } |
| 30 | return errors.length ? errors : true; |
| 31 | } |
| 32 | |
| 33 | function sortOnStringLengthDescending(a, b){ |
| 34 | return b.length - a.length; |