moodlexml-to-json
v1.1.3
Published
Javascript library for translating MoodleXML into JSON
Downloads
8
Maintainers
Readme
MoodleXML to JSON
This JS library parses MoodleXML quizzes into JSON objects.
Usage
import moodleXMLtoJSON from 'moodlexml-to-json';
// ...
moodleXMLtoJSON(xmlString, (result, error) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
Examples
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);
}
});
});
Development
Commands
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.
License
MIT © Sonsoles López Pernas