About sanitizers

Sanitizers are an important aspect of your application, as they handle the validation of the input data you process. Having this in mind, it is mandatory that your sanitizers are fully tested and functional. If you want your sanitizer to be in thorin's core sanitizers, create a pull request.

The general rule of a sanitizer is to verify if the input data has the expected shape, check any limitation or restriction and convert it into the expected type. A number sanitizers should convert the input data into a number, that means typeof output === 'number' should always be true. A boolean sanitizers should convert to true or false, and so on. Keeping things predictable will minimize the errors your application will encounter.

Thorin offers a set of sanitizers out of the box. You can also add your own sanitizers by implementing the interface. Custom sanitizers should be placed under the app/sanitizers folder and should be manually loaded via thorin.loadPath('app/sanitizers'). A small example can be viewed below

'use strict';
// File: app.js
const thorin = require('thorin');
// add your components, stores, transports, etc.
thorin.addStore(require('thorin-store-sql'));
// Load up all your sanitizer .js files under app/sanitizers Each one should include itself in thorin.
thorin.loadPath('app/sanitizers', thorin);

thorin.run((err) => {
   log.info('Running');
});

'use strict';
// File: app/sanitizers/string.js
module.exports = (thorin) => {
   class StringSanitizer extends thorin.Interface.Sanitizer {
      // implement the sanitizers
   }
   // register your sanitizer so that it can be used.
   thorin.addSanitizer(StringSanitizer);
};

Do you have a question or is something missing?

You can always create a new issue on GitHub or contact one of the core founders by chat.