Skip to content

Commit

Permalink
feat: readVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepBergay committed May 10, 2021
1 parent 4c2eba6 commit 5b63a06
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const xml = require('fast-xml-parser');

const isVersion = key => key === 'version' || key === 'Version';

const findVersion = obj => {
if (isVersion(obj.tagname)) {
return obj.val;
}
if (Array.isArray(obj)) {
return obj.reduce((p, c) => p ?? findVersion(c), null);
}
return obj.child && Object.keys(obj.child).reduce((p, c) => p ?? findVersion(obj.child[c]), null);
};

const readVersion = contents => {
const obj = xml.getTraversalObj(contents);
return findVersion(obj);
};

const writeVersion = (contents, version) => {
// const file = xml.parse(contents);
// file.version = version;
// return new xml.j2xParser().parse(file);
};

module.exports = {
readVersion,
writeVersion,
};

0 comments on commit 5b63a06

Please sign in to comment.