-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: standalone mode * docs: update toc
- Loading branch information
1 parent
b57abf1
commit 658411c
Showing
6 changed files
with
297 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
const Ajv = require('ajv') | ||
const fastUri = require('fast-uri') | ||
const ajvFormats = require('ajv-formats') | ||
|
||
module.exports = buildAjv | ||
|
||
function buildAjv (options) { | ||
const ajvInstance = new Ajv({ ...options, strictSchema: false, uriResolver: fastUri }) | ||
ajvFormats(ajvInstance) | ||
|
||
const validateDateTimeFormat = ajvFormats.get('date-time').validate | ||
const validateDateFormat = ajvFormats.get('date').validate | ||
const validateTimeFormat = ajvFormats.get('time').validate | ||
|
||
ajvInstance.addKeyword({ | ||
keyword: 'fjs_date_type', | ||
validate: (schema, date) => { | ||
if (date instanceof Date) { | ||
return true | ||
} | ||
if (schema === 'date-time') { | ||
return validateDateTimeFormat(date) | ||
} | ||
if (schema === 'date') { | ||
return validateDateFormat(date) | ||
} | ||
if (schema === 'time') { | ||
return validateTimeFormat(date) | ||
} | ||
return false | ||
} | ||
}) | ||
|
||
return ajvInstance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.