Skip to content

Commit

Permalink
feat: add an opt-out from semicolons in toModule()
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Oct 9, 2022
1 parent c968c16 commit c7ad5d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/generate-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7ad5d6

Please sign in to comment.