Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.select = function (path) {
var nodes = select(doc, path);
return nodes.map(function (n) {
return n.toString();
});
};
for (var k = 0; k < stops.length; k += 1) {
journey.push(parseBasicStop(stops[k], date));
}
secJson.push({
departure: {
name: select(section, ".//Departure//Station/@name")[0].value,
id: select(section, ".//Departure//Station/@externalId")[0].value,
lat: convertCoord(select(section, ".//Departure//Station/@y")[0].value),
lng: convertCoord(select(section, ".//Departure//Station/@x")[0].value),
time: makeTimestamp(date, select(section, ".//Departure//Dep/Time/text()")[0].data),
platform: strip(getData(select(section, ".//Departure//Dep/Platform/Text/text()")[0]))
},
arrival: {
name: select(section, ".//Arrival//Station/@name")[0].value,
id: select(section, ".//Arrival//Station/@externalId")[0].value,
lat: convertCoord(select(section, ".//Arrival//Station/@y")[0].value),
lng: convertCoord(select(section, ".//Arrival//Station/@x")[0].value),
time: makeTimestamp(date, select(section, ".//Arrival//Arr/Time/text()")[0].data),
platform: strip(getData(select(section, ".//Arrival//Arr/Platform/Text/text()")[0]))
},
journey: journey,
transport: {
name: strip(select(section, ".//Journey//Attribute[@type='NAME']//Text/text()")[0].data),
direction: strip(select(section, ".//Journey//Attribute[@type='DIRECTION']//Text/text()")[0].data)
}
});
}
conJson.push({
sections: secJson
});
}
return conJson;
var parseBasicStop = function(stop, date) {
station = select(stop, ".//Station");
if (station.length) {
var arrival = null, arrivalPlatform = null;
var departure = null, departurePlatform = null;
if (select(stop, ".//Arr").length) {
arrival = makeTimestamp(date, select(stop, ".//Arr/Time/text()")[0].data);
arrivalPlatform = strip(getData(select(stop, ".//Arr/Platform/Text/text()")[0]));
}
if (select(stop, ".//Dep").length) {
departure = makeTimestamp(date, select(stop, ".//Dep/Time/text()")[0].data);
departurePlatform = strip(getData(select(stop, ".//Dep/Platform/Text/text()")[0]));
}
return {
name: select(stop, ".//Station/@name")[0].value,
id: select(stop, ".//Station/@externalId")[0].value,
lat: convertCoord(select(stop, ".//Station/@y")[0].value),
lng: convertCoord(select(stop, ".//Station/@x")[0].value),
arrival: arrival,
arrivalPlatform: arrivalPlatform,
departure: departure,
departurePlatform: departurePlatform
};
}
};
station = select(stop, ".//Station");
if (station.length) {
var arrival = null, arrivalPlatform = null;
var departure = null, departurePlatform = null;
if (select(stop, ".//Arr").length) {
arrival = makeTimestamp(date, select(stop, ".//Arr/Time/text()")[0].data);
arrivalPlatform = strip(getData(select(stop, ".//Arr/Platform/Text/text()")[0]));
}
if (select(stop, ".//Dep").length) {
departure = makeTimestamp(date, select(stop, ".//Dep/Time/text()")[0].data);
departurePlatform = strip(getData(select(stop, ".//Dep/Platform/Text/text()")[0]));
}
return {
name: select(stop, ".//Station/@name")[0].value,
id: select(stop, ".//Station/@externalId")[0].value,
lat: convertCoord(select(stop, ".//Station/@y")[0].value),
lng: convertCoord(select(stop, ".//Station/@x")[0].value),
arrival: arrival,
arrivalPlatform: arrivalPlatform,
departure: departure,
departurePlatform: departurePlatform
};
}
};
var parseBasicStop = function(stop, date) {
station = select(stop, ".//Station");
if (station.length) {
var arrival = null, arrivalPlatform = null;
var departure = null, departurePlatform = null;
if (select(stop, ".//Arr").length) {
arrival = makeTimestamp(date, select(stop, ".//Arr/Time/text()")[0].data);
arrivalPlatform = strip(getData(select(stop, ".//Arr/Platform/Text/text()")[0]));
}
if (select(stop, ".//Dep").length) {
departure = makeTimestamp(date, select(stop, ".//Dep/Time/text()")[0].data);
departurePlatform = strip(getData(select(stop, ".//Dep/Platform/Text/text()")[0]));
}
return {
name: select(stop, ".//Station/@name")[0].value,
id: select(stop, ".//Station/@externalId")[0].value,
lat: convertCoord(select(stop, ".//Station/@y")[0].value),
lng: convertCoord(select(stop, ".//Station/@x")[0].value),
arrival: arrival,
arrivalPlatform: arrivalPlatform,
departure: departure,
departurePlatform: departurePlatform
};
}
};
} else {
const fileName = fileNames[0];
const jsFiles = files.filter(file =>
equalCaseInsensitive(fileName, path.basename(file.path))
);
if (jsFiles.length === 0) {
validationMessages.push(
`File in manifest "${fileName}" is not in package zip`
);
}
}
const resourcesFiles = files.filter(
file => path.basename(file.path) === 'Resources.zip'
);
const resourcesFileNames = select(
doc,
'/dotnetnuke/packages/package/components/component/resourceFiles/resourceFile/name/text()'
).map(({ data }) => data);
if (resourcesFiles.length < resourcesFileNames.length) {
validationMessages.push(
`"${
resourcesFileNames[0]
}" specified in manifest but is not in package zip`
);
} else if (resourcesFiles.length > resourcesFileNames.length) {
validationMessages.push(
`"${resourcesFiles[0].path}" is in package zip but is not specified in manifest`
);
}
return validationMessages;
var parseTripRequestBody = function(body) {
var doc = new dom().parseFromString(body);
var connections = select(doc, "//Connection");
var conJson = [];
for (var i = 0; i < connections.length; i += 1) {
var date = select(connections[i], './/Overview/Date/text()')[0].data;
var sections = select(connections[i], './/ConSection');
var secJson = [];
for (var j = 0; j < sections.length; j += 1) {
var section = sections[j];
var journey = [];
var stops = select(section, './/Journey/PassList/BasicStop');
for (var k = 0; k < stops.length; k += 1) {
journey.push(parseBasicStop(stops[k], date));
}
secJson.push({
departure: {
name: select(section, ".//Departure//Station/@name")[0].value,
id: select(section, ".//Departure//Station/@externalId")[0].value,
lat: convertCoord(select(section, ".//Departure//Station/@y")[0].value),
lng: convertCoord(select(section, ".//Departure//Station/@x")[0].value),
time: makeTimestamp(date, select(section, ".//Departure//Dep/Time/text()")[0].data),
const safeXpath = (doc, p) => {
try {
return xpath(doc, p);
} catch (_) {
return null;
}
};
var sections = select(connections[i], './/ConSection');
var secJson = [];
for (var j = 0; j < sections.length; j += 1) {
var section = sections[j];
var journey = [];
var stops = select(section, './/Journey/PassList/BasicStop');
for (var k = 0; k < stops.length; k += 1) {
journey.push(parseBasicStop(stops[k], date));
}
secJson.push({
departure: {
name: select(section, ".//Departure//Station/@name")[0].value,
id: select(section, ".//Departure//Station/@externalId")[0].value,
lat: convertCoord(select(section, ".//Departure//Station/@y")[0].value),
lng: convertCoord(select(section, ".//Departure//Station/@x")[0].value),
time: makeTimestamp(date, select(section, ".//Departure//Dep/Time/text()")[0].data),
platform: strip(getData(select(section, ".//Departure//Dep/Platform/Text/text()")[0]))
},
arrival: {
name: select(section, ".//Arrival//Station/@name")[0].value,
id: select(section, ".//Arrival//Station/@externalId")[0].value,
lat: convertCoord(select(section, ".//Arrival//Station/@y")[0].value),
lng: convertCoord(select(section, ".//Arrival//Station/@x")[0].value),
time: makeTimestamp(date, select(section, ".//Arrival//Arr/Time/text()")[0].data),
platform: strip(getData(select(section, ".//Arrival//Arr/Platform/Text/text()")[0]))
},
journey: journey,
transport: {
name: strip(select(section, ".//Journey//Attribute[@type='NAME']//Text/text()")[0].data),
direction: strip(select(section, ".//Journey//Attribute[@type='DIRECTION']//Text/text()")[0].data)
}
});
var parseBasicStop = function(stop, date) {
station = select(stop, ".//Station");
if (station.length) {
var arrival = null, arrivalPlatform = null;
var departure = null, departurePlatform = null;
if (select(stop, ".//Arr").length) {
arrival = makeTimestamp(date, select(stop, ".//Arr/Time/text()")[0].data);
arrivalPlatform = strip(getData(select(stop, ".//Arr/Platform/Text/text()")[0]));
}
if (select(stop, ".//Dep").length) {
departure = makeTimestamp(date, select(stop, ".//Dep/Time/text()")[0].data);
departurePlatform = strip(getData(select(stop, ".//Dep/Platform/Text/text()")[0]));
}
return {
name: select(stop, ".//Station/@name")[0].value,
id: select(stop, ".//Station/@externalId")[0].value,
lat: convertCoord(select(stop, ".//Station/@y")[0].value),
lng: convertCoord(select(stop, ".//Station/@x")[0].value),
arrival: arrival,
arrivalPlatform: arrivalPlatform,
departure: departure,
departurePlatform: departurePlatform
};
}
};