UNPKG

@acot/utils

Version:
27 lines (26 loc) 850 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseViewport = void 0; const puppeteer_core_1 = require("puppeteer-core"); const SIZE_REGEX = /(\d+)x(\d+)/; const parseViewport = (viewport) => { if (typeof viewport !== 'string') { return viewport; } if (puppeteer_core_1.devices[viewport] != null) { return puppeteer_core_1.devices[viewport].viewport; } const match = viewport.match(SIZE_REGEX); if (match != null) { return { width: parseInt(match[1], 10), height: parseInt(match[2], 10), }; } const json = JSON.parse(viewport); if (typeof json.width === 'number' && typeof json.height === 'number') { return json; } throw new Error('viewport parsing failed.'); }; exports.parseViewport = parseViewport;