@exodus/schemasafe
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -110,2 +110,3 @@ // These typings are experimental and known to be incomplete. | ||
dryRun?: boolean | ||
lint?: boolean | ||
allowUnusedKeywords?: boolean | ||
@@ -141,2 +142,8 @@ allowUnreachable?: boolean | ||
interface LintError { | ||
message: string | ||
keywordLocation: string | ||
schema: Schema | ||
} | ||
declare const validator: (schema: Schema, options?: ValidatorOptions) => Validate | ||
@@ -146,5 +153,8 @@ | ||
declare const lint: (schema: Schema, options?: ValidatorOptions) => LintError[] | ||
export { | ||
validator, | ||
parser, | ||
lint, | ||
Validate, | ||
@@ -155,4 +165,5 @@ ValidationError, | ||
Parse, | ||
LintError, | ||
Json, | ||
Schema, | ||
} |
{ | ||
"name": "@exodus/schemasafe", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "JSON Safe Parser & Schema Validator", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -31,2 +31,3 @@ # `@exodus/schemasafe` | ||
Throws at build time if those options are used with schemas that don't allow to do that safely. | ||
* Can use used as a [schema linter](./doc/Linter.md). | ||
@@ -33,0 +34,0 @@ ## Installation |
@@ -6,2 +6,8 @@ 'use strict' | ||
/* | ||
* Construct a function from lines/blocks/if conditions. | ||
* | ||
* Returns a Function instance (makeFunction) or code in text format (makeModule). | ||
*/ | ||
const INDENT_START = /[{[]/ | ||
@@ -8,0 +14,0 @@ const INDENT_END = /[}\]]/ |
@@ -35,2 +35,3 @@ 'use strict' | ||
if (opts.dryRun) return | ||
if (opts.lint) return scope.lintErrors | ||
const fun = genfun() | ||
@@ -93,2 +94,7 @@ if (parse) { | ||
module.exports = { validator, parser } | ||
const lint = function(schema, { lint: lintOption = true, ...opts } = {}) { | ||
if (!lintOption) throw new Error('can not disable lint option in lint()') | ||
return validator(schema, { lint: lintOption, ...opts }) | ||
} | ||
module.exports = { validator, parser, lint } |
@@ -5,2 +5,6 @@ 'use strict' | ||
/* | ||
* JSON pointer collection/resolution logic | ||
*/ | ||
function safeSet(map, key, value, comment = 'keys') { | ||
@@ -7,0 +11,0 @@ if (!map.has(key)) return map.set(key, value) |
@@ -7,2 +7,5 @@ 'use strict' | ||
// Given a scope object, generates new symbol/loop/pattern/format/ref variable names, | ||
// also stores in-scope format/ref mapping to variable names | ||
const scopeMethods = (scope) => { | ||
@@ -14,2 +17,3 @@ // cache meta info for known scope variables, per meta type | ||
// Generic variable names, requires a base name aka prefix | ||
const gensym = (name) => { | ||
@@ -22,2 +26,3 @@ if (!cache.sym.get(name)) cache.sym.set(name, 0) | ||
// Regexp pattern names | ||
const genpattern = (p) => { | ||
@@ -31,2 +36,3 @@ if (cache.pattern.has(p)) return cache.pattern.get(p) | ||
// Loop variable names | ||
if (!cache.loop) cache.loop = 'ijklmnopqrstuvxyz'.split('') | ||
@@ -39,2 +45,3 @@ const genloop = () => { | ||
// Reference (validator function) names | ||
const getref = (sub) => cache.ref.get(sub) | ||
@@ -47,2 +54,3 @@ const genref = (sub) => { | ||
// Format validation function names | ||
const genformat = (impl) => { | ||
@@ -49,0 +57,0 @@ let n = cache.format.get(impl) |
Sorry, the diff of this file is too big to display
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
137022
2478
270