Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function(xmlData: string) {
// when a tag has attributes
const options = {
attrPrefix: "@_",
textNodeName: "#text",
ignoreNonTextNodeAttr: true,
ignoreTextNodeAttr: true,
ignoreNameSpace: true,
ignoreRootElement: false,
textNodeConversion: true,
textAttrConversion: false
};
if (fastXmlParser.validate(xmlData) === true) {
//optional
const jsonObj = fastXmlParser.parse(xmlData, options);
var array = jsonToArray(jsonObj);
const data = {
data: array,
meta: {
fields: ["name", "value"],
type: "tabular"
}
};
return data;
}
return null;
}
static getFromXML(contents: string, name = 'New Event'): Promise {
const json = parser.parse(contents).sml;
// debugger;
// A few mods here to convert it to compatible json suunto string
json.DeviceLog.Samples = json.DeviceLog.Samples.Sample;
const samplesWithUTC: any[] = json.DeviceLog.Samples.filter((sample: any) => !!sample.UTC);
// Find the first UTC timestamped sample and use it later for start date
const startDate = samplesWithUTC.length ? new Date(samplesWithUTC[0].UTC) : new Date(json.DeviceLog.Header.DateTime);
// Determine the end date
const endDate = samplesWithUTC.length > 1 ? samplesWithUTC[samplesWithUTC.length - 1].UTC : (new Date((startDate.getTime() + json.DeviceLog.Header.Duration * 1000)));
// Filter out the old activity type
async function getModuleConfig(root: string, path: string): Promise {
const configPath = join(root, path, 'etc', 'module.xml');
const rawConfig = await fs.readFile(configPath, 'utf8');
const parsedConfig = parse(rawConfig, {
ignoreAttributes: false,
attributeNamePrefix: '',
ignoreNameSpace: true,
});
const config = {
moduleID: parsedConfig.config.module.name as string,
sequence: [] as string[],
pathFromStoreRoot: join(sep, path),
};
const { sequence } = parsedConfig.config.module;
if (!sequence) return config;
if (Array.isArray(sequence.module)) {
// multiple dependencies
export const getGamesJapan = async (): Promise => {
try {
const gamesJP = await fetch(constants.JP_GET_GAMES_URL);
if (!gamesJP.ok) throw new Error('JP_games_request_failed');
const parsedGamesJP = xml2json(await gamesJP.text());
const allGamesJP: interfaces.GameJP[] = parsedGamesJP.TitleInfoList.TitleInfo;
return allGamesJP;
} catch (err) {
if (/(?:JP_games_request_failed)/i.test(err.toString())) throw new constants.EshopError('Fetching of JP Games failed');
throw err;
}
};
static getProcessId(bpmnString) {
const jsonObj = parser.parse(bpmnString, BpmnParser.parserOptions);
if (jsonObj) {
if (jsonObj["bpmn:definitions"]) {
if (jsonObj["bpmn:definitions"]["bpmn:process"]) {
const attr = jsonObj["bpmn:definitions"]["bpmn:process"].attr;
return attr ? attr["@_id"] : undefined;
}
}
}
return undefined;
}
/**
return new Promise((resolve, reject) => {
resolve(
require('fast-xml-parser').parse(content, {
attrPrefix: '_',
textNodeName: '__',
ignoreNonTextNodeAttr: false,
ignoreTextNodeAttr: false,
ignoreNameSpace: false,
})
);
});
}
async xml ( filePath ) {
const content = await File.read ( filePath );
try {
return xml2js ( content );
} catch ( e ) {}
}
function cleanXML(message){
var fastXmlParser = require('fast-xml-parser');
var jsonObj = fastXmlParser.parse(message);
return jsonObj;
}
export async function systemUsers(h: AdtHTTP) {
const response = await h.request("/sap/bc/adt/system/users", {
headers: { Accept: "application/*" }
})
const raw = parse(response.body)
return xmlArray(raw, "atom:feed", "atom:entry").map(
(r: any): SystemUser => ({ id: r["atom:id"], title: r["atom:title"] })
)
}
private extractParentVersion(pomXmlContent: string): string | null {
const pomXml = xmlParser.parse(pomXmlContent)
if (!pomXml.project || !pomXml.project.parent) {
this.logger.warn("Missing parent tag")
return null
}
const groupId: string = pomXml.project.parent.groupId
const artifactId: string = pomXml.project.parent.artifactId
const version: string = pomXml.project.parent.version
if (!groupId || !artifactId) {
this.logger.warn(`Missing groupId or artifactId - ${groupId}.${artifactId}`)
return null
}
if (PomFile.ParentGroupByArtifact[artifactId] !== groupId) {