UNPKG

711 BJavaScriptView Raw
1/**
2 * @copyright Copyright (c) 2019 Maxim Khorin <maksimovichu@gmail.com>
3 */
4'use strict';
5
6const Base = require('../base/Behavior');
7
8module.exports = class TrimBehavior extends Base {
9
10 constructor (config) {
11 super({
12 // attrs: []
13 ...config
14 });
15 this.setHandler(ActiveRecord.EVENT_BEFORE_VALIDATE, this.beforeValidate);
16 }
17
18 beforeValidate () {
19 for (const attr of this.attrs) {
20 const value = this.owner.get(attr);
21 if (value && typeof value === 'string') {
22 this.owner.set(attr, value.trim());
23 }
24 }
25 }
26};
27
28const ActiveRecord = require('../db/ActiveRecord');
\No newline at end of file