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