(path: string)
| 13 | * @returns {String|Boolean} true if path is valid, string error message if not |
| 14 | */ |
| 15 | export const validate = (path: string): string | boolean => { |
| 16 | if (typeof path !== 'string') { |
| 17 | return 'path must be a string' |
| 18 | } |
| 19 | |
| 20 | if (path.length === 0) { |
| 21 | return 'path can\'t be empty' |
| 22 | } |
| 23 | |
| 24 | if (path[0] === '/') { |
| 25 | return 'path can\'t start with /' |
| 26 | } |
| 27 | |
| 28 | const invalidVariableNames = path.match(INVALID_VARIABLE_REGEXP) |
| 29 | |
| 30 | if (invalidVariableNames !== null) { |
| 31 | return `invalid variable name ${invalidVariableNames[0]}` |
| 32 | } |
| 33 | |
| 34 | return true |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Parses a path and returns a regexp matcher with capture groups for |
nothing calls this directly
no outgoing calls
no test coverage detected