ajv-formats
Advanced tools
Comparing version
@@ -8,16 +8,15 @@ "use strict"; | ||
const names = Object.keys(fs); | ||
addFormats(names, fs, opts); | ||
addFormats(names, fs); | ||
} | ||
else if (Array.isArray(opts)) { | ||
addFormats(opts, formats_1.formats.full, "full"); | ||
addFormats(opts, formats_1.formats.full); | ||
} | ||
else { | ||
addFormats(opts.formats, formats_1.formats[opts.mode], opts.mode); | ||
addFormats(opts.formats, formats_1.formats[opts.mode]); | ||
} | ||
return ajv; | ||
function addFormats(list, fs, mode) { | ||
function addFormats(list, fs) { | ||
for (const f of list) { | ||
ajv.addFormat(f, fs[f]); | ||
} | ||
ajv._opts.format = mode; | ||
} | ||
@@ -24,0 +23,0 @@ }; |
@@ -1,7 +0,4 @@ | ||
import { Format, FormatMode } from "./formats"; | ||
import { Format } from "./formats"; | ||
export interface Ajv { | ||
addFormat: (name: string, f: Format) => Ajv; | ||
_opts: { | ||
format: FormatMode | false; | ||
}; | ||
} | ||
@@ -8,0 +5,0 @@ export default interface AjvPlugin { |
{ | ||
"name": "ajv-formats", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Format validation for Ajv v7 (WIP)", | ||
@@ -12,3 +12,4 @@ "main": "dist/index.js", | ||
"eslint": "eslint --ext .ts ./src/**/*", | ||
"test": "npm run prettier:check && npm run eslint && npm run build" | ||
"test": "jest", | ||
"ci-test": "npm run prettier:check && npm run eslint && npm run build && npm run test" | ||
}, | ||
@@ -15,0 +16,0 @@ "repository": { |
# ajv-formats | ||
Format validation for Ajv v7 (WIP) | ||
[](https://travis-ci.org/ajv-validator/ajv-formats) | ||
[](https://www.npmjs.com/package/ajv-formats) | ||
[](https://gitter.im/ajv-validator/ajv) | ||
[](https://github.com/sponsors/epoberezkin) |
@@ -82,4 +82,4 @@ export type FormatMode = "fast" | "full" | ||
// uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js | ||
uri: /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i, | ||
"uri-reference": /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i, | ||
uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i, | ||
"uri-reference": /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i, | ||
"uri-template": URITEMPLATE, | ||
@@ -86,0 +86,0 @@ url: URL, |
@@ -24,19 +24,14 @@ import { | ||
const names = Object.keys(fs) as FormatName[] | ||
addFormats(names, fs, opts) | ||
addFormats(names, fs) | ||
} else if (Array.isArray(opts)) { | ||
addFormats(opts, formats.full, "full") | ||
addFormats(opts, formats.full) | ||
} else { | ||
addFormats(opts.formats, formats[opts.mode], opts.mode) | ||
addFormats(opts.formats, formats[opts.mode]) | ||
} | ||
return ajv | ||
function addFormats( | ||
list: FormatName[], | ||
fs: DefinedFormats, | ||
mode: FormatMode | ||
) { | ||
function addFormats(list: FormatName[], fs: DefinedFormats) { | ||
for (const f of list) { | ||
ajv.addFormat(f, fs[f]) | ||
} | ||
ajv._opts.format = mode | ||
} | ||
@@ -43,0 +38,0 @@ } |
// TODO move plugin interface either to ajv or a separate package | ||
import {Format, FormatMode} from "./formats" | ||
import {Format} from "./formats" | ||
export interface Ajv { | ||
addFormat: (name: string, f: Format) => Ajv | ||
_opts: { | ||
format: FormatMode | false | ||
} | ||
} | ||
@@ -10,0 +7,0 @@ |
@@ -13,6 +13,8 @@ "use strict" | ||
jsonSchemaTest(instances, { | ||
description: `JSON-Schema Test Suite draft-07: ${instances.length} ajv instances with different options`, | ||
description: `JSON-Schema Test Suite draft-07 + extras: ${instances.length} ajv instances with different options`, | ||
suites: { | ||
draft7: | ||
"./JSON-Schema-Test-Suite/tests/draft7/optional/{format/*,ecmascript-regex}.json", | ||
"draft-07 formats": | ||
"./JSON-Schema-Test-Suite/tests/draft7/optional/format/*.json", | ||
"draft-07 regex": | ||
"./JSON-Schema-Test-Suite/tests/draft7/optional/ecmascript-regex.json", | ||
extras: "./extras/{**/,}*.json", | ||
@@ -19,0 +21,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1024257
0.04%290
0.35%9
125%0
-100%33951
-0.03%