This JS library parses MoodleXML quizzes into JSON objects.
import moodleXMLtoJSON from 'moodlexml-to-json';
// ...
moodleXMLtoJSON(xmlString, (result, error) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
On the server
import moodleXMLtoJSON from 'moodlexml-to-json';
const fs = require('fs');
const path = require('path');
const xmlString = fs.readFileSync("/path/to/your/file.xml", 'utf8');
moodleXMLtoJSON(xmlString, (result, error) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
On a JS SPA
import moodleXMLtoJSON from 'moodlexml-to-json';
// ...
fetch("https://myweb.org/moodle.xml")
.then(res=>res.text())
.then(xmlString => {
moodleXMLtoJSON(xmlString, (result, error) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
});
npm run clean
- Removelib/
directorynpm test
- Run tests with linting and coverage results.npm test:only
- Run tests without linting or coverage.npm test:watch
- You can even re-run tests on file changes!npm test:prod
- Run tests with minified code.npm run test:examples
- Test written examples on pure JS for better understanding module usage.npm run lint
- Run ESlint with airbnb-confignpm run cover
- Get coverage report for your code.npm run build
- Babel will transpile ES6 => ES5 and minify the code.npm run prepublish
- Hook for npm. Do all the checks before publishing your module.
MIT © Sonsoles López Pernas