All Projects → webpack → Schema Utils

webpack / Schema Utils

Licence: mit
Options Validation

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Schema Utils

Awesome Python Models
A curated list of awesome Python libraries, which implement models, schemas, serializers/deserializers, ODM's/ORM's, Active Records or similar patterns.
Stars: ✭ 124 (-23.46%)
Mutual labels:  schema, validation, validator
Joiful
TypeScript Declarative Validation for Joi
Stars: ✭ 177 (+9.26%)
Mutual labels:  schema, validation, validator
Schema Typed
Schema for data modeling & validation
Stars: ✭ 150 (-7.41%)
Mutual labels:  schema, validator
Credit Card
Credit Card Validation
Stars: ✭ 150 (-7.41%)
Mutual labels:  validation, validator
Aura.filter
Validate and sanitize arrays and objects.
Stars: ✭ 134 (-17.28%)
Mutual labels:  validation, validator
Validation Composite
Allows uniting of several validation rules into single one for easy re-usage
Stars: ✭ 159 (-1.85%)
Mutual labels:  validation, validator
Rdfunit
An RDF Unit Testing Suite
Stars: ✭ 117 (-27.78%)
Mutual labels:  schema, validation
Apvalidators
Codeless solution for form validation in iOS!
Stars: ✭ 130 (-19.75%)
Mutual labels:  validation, validator
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (-16.05%)
Mutual labels:  schema, validation
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+1045.06%)
Mutual labels:  schema, validation
Formhelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)
Stars: ✭ 155 (-4.32%)
Mutual labels:  validation, validator
Class Transformer Validator
A simple plugin for class-transformer and class-validator which combines them in a nice and programmer-friendly API.
Stars: ✭ 151 (-6.79%)
Mutual labels:  validation, validator
Validator
A tool to validate text inside TextInputLayout
Stars: ✭ 117 (-27.78%)
Mutual labels:  validation, validator
Laravel Zip Validator
Laravel ZIP file content validator
Stars: ✭ 120 (-25.93%)
Mutual labels:  validation, validator
Postguard
🐛 Statically validate Postgres SQL queries in JS / TS code and derive schemas.
Stars: ✭ 104 (-35.8%)
Mutual labels:  schema, validation
Ngx Dynamic Form Builder
FormBuilder + class-transformer + class-validator = dynamic form group builder for Angular10+
Stars: ✭ 93 (-42.59%)
Mutual labels:  validation, validator
Property Validator
✅ Easy property validation for JavaScript, Node and Express.
Stars: ✭ 153 (-5.56%)
Mutual labels:  validation, validator
Unicorn
Unicorn - W3C's Unified Validator
Stars: ✭ 70 (-56.79%)
Mutual labels:  validation, validator
Vue Rawmodel
RawModel.js plugin for Vue.js v2. Form validation has never been easier!
Stars: ✭ 79 (-51.23%)
Mutual labels:  schema, validation
Pandasschema
A validation library for Pandas data frames using user-friendly schemas
Stars: ✭ 135 (-16.67%)
Mutual labels:  schema, validation

npm node deps tests coverage chat size

schema-utils

Package for validate options in loaders and plugins.

Getting Started

To begin, you'll need to install schema-utils:

npm install schema-utils

API

schema.json

{
  "type": "object",
  "properties": {
    "option": {
      "type": "boolean"
    }
  },
  "additionalProperties": false
}
import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { option: true };
const configuration = { name: 'Loader Name/Plugin Name/Name' };

validate(schema, options, configuration);

schema

Type: String

JSON schema.

Simple example of schema:

{
  "type": "object",
  "properties": {
    "name": {
      "description": "This is description of option.",
      "type": "string"
    }
  },
  "additionalProperties": false
}

options

Type: Object

Object with options.

import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { foo: 'bar' };

validate(schema, { name: 123 }, { name: 'MyPlugin' });

configuration

Allow to configure validator.

There is an alternative method to configure the name andbaseDataPath options via the title property in the schema. For example:

{
  "title": "My Loader options",
  "type": "object",
  "properties": {
    "name": {
      "description": "This is description of option.",
      "type": "string"
    }
  },
  "additionalProperties": false
}

The last word used for the baseDataPath option, other words used for the name option. Based on the example above the name option equals My Loader, the baseDataPath option equals options.

name

Type: Object Default: "Object"

Allow to setup name in validation errors.

import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { foo: 'bar' };

validate(schema, options, { name: 'MyPlugin' });
Invalid configuration object. MyPlugin has been initialised using a configuration object that does not match the API schema.
 - configuration.optionName should be a integer.

baseDataPath

Type: String Default: "configuration"

Allow to setup base data path in validation errors.

import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { foo: 'bar' };

validate(schema, options, { name: 'MyPlugin', baseDataPath: 'options' });
Invalid options object. MyPlugin has been initialised using an options object that does not match the API schema.
 - options.optionName should be a integer.

postFormatter

Type: Function Default: undefined

Allow to reformat errors.

import schema from './path/to/schema.json';
import { validate } from 'schema-utils';

const options = { foo: 'bar' };

validate(schema, options, {
  name: 'MyPlugin',
  postFormatter: (formattedError, error) => {
    if (error.keyword === 'type') {
      return `${formattedError}\nAdditional Information.`;
    }

    return formattedError;
  },
});
Invalid options object. MyPlugin has been initialized using an options object that does not match the API schema.
 - options.optionName should be a integer.
   Additional Information.

Examples

schema.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 'loader-utils';
import { validate } from 'schema-utils';

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

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

  validate(schema, options, {
    name: 'Loader Name',
    baseDataPath: 'options',
  });

  // Code...
}

export default loader;

Plugin

import { validate } from 'schema-utils';

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

class Plugin {
  constructor(options) {
    validate(schema, options, {
      name: 'Plugin Name',
      baseDataPath: 'options',
    });

    this.options = options;
  }

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

export default Plugin;

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].