(total: number, rangeStr?: string)
| 8 | * 1,3-5,8 => [1, 3, 4, 5, 8] |
| 9 | */ |
| 10 | export function parseRangeString(total: number, rangeStr?: string) { |
| 11 | if (!rangeStr || rangeStr === 'all' || rangeStr === '*') |
| 12 | return range(1, total + 1) |
| 13 | |
| 14 | if (rangeStr === 'none') |
| 15 | return [] |
| 16 | |
| 17 | const indexes: number[] = [] |
| 18 | for (const part of rangeStr.split(/[,;]/g)) { |
| 19 | if (!part.includes('-')) { |
| 20 | indexes.push(+part) |
| 21 | } |
| 22 | else { |
| 23 | const [start, end] = part.split('-', 2) |
| 24 | indexes.push( |
| 25 | ...range(+start, !end ? (total + 1) : (+end + 1)), |
| 26 | ) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return uniq(indexes).filter(i => i <= total).sort((a, b) => a - b) |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Accepts `16/9` `1:1` `3x4` |
no outgoing calls
no test coverage detected