MCPcopy
hub / github.com/slidevjs/slidev / parseRangeString

Function parseRangeString

packages/parser/src/utils.ts:10–31  ·  view source on GitHub ↗
(total: number, rangeStr?: string)

Source from the content-addressed store, hash-verified

8 * 1,3-5,8 => [1, 3, 4, 5, 8]
9 */
10export 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`

Callers 5

useNav.tsFile · 0.90
utils.test.tsFile · 0.90
loadMarkdownFunction · 0.70
updateCodeHighlightRangeFunction · 0.50
exportSlidesFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected