Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mjml-validator

Package Overview
Dependencies
Maintainers
6
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mjml-validator - npm Package Compare versions

Comparing version 4.13.0 to 4.15.1

14

lib/dependencies.js

@@ -6,4 +6,3 @@ "use strict";

});
exports.default = exports.registerDependencies = exports.assignDependencies = void 0;
exports.registerDependencies = exports.default = exports.assignDependencies = void 0;
const assignDependencies = (target, ...sources) => {

@@ -13,3 +12,2 @@ if (sources.length === 0) {

}
for (const source of sources) {

@@ -20,11 +18,8 @@ if (typeof source === 'object' && source !== null) {

const list = [];
if (target[tag]) {
list.push(...target[tag]);
}
if (source[tag]) {
list.push(...source[tag]);
}
target[tag] = Array.from(new Set(list));

@@ -39,15 +34,10 @@ } else {

}
return target;
};
exports.assignDependencies = assignDependencies;
const dependencies = {};
const registerDependencies = dep => {
assignDependencies(dependencies, dep);
};
exports.registerDependencies = registerDependencies;
var _default = dependencies;
exports.default = _default;
var _default = exports.default = dependencies;

39

lib/index.js
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = MJMLValidator;
Object.defineProperty(exports, "rulesCollection", {
Object.defineProperty(exports, "assignDependencies", {
enumerable: true,
get: function () {
return _MJMLRulesCollection.default;
return _dependencies.assignDependencies;
}
});
Object.defineProperty(exports, "registerRule", {
enumerable: true,
get: function () {
return _MJMLRulesCollection.registerRule;
}
});
exports.default = MJMLValidator;
Object.defineProperty(exports, "dependencies", {

@@ -29,2 +21,3 @@ enumerable: true,

});
exports.formatValidationError = void 0;
Object.defineProperty(exports, "registerDependencies", {

@@ -36,20 +29,19 @@ enumerable: true,

});
Object.defineProperty(exports, "assignDependencies", {
Object.defineProperty(exports, "registerRule", {
enumerable: true,
get: function () {
return _dependencies.assignDependencies;
return _MJMLRulesCollection.registerRule;
}
});
exports.formatValidationError = void 0;
Object.defineProperty(exports, "rulesCollection", {
enumerable: true,
get: function () {
return _MJMLRulesCollection.default;
}
});
var _ruleError = _interopRequireDefault(require("./rules/ruleError"));
var _MJMLRulesCollection = _interopRequireWildcard(require("./MJMLRulesCollection"));
var _dependencies = _interopRequireWildcard(require("./dependencies"));
const SKIP_ELEMENTS = ['mjml'];
const formatValidationError = _ruleError.default;
exports.formatValidationError = formatValidationError;
const formatValidationError = exports.formatValidationError = _ruleError.default;
function MJMLValidator(element, options = {}) {

@@ -62,7 +54,5 @@ const {

const skipElements = options.skipElements || SKIP_ELEMENTS;
if (options.dependencies == null) {
console.warn('"dependencies" option should be provided to mjml validator');
}
if (!skipElements.includes(tagName)) {

@@ -75,3 +65,2 @@ for (const rule of Object.values(_MJMLRulesCollection.default)) {

});
if (Array.isArray(ruleError)) {

@@ -84,3 +73,2 @@ errors.push(...ruleError);

}
if (children && children.length > 0) {

@@ -91,4 +79,3 @@ for (const child of children) {

}
return errors;
}
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.registerRule = registerRule;
exports.default = void 0;
var _validAttributes = _interopRequireDefault(require("./rules/validAttributes"));
var _validChildren = _interopRequireDefault(require("./rules/validChildren"));
var _validTag = _interopRequireDefault(require("./rules/validTag"));
var _validTypes = _interopRequireDefault(require("./rules/validTypes"));
var _errorAttr = _interopRequireDefault(require("./rules/errorAttr"));
const MJMLRulesCollection = {

@@ -28,3 +21,2 @@ validAttributes: _validAttributes.default,

};
function registerRule(rule, name) {

@@ -34,3 +26,2 @@ if (typeof rule !== 'function') {

}
if (name) {

@@ -41,7 +32,4 @@ MJMLRulesCollection[name] = rule;

}
return true;
}
var _default = MJMLRulesCollection;
exports.default = _default;
var _default = exports.default = MJMLRulesCollection;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {

@@ -9,5 +8,3 @@ value: true

exports.default = errorAttr;
var _ruleError = _interopRequireDefault(require("./ruleError"));
function errorAttr(element) {

@@ -28,3 +25,2 @@ const {

}
default:

@@ -35,3 +31,2 @@ return null;

}
module.exports = exports.default;

@@ -7,3 +7,2 @@ "use strict";

exports.default = ruleError;
function formatInclude(element) {

@@ -20,3 +19,2 @@ const {

}
function ruleError(message, element) {

@@ -35,3 +33,2 @@ const {

}
module.exports = exports.default;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {

@@ -9,7 +8,4 @@ value: true

exports.default = validateAttribute;
var _ruleError = _interopRequireDefault(require("./ruleError"));
const WHITELIST = ['mj-class', 'css-class'];
function validateAttribute(element, {

@@ -23,14 +19,10 @@ components

const Component = components[tagName];
if (!Component) {
return null;
}
const availableAttributes = [...Object.keys(Component.allowedAttributes || {}), ...WHITELIST];
const unknownAttributes = Object.keys(attributes || {}).filter(attribute => !availableAttributes.includes(attribute));
if (unknownAttributes.length === 0) {
return null;
}
const {

@@ -45,3 +37,2 @@ attribute,

}
module.exports = exports.default;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {

@@ -9,5 +8,3 @@ value: true

exports.default = validChildren;
var _ruleError = _interopRequireDefault(require("./ruleError"));
function validChildren(element, {

@@ -23,9 +20,6 @@ components,

const Component = components[tagName];
if (!Component || !children || !children.length) {
return null;
}
const errors = [];
for (const child of children) {

@@ -36,3 +30,2 @@ const childTagName = child.tagName;

const childIsValid = !ChildComponent || skipElements.includes(childTagName) || parentDependencies.includes(childTagName) || parentDependencies.some(dep => dep instanceof RegExp && dep.test(childTagName));
if (childIsValid === false) {

@@ -43,6 +36,4 @@ const allowedDependencies = Object.keys(dependencies).filter(key => dependencies[key].includes(childTagName) || dependencies[key].some(dep => dep instanceof RegExp && dep.test(childTagName)));

}
return errors;
}
module.exports = exports.default;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {

@@ -9,8 +8,5 @@ value: true

exports.default = validateTag;
var _ruleError = _interopRequireDefault(require("./ruleError"));
// Tags that have no associated components but are allowed even so
const componentLessTags = ['mj-all', 'mj-class', 'mj-selector', 'mj-html-attribute'];
function validateTag(element, {

@@ -24,10 +20,7 @@ components

const Component = components[tagName];
if (!Component) {
return (0, _ruleError.default)(`Element ${tagName} doesn't exist or is not registered`, element);
}
return null;
}
module.exports = exports.default;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {

@@ -9,5 +8,3 @@ value: true

exports.default = validateType;
var _ruleError = _interopRequireDefault(require("./ruleError"));
function validateType(element, {

@@ -22,16 +19,11 @@ components,

const Component = components[tagName];
if (!Component) {
return null;
}
const errors = [];
for (const [attr, value] of Object.entries(attributes || {})) {
const attrType = Component.allowedAttributes && Component.allowedAttributes[attr];
if (attrType) {
const TypeChecker = initializeType(attrType);
const result = new TypeChecker(value);
if (result.isValid() === false) {

@@ -42,6 +34,4 @@ errors.push((0, _ruleError.default)(`Attribute ${attr} ${result.getErrorMessage()}`, element));

}
return errors;
}
module.exports = exports.default;
{
"name": "mjml-validator",
"description": "mjml-validator",
"version": "4.13.0",
"version": "4.15.1",
"main": "lib/index.js",

@@ -30,3 +30,3 @@ "files": [

},
"gitHead": "d414b074bb3f478799fcc0c8e5ac8fac11d266aa"
"gitHead": "d53d73df61d07a22926c3d73b7b38dc1701aa99d"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc