diff --git a/src/generate-function.js b/src/generate-function.js index 535ad09..3f6cb8d 100644 --- a/src/generate-function.js +++ b/src/generate-function.js @@ -84,7 +84,7 @@ module.exports = () => { const scopeDefs = processScope(scope).map( ([key, val]) => `const ${safe(key)} = ${jaystring(val)};` ) - return `(function() {\n'use strict'\n${scopeDefs.join('\n')}\n${build()}})();` + return `(function() {\n'use strict'\n${scopeDefs.join('\n')}\n${build()}})()` }, makeFunction(scope = {}) { diff --git a/src/index.js b/src/index.js index 72fa260..2f7e9ca 100644 --- a/src/index.js +++ b/src/index.js @@ -31,7 +31,7 @@ const validator = (schema, { jsonCheck = false, isJSON = false, schemas = [], .. fun.write('}') } const validate = fun.makeFunction(scope) - validate.toModule = () => fun.makeModule(scope) + validate.toModule = ({ semi = true } = {}) => fun.makeModule(scope) + (semi ? ';' : '') validate.toJSON = () => schema return validate } @@ -67,13 +67,13 @@ const parser = function(schema, opts = {}) { return { valid: false } } } - parse.toModule = () => + parse.toModule = ({ semi = true } = {}) => [ '(function(src) {', `const validate = ${validate.toModule()}`, `const parse = ${parse}\n`, 'return parse(src)', - '});', + `})${semi ? ';' : ''}`, ].join('\n') parse.toJSON = () => schema return parse