UNPKG

playwright-fluent

Version:
29 lines (28 loc) 785 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNthHandle = void 0; async function getNthHandle(index, handles) { if (index === 0) { throw new Error('Index is one-based'); } if (Math.abs(index) > handles.length) { return []; } const currentHandles = [...handles]; if (index > 0) { let nthHandle; for (let i = 1; i <= index; i++) { nthHandle = currentHandles.shift(); } return nthHandle ? [nthHandle] : []; } if (index < 0) { let nthHandle; for (let i = 1; i <= -index; i++) { nthHandle = currentHandles.pop(); } return nthHandle ? [nthHandle] : []; } return []; } exports.getNthHandle = getNthHandle;