23 lines
578 B
JavaScript
23 lines
578 B
JavaScript
const semver = require('semver')
|
|
|
|
const { IncorrectTypeError, IncorrectPropertyError, MismatchedVersionError } = require('./errors.js')
|
|
|
|
function readGear(collection, v) {
|
|
if (v.type !== 'hord-gear') {
|
|
throw new IncorrectTypeError('hord-gear', v.type)
|
|
}
|
|
if (!Array.isArray(v.gear)) {
|
|
throw new IncorrectPropertyError('gear', typeof [], typeof v.gear)
|
|
}
|
|
if (!v.version || !semver.satisfies(v.version, '1.x')) {
|
|
throw new MismatchedVersionError('1.x', v.version)
|
|
}
|
|
for (let g of v.gear) {
|
|
collection.insert(g)
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
readGear,
|
|
}
|