mjml-validator
Advanced tools
Comparing version 4.0.0-alpha.2 to 4.0.0-alpha.3
@@ -14,2 +14,4 @@ 'use strict'; | ||
var dependencies = {}; | ||
var registerDependencies = exports.registerDependencies = function registerDependencies(dep) { | ||
@@ -19,4 +21,2 @@ return (0, _merge2.default)(dependencies, dep); | ||
var dependencies = {}; | ||
exports.default = dependencies; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.registerDependencies = exports.dependencies = exports.formatValidationError = exports.registerRule = exports.rulesCollection = undefined; | ||
exports.registerDependencies = exports.dependencies = exports.registerRule = exports.rulesCollection = exports.formatValidationError = undefined; | ||
@@ -17,2 +17,3 @@ var _dependencies2 = require('./dependencies'); | ||
}); | ||
exports.default = MJMLValidator; | ||
@@ -31,2 +32,6 @@ var _concat = require('lodash/concat'); | ||
var _values = require('lodash/values'); | ||
var _values2 = _interopRequireDefault(_values); | ||
var _ruleError = require('./rules/ruleError'); | ||
@@ -40,6 +45,2 @@ | ||
var _values = require('lodash/values'); | ||
var _values2 = _interopRequireDefault(_values); | ||
var _dependencies3 = _interopRequireDefault(_dependencies2); | ||
@@ -51,12 +52,15 @@ | ||
var SKIP_ELEMENTS = ['mjml', 'mj-body', 'mj-head']; | ||
var formatValidationError = exports.formatValidationError = _ruleError2.default; | ||
exports.rulesCollection = _MJMLRulesCollection2.default; | ||
exports.registerRule = _MJMLRulesCollection.registerRule; | ||
var formatValidationError = exports.formatValidationError = _ruleError2.default; | ||
var SKIP_ELEMENTS = ["mjml", "mj-body", "mj-head"]; | ||
var validateNode = function validateNode(element) { | ||
exports.dependencies = _dependencies3.default; | ||
function MJMLValidator(element) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var children = element.children, | ||
tagName = element.tagName; | ||
var errors = void 0; | ||
@@ -66,3 +70,3 @@ | ||
errors = _concat2.default.apply(undefined, [errors].concat(_toConsumableArray((0, _values2.default)(_MJMLRulesCollection2.default).map(function (rule) { | ||
return rule(element); | ||
return rule(element, options); | ||
})))); | ||
@@ -73,3 +77,3 @@ } | ||
errors = _concat2.default.apply(undefined, [errors].concat(_toConsumableArray(children.map(function (child) { | ||
return validateNode(child); | ||
return MJMLValidator(child, options); | ||
})))); | ||
@@ -79,5 +83,2 @@ } | ||
return (0, _filter2.default)(errors); | ||
}; | ||
exports.dependencies = _dependencies3.default; | ||
exports.default = validateNode; | ||
} |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.registerRule = undefined; | ||
exports.registerRule = registerRule; | ||
@@ -23,5 +23,4 @@ var _warning = require('warning'); | ||
var registerRule = exports.registerRule = function registerRule(rule, name) { | ||
if (typeof rule != 'function' || rule.length !== 1) { | ||
function registerRule(rule, name) { | ||
if (typeof rule !== 'function' || rule.length !== 1) { | ||
return (0, _warning2.default)(false, 'Your rule must be a function and must have one parameter which is the element to validate'); | ||
@@ -35,4 +34,4 @@ } | ||
} | ||
}; | ||
} | ||
exports.default = MJMLRulesCollection; |
@@ -6,37 +6,20 @@ 'use strict'; | ||
}); | ||
exports.validTag = exports.validChildren = exports.validAttributes = undefined; | ||
var _validAttributes = require('./validAttributes'); | ||
var _validAttributes2 = require('./validAttributes'); | ||
Object.keys(_validAttributes).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _validAttributes[key]; | ||
} | ||
}); | ||
}); | ||
var _validAttributes3 = _interopRequireDefault(_validAttributes2); | ||
var _validChildren = require('./validChildren'); | ||
var _validChildren2 = require('./validChildren'); | ||
Object.keys(_validChildren).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _validChildren[key]; | ||
} | ||
}); | ||
}); | ||
var _validChildren3 = _interopRequireDefault(_validChildren2); | ||
var _validTag = require('./validTag'); | ||
var _validTag2 = require('./validTag'); | ||
Object.keys(_validTag).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _validTag[key]; | ||
} | ||
}); | ||
}); | ||
var _validTag3 = _interopRequireDefault(_validTag2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.validAttributes = _validAttributes3.default; | ||
exports.validChildren = _validChildren3.default; | ||
exports.validTag = _validTag3.default; |
@@ -6,4 +6,4 @@ "use strict"; | ||
}); | ||
exports.default = function (message, element) { | ||
exports.default = ruleError; | ||
function ruleError(message, element) { | ||
var line = element.line, | ||
@@ -19,4 +19,3 @@ tagName = element.tagName; | ||
}; | ||
}; | ||
} | ||
module.exports = exports["default"]; |
@@ -6,8 +6,4 @@ 'use strict'; | ||
}); | ||
exports.validateAttribute = undefined; | ||
exports.default = validateAttribute; | ||
var _mjmlCore = require('mjml-core'); | ||
var _mjmlCore2 = _interopRequireDefault(_mjmlCore); | ||
var _concat = require('lodash/concat'); | ||
@@ -35,10 +31,12 @@ | ||
var WHITELIST = ['mj-class']; | ||
var WHITELIST = ['mj-class', 'css-class']; | ||
var validateAttribute = exports.validateAttribute = function validateAttribute(element) { | ||
function validateAttribute(element, _ref) { | ||
var components = _ref.components; | ||
var attributes = element.attributes, | ||
tagName = element.tagName; | ||
var Component = _mjmlCore2.default[tagName]; | ||
var Component = components[tagName]; | ||
if (!Component) { | ||
@@ -57,3 +55,4 @@ return; | ||
return (0, _ruleError2.default)((unknownAttributes.length > 1 ? "Attributes" : "Attribute") + ' ' + unknownAttributes.join(', ') + ' ' + (unknownAttributes.length > 1 ? "are illegal" : "is illegal"), element); | ||
}; | ||
return (0, _ruleError2.default)((unknownAttributes.length > 1 ? 'Attributes' : 'Attribute') + ' ' + unknownAttributes.join(', ') + ' ' + (unknownAttributes.length > 1 ? 'are illegal' : 'is illegal'), element); | ||
} | ||
module.exports = exports['default']; |
@@ -6,12 +6,4 @@ 'use strict'; | ||
}); | ||
exports.validChildren = undefined; | ||
exports.default = validChildren; | ||
var _mjmlCore = require('mjml-core'); | ||
var _mjmlCore2 = _interopRequireDefault(_mjmlCore); | ||
var _dependencies = require('../dependencies'); | ||
var _dependencies2 = _interopRequireDefault(_dependencies); | ||
var _filter = require('lodash/filter'); | ||
@@ -25,2 +17,6 @@ | ||
var _dependencies = require('../dependencies'); | ||
var _dependencies2 = _interopRequireDefault(_dependencies); | ||
var _ruleError = require('./ruleError'); | ||
@@ -32,8 +28,10 @@ | ||
var validChildren = exports.validChildren = function validChildren(element) { | ||
function validChildren(element, _ref) { | ||
var components = _ref.components; | ||
var children = element.children, | ||
tagName = element.tagName; | ||
var Component = _mjmlCore2.default[tagName]; | ||
var Component = components[tagName]; | ||
if (!Component) { | ||
@@ -49,3 +47,3 @@ return; | ||
var childTagName = child.tagName; | ||
var ChildComponent = _mjmlCore2.default[childTagName]; | ||
var ChildComponent = components[childTagName]; | ||
var parentDependencies = _dependencies2.default[tagName] || []; | ||
@@ -63,2 +61,3 @@ | ||
})); | ||
}; | ||
} | ||
module.exports = exports['default']; |
@@ -6,8 +6,4 @@ 'use strict'; | ||
}); | ||
exports.validateTag = undefined; | ||
exports.default = validateTag; | ||
var _mjmlCore = require('mjml-core'); | ||
var _mjmlCore2 = _interopRequireDefault(_mjmlCore); | ||
var _ruleError = require('./ruleError'); | ||
@@ -19,10 +15,13 @@ | ||
var validateTag = exports.validateTag = function validateTag(element) { | ||
function validateTag(element, _ref) { | ||
var components = _ref.components; | ||
var tagName = element.tagName; | ||
var Component = _mjmlCore2.default[tagName]; | ||
var Component = components[tagName]; | ||
if (!Component) { | ||
return (0, _ruleError2.default)('Element ' + tagName + ' doesn\'t exist or is not registered', element); | ||
} | ||
}; | ||
} | ||
module.exports = exports['default']; |
{ | ||
"name": "mjml-validator", | ||
"description": "mjml-validator", | ||
"version": "4.0.0-alpha.2", | ||
"version": "4.0.0-alpha.3", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12250
200