ajv-formats
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -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) | ||
[![Build Status](https://travis-ci.org/ajv-validator/ajv-formats.svg?branch=master)](https://travis-ci.org/ajv-validator/ajv-formats) | ||
[![npm](https://img.shields.io/npm/v/ajv-formats.svg)](https://www.npmjs.com/package/ajv-formats) | ||
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) | ||
[![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](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
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
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
290
9
0
33951