Hain supports Plugin Preferences defined by preferences.json using JSONSchema.
preferences.json
Put a preferences.json file into your plugin folder and you can open Preferences by entering open preferences in Hain.
open preferences
See http://json-schema.org/ for full details on JSONSchema
{ "type": "object", "properties": { "testStr": { "type": "string", "title": "Test string", "default": "this is default" }, "testBool": { "type": "boolean", "title": "Test boolean", "default": true } } }
Will show in Hain preferences like this:
You can access the preferences via pluginContext.preferences such as:
pluginContext.preferences
'use strict' module.exports = (pluginContext) => { const logger = pluginContext.logger; const prefObj = pluginContext.preferences; const pref = prefObj.get(); logger.log(pref.testStr); logger.log(pref.testBool); // or logger.log(prefObj.get('testStr')); logger.log(prefObj.get('testBool')); function startup() { ... } function search(query, res) { ... } function execute(id, payload, extra) { ... } return { startup, search, execute }; };
See Preferences for details.
You can customize error messages for various conditions.
{ "type": "string", "minLength": 3, "errorMessages": "This is error!" }
- or -
{ "type": "string", "minLength": 3, "maxLength": 5, "errorMessages": { "minLength": "This is Error for minLength", "maxLength": "This is Error for maxLength" } }
You can define a set of values for string property
{ "type": "string", "enum": [ "a", "b", "c" ] }
Currently, the type of root object must be object.
object
Generated using TypeDoc
preferences.json Format
Hain supports Plugin Preferences defined by
preferences.jsonusing JSONSchema.Put a
preferences.jsonfile into your plugin folder and you can open Preferences by enteringopen preferencesin Hain.See http://json-schema.org/ for full details on JSONSchema
Example
{ "type": "object", "properties": { "testStr": { "type": "string", "title": "Test string", "default": "this is default" }, "testBool": { "type": "boolean", "title": "Test boolean", "default": true } } }Will show in Hain preferences like this:
Accessing From Code
You can access the preferences via
pluginContext.preferencessuch as:'use strict' module.exports = (pluginContext) => { const logger = pluginContext.logger; const prefObj = pluginContext.preferences; const pref = prefObj.get(); logger.log(pref.testStr); logger.log(pref.testBool); // or logger.log(prefObj.get('testStr')); logger.log(prefObj.get('testBool')); function startup() { ... } function search(query, res) { ... } function execute(id, payload, extra) { ... } return { startup, search, execute }; };See Preferences for details.
Non-Standard Options
Error Messages
You can customize error messages for various conditions.
Example
{ "type": "string", "minLength": 3, "errorMessages": "This is error!" }- or -
{ "type": "string", "minLength": 3, "maxLength": 5, "errorMessages": { "minLength": "This is Error for minLength", "maxLength": "This is Error for maxLength" } }Enum Values
You can define a set of values for string property
Example
{ "type": "string", "enum": [ "a", "b", "c" ] }Limitations
Currently, the type of root object must be
object.