Value filters

Filters implement generic conversion of values during the import process. Plugins can add to the standard value filters provided by the data import framework.

To implement a value filter, you need to define a service, then declare it in a service metadata file.

The service should return a function that takes a value as a single argument, and returns a converted value, or undefined. This service will be called once and only once per Batch, so your implementation can keep state in a closure.

Example filter

This example filter value ‘doubles’ a string.

P.implementService("example:data:filter:double-string",
    function() {
        return function(value) {
            if(typeof(value) === "string") {
                return value + value;
            }
        };
    }
);

To enable this value filter to be found by the data import framework, create a file/__service-metadata__.json in your plugin which declares the details of this filter:

{
    "example:data:filter:double-string": {
        "statements": [
            "conforms-to haplo:data-import-framework:filter"
        ],
        "metadata": {
            "name": "example:double-string",
            "description": "Doubles a string.",
            "documentationURL":
                "https://docs.example.org/filter/double-string"
        }
    }
}

The "documentationURL" is optional, but if supplied, will add a link under the value filter’s name in the admin UI.