UNPKG

itch-dl

Version:

Bulk download games from itch.io - TypeScript implementation

45 lines (44 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ItchDownloadError = void 0; exports.getIntAfterMarkerInJson = getIntAfterMarkerInJson; exports.shouldSkipItemByGlob = shouldSkipItemByGlob; exports.shouldSkipItemByRegex = shouldSkipItemByRegex; const minimatch_1 = require("minimatch"); class ItchDownloadError extends Error { } exports.ItchDownloadError = ItchDownloadError; function getIntAfterMarkerInJson(text, marker, key) { let markerLine = null; const lines = text.split(/\r?\n/).reverse(); for (const line of lines) { const idx = line.indexOf(marker); if (idx !== -1) { markerLine = line.slice(idx); break; } } if (!markerLine) { return null; } const regex = new RegExp(`\\"${key}\\":\\s?(\\d+)`); const match = markerLine.match(regex); if (!match) { return null; } return parseInt(match[1], 10); } function shouldSkipItemByGlob(kind, item, glob) { if (glob && !(0, minimatch_1.minimatch)(item, glob)) { console.info(`${kind} '${item}' does not match the glob filter '${glob}', skipping`); return true; } return false; } function shouldSkipItemByRegex(kind, item, regex) { if (regex && !new RegExp(`^${regex}$`).test(item)) { console.info(`${kind} '${item}' does not match the regex filter '${regex}', skipping`); return true; } return false; }