A route's own path segment(s): a string, a `$localize` default, or a constant kept as `{expr}`; null when it cannot be named.
(text: string)
| 168 | |
| 169 | /** A route's own path segment(s): a string, a `$localize` default, or a constant kept as `{expr}`; null when it cannot be named. */ |
| 170 | function pathSegments(text: string): string[] | null { |
| 171 | const trimmed = text.trim(); |
| 172 | const value = staticString(trimmed); |
| 173 | if (value !== null) { |
| 174 | if (value.includes('**')) return null; |
| 175 | return value.split('/').filter((s) => s.length > 0); |
| 176 | } |
| 177 | if (CONSTANT_PATH.test(trimmed)) return [`{${trimmed.replace(/\s+/g, '')}}`]; |
| 178 | // `` `issue/:${ProjectConst.IssueId}` ``: a template whose holes are constants. |
| 179 | if (trimmed.startsWith('`') && skipString(trimmed, 0) === trimmed.length - 1) { |
| 180 | let ok = true; |
| 181 | const body = trimmed.slice(1, -1).replace(/\$\{([^}]*)\}/g, (_all, hole: string) => { |
| 182 | if (!CONSTANT_PATH.test(hole.trim())) ok = false; |
| 183 | return `{${hole.replace(/\s+/g, '')}}`; |
| 184 | }); |
| 185 | if (ok && !body.includes('**')) return body.split('/').filter((seg) => seg.length > 0); |
| 186 | return null; |
| 187 | } |
| 188 | // `internalRoutes.account.subRoutes.access.path + '/:id'`: each part a |
| 189 | // string or a constant, the constant a whole segment of its own. |
| 190 | if (trimmed.includes('+')) { |
| 191 | const joined: string[] = []; |
| 192 | for (const part of splitPlus(trimmed)) { |
| 193 | const literal = staticString(part); |
| 194 | if (literal !== null) joined.push(literal); |
| 195 | else if (CONSTANT_PATH.test(part.trim())) joined.push(`{${part.trim().replace(/\s+/g, '')}}`); |
| 196 | else return null; |
| 197 | } |
| 198 | const value = joined.join(''); |
| 199 | return value.includes('**') ? null : value.split('/').filter((seg) => seg.length > 0); |
| 200 | } |
| 201 | return null; |
| 202 | } |
| 203 | |
| 204 | /** An expression's `+` operands at depth 0, strings and brackets stepped over. */ |
| 205 | function splitPlus(text: string): string[] { |
no test coverage detected