1
- 'use strict' ;
2
1
const debug = require ( 'debug' ) ( 'splitter' ) ;
3
2
const _ = require ( 'lodash' ) ;
4
- const messages = require ( 'elasticio-node' ) . messages ;
3
+ const { messages } = require ( 'elasticio-node' ) ;
5
4
6
5
/** @this processAction */
7
6
async function processAction ( msg , conf ) {
8
7
const splitting = conf . splitter || { } ;
9
- let body = msg . body || { } ;
8
+ const body = msg . body || { } ;
10
9
11
10
debug ( 'Received new message with body: %j' , body ) ;
12
11
debug ( 'Config: %j' , conf ) ;
@@ -23,22 +22,22 @@ async function processAction(msg, conf) {
23
22
return ;
24
23
}
25
24
26
- if ( _ . isArray ( split ) && _ . find ( split , elem => ! _ . isObject ( elem ) ) ) {
25
+ if ( _ . isArray ( split ) && _ . find ( split , ( elem ) => ! _ . isObject ( elem ) ) ) {
27
26
await this . emit ( 'error' , new Error ( 'Splitting arrays of objects only!' ) ) ;
28
27
return ;
29
28
}
30
29
31
30
const result = [ ] ;
32
31
33
32
if ( _ . isArray ( split ) ) {
34
- split . forEach ( elem => result . push ( elem ) ) ;
33
+ split . forEach ( ( elem ) => result . push ( elem ) ) ;
35
34
} else if ( _ . isObject ( split ) ) {
36
35
debug ( `"${ splitting } " is not an array. Returning the original object` ) ;
37
36
result . push ( split ) ;
38
37
}
39
38
40
39
debug ( '%s parts to emit found' , result . length ) ;
41
- for ( let value of result ) {
40
+ for ( const value of result ) {
42
41
if ( value ) {
43
42
await this . emit ( 'data' , messages . newMessageWithBody ( value ) ) ;
44
43
}
0 commit comments