Writing Custom Modules and Formatters (ASP)

Sometimes you want to format or transform your data in a way that is not supported with the supplied formatters included with Wappler. This topic will explain you how you can write your own modules and formatters.

Writing your own Formatters

Location

All formatters are being placed in the extensions/server_connect/formatters folder. A single ASP file can contain multiple formatters and you can have multiple ASP files. Best practice is to group formatters that belong together in a single ASP file. For example you to keep all array specific formatters in a file called array.asp.

File Structure

Here a sample of how such a formatter file looks like.

<script runat="server" language="jscript">

exports.uppercase = function(str) {
  return str.toUpperCase();
};

exports.lowercase = function(str) {
  return str.toLowerCase();
};

</script>

Only methods added to exports will be available as formatter. Naming a formatter the same as one bundled with Server Connect will override it.

Writing your own Modules

Location

All modules are being placed in the extensions/server_connect/modules folder. The name of the file is also the module name and the methods it exposes are the action names. Best practice is to group actions together under a module and not create a file for each action.

File Structure

Here a sample of how a module file looks like.

<script runat="server" language="jscript">

var Parser = require('lib/core/parser');

exports.setvalue = function(options, name) {
  return Parser.parseValue(options.value);
}

</script>

Only methods added to exports will be available as actions. Naming the file the same as a build-in module will override it. The options parameter will contain all the options and the name is the name of the action step. The Parser.parseValue(...) can be used to parse expressions.

Community Page
Last updated: