-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgetSlideIndex.ts
More file actions
31 lines (26 loc) · 881 Bytes
/
getSlideIndex.ts
File metadata and controls
31 lines (26 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { isPresentation } from "./isPresentation";
import { isSlide } from "./isSlide";
/**
* Gets the index of a slide in its presentation.
*
* @param {GoogleAppsScript.Slides.Slide} slide The slide object.
* @param {GoogleAppsScript.Slides.Presentation} presentation The presentation object.
* @returns {number | null} The zero-based index of the slide, or `null` if the slide is not found in the presentation.
* @since 1.5.0
*/
export function getSlideIndex(
slide: GoogleAppsScript.Slides.Slide,
presentation: GoogleAppsScript.Slides.Presentation
): number | null {
if (!isSlide(slide) || !isPresentation(presentation)) {
return null;
}
const slideId = slide.getObjectId();
const slides = presentation.getSlides();
for (let i = 0; i < slides.length; i++) {
if (slides[i].getObjectId() === slideId) {
return i;
}
}
return null;
}