(plan: MarbleTimingPlan)
| 266 | } |
| 267 | |
| 268 | export function parseTimingPlan(plan: MarbleTimingPlan): number[] { |
| 269 | if (typeof plan !== 'string') { |
| 270 | let previous = -Infinity; |
| 271 | return plan.map((time) => { |
| 272 | const valid = validateDuration(time); |
| 273 | if (valid <= previous) { |
| 274 | throw new Error('Timing plan entries must be strictly increasing absolute times.'); |
| 275 | } |
| 276 | previous = valid; |
| 277 | return valid; |
| 278 | }); |
| 279 | } |
| 280 | |
| 281 | const characters = [...plan]; |
| 282 | const opportunities: number[] = []; |
| 283 | let frame = 0; |
| 284 | |
| 285 | for (let index = 0; index < characters.length; index++) { |
| 286 | const character = characters[index]; |
| 287 | if (character === undefined) { |
| 288 | break; |
| 289 | } |
| 290 | if (isWhitespace(character)) { |
| 291 | continue; |
| 292 | } |
| 293 | |
| 294 | const duration = readDuration(characters, index); |
| 295 | if (duration) { |
| 296 | frame += duration.milliseconds; |
| 297 | index += duration.length - 1; |
| 298 | continue; |
| 299 | } |
| 300 | |
| 301 | if (character === '-') { |
| 302 | frame += 1; |
| 303 | continue; |
| 304 | } |
| 305 | if ('|#^!()'.includes(character)) { |
| 306 | throw new Error(`Timing plans cannot contain the reserved marker "${character}".`); |
| 307 | } |
| 308 | opportunities.push(frame); |
| 309 | frame += 1; |
| 310 | } |
| 311 | return opportunities; |
| 312 | } |
| 313 | |
| 314 | export function toSubscriptionLog(subscription: ParsedSubscription): ParsedSubscription { |
| 315 | return { |
no test coverage detected