mip-validator
Version:
29 lines (24 loc) • 815 B
JavaScript
const _ = require('lodash')
const ERR = require('../error/dfn.json')
const matcher = require('../matcher.js')
exports.onAttr = function(attr, attrRule, node, nodeRule, error) {
if (!attrRule.properties) return
var obj = parseValueProperties(attr.value)
_.forOwn(attrRule.properties, (value, key) => {
var property = {
name: key,
value: obj[key]
}
if (matcher.matchValue(property.value, value)) return
error(ERR.INVALID_PROPERTY_VALUE_IN_ATTR_VALUE,
node.nodeName, attr.name,
property.name, property.value || '')
})
}
function parseValueProperties(value) {
return _.chain(value || '')
.split(/[,;]/)
.map(propertyStr => propertyStr.split('=').map(_.trim))
.fromPairs()
.value()
}