Nocturnal Practitioners of Magic
Miss any of our Open RFC calls?Watch the recordings here! »

@offen/schemaify

0.1.0 • Public • Published

schemaify

Browserify transform for compiling JSON schemas at build time using AJV

Installation

The package is released to npm as schemaify:

npm install @offen/schemaify -D

Usage

In the default configuration, the transform is applied to all files with a .schema extension. The transformed module will export the AJV validate function.

In your application:

var validateFoo = require('./foo.schema')
 
var ok = validateFoo({ foo: true })
if (!ok) {
  console.log(validateFoo.errors)
  throw new Error('Foo did not validate')
}

When bundling:

var browserify = require('browserify')
 
var b = browserify()
b.add('app.js')
b.transform('@offen/schemaify')
b.bundle(function (err, src) {
  // consume bundle
})

Options

The transform accepts the following options as its 2nd arguments:

secure

By default, schemaify only compiles "secure" schemas. This can be disabled by passing secure: false to the transform.

matcher

By default, schemaify only compiles files with a .schema extension. If you have different requirements you can pass a Regexp string to matcher for the transform to use.

Important caveat: Due to the way that Browserify handles JSON files, you currently cannot use JSON files for storing your schemas, as this would make these files subject to another set of rules that would conflict with.

Releasing a new version

New versions can be released using npm version <patch|minor|major>. Make sure you are authenticated against the @offen scope with npm.

License

Copyright 2020 Frederik Ring - Available under the MIT License

Install

npm i @offen/schemaify

DownloadsWeekly Downloads

73

Version

0.1.0

License

MIT

Unpacked Size

5.46 kB

Total Files

5

Last publish

Collaborators

  • avatar