1.0.0 • Published 26 days ago

@teaplus2024/fugiat-nihil-ullam-doloribus v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
26 days ago

@teaplus2024/fugiat-nihil-ullam-doloribus

JSON Schema formats for Ajv

Build Status npm Gitter GitHub Sponsors

Usage

// ESM/TypeScript import
import Ajv from "ajv"
import addFormats from "@teaplus2024/fugiat-nihil-ullam-doloribus"
// Node.js require:
const Ajv = require("ajv")
const addFormats = require("@teaplus2024/fugiat-nihil-ullam-doloribus")

const ajv = new Ajv()
addFormats(ajv)

Formats

The package defines these formats:

See regular expressions used for format validation and the sources that were used in formats.ts.

Please note: JSON Schema draft-07 also defines formats iri, iri-reference, idn-hostname and idn-email for URLs, hostnames and emails with international characters. These formats are available in @teaplus2024/fugiat-nihil-ullam-doloribus-draft2019 plugin.

Keywords to compare values: formatMaximum / formatMinimum and formatExclusiveMaximum / formatExclusiveMinimum

These keywords allow to define minimum/maximum constraints when the format keyword defines ordering (compare function in format definition).

These keywords are added to ajv instance when @teaplus2024/fugiat-nihil-ullam-doloribus is used without options or with option keywords: true.

These keywords apply only to strings. If the data is not a string, the validation succeeds.

The value of keywords formatMaximum/formatMinimum and formatExclusiveMaximum/formatExclusiveMinimum should be a string or $data reference. This value is the maximum (minimum) allowed value for the data to be valid as determined by format keyword. If format keyword is not present schema compilation will throw exception.

When these keyword are added, they also add comparison functions to formats "date", "time" and "date-time". User-defined formats also can have comparison functions. See addFormat method.

require("@teaplus2024/fugiat-nihil-ullam-doloribus")(ajv)

const schema = {
  type: "string",
  format: "date",
  formatMinimum: "2016-02-06",
  formatExclusiveMaximum: "2016-12-27",
}

const validDataList = ["2016-02-06", "2016-12-26"]

const invalidDataList = ["2016-02-05", "2016-12-27", "abc"]

Options

Options can be passed via the second parameter. Options value can be

  1. The list of format names that will be added to ajv instance:
addFormats(ajv, ["date", "time"])

Please note: when ajv encounters an undefined format it throws exception (unless ajv instance was configured with strict: false option). To allow specific undefined formats they have to be passed to ajv instance via formats option with true value:

const ajv = new Ajv({formats: {date: true, time: true}}) // to ignore "date" and "time" formats in schemas.
  1. Format validation mode (default is "full") with optional list of format names and keywords option to add additional format comparison keywords:
addFormats(ajv, {mode: "fast"})

or

addFormats(ajv, {mode: "fast", formats: ["date", "time"], keywords: true})

In "fast" mode the following formats are simplified: "date", "time", "date-time", "iso-time", "iso-date-time", "uri", "uri-reference", "email". For example, "date", "time" and "date-time" do not validate ranges in "fast" mode, only string structure, and other formats have simplified regular expressions.

Tests

npm install
git submodule update --init
npm test

License

MIT

indicatorfunctionstypedarraydeep-copysuperagentpluginanimationregexsetImmediateimportlogslotRxwatchinginternaljQueryformattingArray.prototype.filterless mixinsvalidationeast-asian-widthWeakMapfull-widthxhrtermmapcode pointscompile lessutiltoArraydatastructuredefineReactiveXlengthcharacterlookopensarraysdefinePropertyoutputcolumnsTypedArrayString.prototype.trimairbnbuser-streamsperformanceprettytypescollectionrecursivegdprnodejsgetPrototypeOfparseObject.entriesmomentRegExp#flagsSymbol.toStringTagentriescolorslesslrubannercmdweakmapUint8Arraytostringtagfromtapeshrinkwraprm -frconcurrencyprotobufhttpsregular expressionprotocol-buffersES5stylesspinnermulti-packageenvfantasy-landArray.prototype.flatMap@@toStringTagjsonschemaopenermatchesquerystringObjectcss nestingargsutilitycjkjestprogresscopypromisesprotoObject.definePropertytsauthlistenersreact-testing-libraryequalitynamesES2017browserslisttypeerrorshamArrayBuffer#sliceexecutablejsxjson-schemaincludesponyfillReflect.getPrototypeOfcss-in-jsdeepclonehandlersYAMLbuffersjsl10nObservableECMAScript 2015flattendiffcall-boundcryptconfigoptimisthardlinksconfigurableexecpropertieswatchnumberxtermbytesortedobjectObject.assignJSON-SchemareactcryptomimeconnectreadablesignalIteratorappoptimizerboundshebangmkdirargparsetoolssidereusemiddlewarecolorbyteLengthECMAScript 3waapitimeCSScreateECMAScript 6__proto__matchHyBivaluearrayeslintsigtermsameValueZerowalkcoreframermakenodeexitpolyfillchromesigintsymbolAsyncIteratorspecvar3dcliviewsearchclassnameratelimitdeepcopyFunction.prototype.nametrimStartasyncjasmineiteratorargvloggingstructuredClonegetOwnPropertyDescriptorStyleSheettacitinternal slotsafepositivegroupByfindLastIndexCSSStyleDeclarationinterruptsdeleteauthenticationfindupstylingnested cssfolderspringstyleless cssexpresshasjsdiffECMAScript 5stringifiersignalstranspilees-abstractES2020symlinkspipeperformantkeystypedarraysstartES2021BigUint64ArraytypeoftakegetintrinsicReactiveExtensionslimiteddescriptortypedmodulestypanionless.jsiemkdirsthrottleconcatshellminimalemitlazycallbindes6poseinputfulltextstdlibpopmotionvalidcloneWebSocketsprocessUint16ArrayexeenumerablepicomatchxssES2019yuppatchsymbols[[Prototype]]valuesFloat32Arraymoduleoffsetenvironmentdom-testing-librarytrimLeftcensorlinewrapstyled-componentstranspilerutil.inspectxdg-opengesturessequenceform-validationbootstrap lessa11ydeep-cloneworkspace:*hookscircularcompilertelephonearktypenpmjson-schema-validationdescriptionexit-codecomputed-typesmkdirpfile systemBigInt64ArrayECMAScript 2021tapArrayBufferArray.prototype.findLastIndexemojioperating-systemdayjsprototypearraybuffer0preserve-symlinkssomefixed-widthstablezodregexppropertyECMAScript 7sharedarraybufferprivate dataMapsetterbundlingcorsremoveterminalasciiurlES8curriedObject.valueshelperscss variablekey256debugfiletoolkitajvchromiumstringifyproppackagescachermwritedefaultjsonpathfpeslint-pluginmruURLSearchParamsjwtES2022wrapdirectoryfastcopytestingnativereact posetypesafemonorepofunctionalinvariant-0io-tstypescriptMicrosoftspeedECMAScript 2022argumentgraphqlsettingsschemeESnextobjchaiUint32Arraypurecore-jsparentsES3japanesedependenciesbabeldroptouchbreakES6ramdafast-deep-cloneaccessorformreadablestreamwidthmime-dbwhatwgrgbcollection.es6callboundparentes-shim APIparseransi6to5busyefficientsyntaxerrorbufferthreeTypeBoximmereventstyped arrayttysanitizedeterministicshimcallinferenceastencryptionreducerstyleguideglobcall-bindjsonfast-cloneeslintpluginkoreanwebsiteapies8es-shimsURLregular expressionsgradients css3writablepackagewebpnpm9Int8Arrayes2016iterateajaxstreams2fetchgenericsflatlinuxharmonyserializedateArrayweaksetserializationawesomesauceduplexSetmetadataunicodeeslintconfigECMAScript 2016Pushschemaexpressionfunction_.extendtoStringTagformatstatelessdragless compilerrandomspawn.envcodesPromiseawaitdirpostcss-pluginredux-toolkitclassesECMAScript 2018joisymlinkstarterObject.keysdescriptorsslicebcryptreduxrangeerrornopefastcloneassignstreameventDispatcherescapefigletkarmaStreamsWebSocketvalidatorwindowspromisejson-schema-validatoreverymochathroatonceObject.getPrototypeOf
1.0.0

26 days ago