-
-
Notifications
You must be signed in to change notification settings - Fork 1
Using plugins
Alan Berdinelli edited this page Feb 13, 2024
·
2 revisions
Added in v1.6.0
- To use a plugin, first you need to install it with npm:
npm install --save <plugin name>.
- Then import it in your project, for example here we translate schemy messages with the spanish plugin:
const Schemy = require('schemy');
const SchemyTranslationsSpanish = require('schemy-translations-spanish');
Schemy.extend(SchemyTranslationsSpanish);You can call Schemy.extend as many times as you need.
const Schemy = require('schemy');
const SchemyTranslationsSpanish = require('schemy-translations-spanish');
const SomeCoolSchemyFeature = require('schemy-cool-feature');
Schemy.extend(SchemyTranslationsSpanish);
Schemy.extend(SomeCoolSchemyFeature);Or if you prefer, you can pass an array of plugins to the extend method:
const Schemy = require('schemy');
const SchemyTranslationsSpanish = require('schemy-translations-spanish');
const SomeCoolSchemyFeature = require('schemy-cool-feature');
Schemy.extend([SchemyTranslationsSpanish, SomeCoolSchemyFeature]);Once you extended Schemy with the desired funcionality, you can just use it as usual:
const Schemy = require('schemy');
const SchemyTranslationsSpanish = require('schemy-translations-spanish');
Schemy.extend(SchemyTranslationsSpanish);
const schema = new Schemy({
title: String
});
schema.validate({ title: 1 });
schema.getValidationErrors(); // => [ 'La propiedad title es de tipo number, se esperaba string' ]Developed with ♥ by Alan Berdinelli.