UNPKG

vinmonopolet-ts

Version:

Extracts information on products, categories and stores from Vinmonopolet

33 lines (32 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const baseUrl = "https://www.vinmonopolet.no"; const oldUrl = "http://www.vinmonopolet.no/vareutvalg"; // Vinmonopolet seems to use a weird mix of escape/encodeURIComponent const enc = (str) => encodeURIComponent(str) .replace(/'/g, "%27") .replace(/\(/g, "%28") .replace(/\)/g, "%29") .replace(/~/g, "%7E") .replace(/!/g, "%21"); exports.default = (url, row) => { const path = String(url); if (path[0] === "/") { return `${baseUrl}${path}`; } if (path.indexOf(oldUrl) === 0) { // Try rewriting to new format const namePart = enc(row.Varenavn.replace(/[.\s]/gi, "-").replace(/-{2,}/g, "-")); return [ baseUrl, "vmp", row.Land && `Land/${enc(row.Land)}`, namePart, "p", row.Varenummer, ] .filter(Boolean) .join("/"); } return `${baseUrl}/p/${path}`; };