core/converters/search.converter.ts
core/converters/search.converter.ts is a file in Bane's Lab Deploy. 37 lines of code and 16 definitions.
const URL_OPEN = "<url>";
const URL_CLOSE = "</url>";
const LOC_OPEN = "<loc>";
const LOC_CLOSE = "</loc>";
const LASTMOD_OPEN = "<lastmod>";
const LASTMOD_CLOSE = "</lastmod>";
const taggedText = function taggedText(text: string, open: string, close: string): string | null {
const start = text.indexOf(open);
if (start === -1) {
return null;
}
const end = text.indexOf(close, start + open.length);
return end === -1 ? null : text.slice(start + open.length, end);
};
export const stampsOf = function stampsOf(xml: string): ReadonlyMap<string, string | null> {
const stamps = new Map<string, string | null>();
let cursor = xml.indexOf(URL_OPEN);
while (cursor !== -1) {
const end = xml.indexOf(URL_CLOSE, cursor);
if (end === -1) {
break;
}
const entry = xml.slice(cursor, end);
const location = taggedText(entry, LOC_OPEN, LOC_CLOSE);
if (location !== null) {
stamps.set(location, taggedText(entry, LASTMOD_OPEN, LASTMOD_CLOSE));
}
cursor = xml.indexOf(URL_OPEN, end);
}
return stamps;
};
export const changedLocations = function changedLocations(before: string | null, after: string): readonly string[] {
const held = before === null ? new Map<string, string | null>() : stampsOf(before);
return [...stampsOf(after)]
.filter(([location, lastmod]) => !held.has(location) || held.get(location) !== lastmod)
.map(([location]) => location);
};