UNPKG

@tracking-exposed/data

Version:
42 lines (30 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.sanitize = exports.toUrl = exports.toEntities = void 0; var _path = _interopRequireDefault(require("path")); var _url = require("url"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const toEntities = url => { const u = url.startsWith("http") ? new _url.URL(url) : new _url.URL(`http://will-be-ignored.com/${_path.default.basename(url)}`); const entityPath = _path.default.basename(u.pathname).replace(/\.xml$/, "").replace(/\/(.*)/, "$1"); if (entityPath === "") return []; const entities = entityPath.split("+").map(decodeURIComponent); return Array.from(new Set(entities)).sort((a, b) => a.localeCompare(b)); }; exports.toEntities = toEntities; const toUrl = entities => { if (entities.length === 0) throw new Error("No entities supplied to form an URL."); return Array.from(new Set(entities)).sort((a, b) => a.localeCompare(b)).join("+"); }; exports.toUrl = toUrl; const sanitize = url => toUrl(toEntities(url)); exports.sanitize = sanitize; var _default = { toEntities, toUrl, sanitize }; exports.default = _default; //# sourceMappingURL=feeds.js.map