@webpack-utilities/schema
webpack Validation Utils
Last updated 4 years ago by michael-ciniawsky .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @webpack-utilities/schema 
SYNC missed versions from official npm registry.

npm node deps test coverage code style chat

Schema Utils

Options Validation for Loaders/Plugins

Install

npm i @webpack-utilities/schema

Usage

validateOptions(schema, options, title)

schema.json

{
  "type": "object",
  "properties": {
    "option": {
      "type": [ "boolean" ]
    }
  },
  "errorMessage": {
    "option": "should be {Boolean} (https:/github.com/org/repo#anchor)"
  }
  "additionalProperties": false
}
import schema from 'path/to/schema.json'
import { validateOptions } from '@webpack-utilities/schema'

validateOptions(schema, options, 'Loader/Plugin Name')

Examples

options.json

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "test": {
      "anyOf": [
        { "type": "array" },
        { "type": "string" },
        { "instanceof": "RegExp" }
      ]
    },
    "transform": {
      "instanceof": "Function"
    },
    "sourceMap": {
      "type": "boolean"
    }
  },
  "additionalProperties": false
}

Loader

import { getOptions } from '@webpack-utilities/loader'
import { validateOptions } from '@webpack-utilities/schema'

import schema from 'path/to/options.json'

function loader (src, map) {
  const options = getOptions(this) || {}

  validateOptions(schema, options, 'Loader Name')

  // Code...
}

Plugin

import schema from 'path/to/options.json'
import { validateOptions } from '@webpack-utilities/schema'

class Plugin {
  constructor (options) {
    validateOptions(schema, options, 'Plugin Name')

    this.options = options
  }

  apply (compiler) {
    // Code...
  }
}

Current Tags

  • 1.0.0-alpha.0                                ...           latest (4 years ago)

1 Versions

  • 1.0.0-alpha.0                                ...           4 years ago
Maintainers (1)
Downloads
Total 73
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 0
Dependencies (3)
Dev Dependencies (7)
Dependents (1)

Copyright 2014 - 2021 © npmmirror.com |