Passed
Push — master ( 22873c...be0969 )
by Björn
02:06
created

handlebars.registerHelper(ꞌtexthelperꞌ)   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
nc 3
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
nop 1
1 1
var handlebars = require('handlebars');
2 1
var texts = require('../config/texthelper');
3
4
/**
5
 * simple text helper to provide consistent test-data over all patterns
6
 * 
7
 * usage:
8
 * {{#texthelper $mode}}
9
 * 
10
 * provides text samples for
11
 * - text
12
 * - date/time
13
 * - contact info
14
 * - product info
15
 * 
16
 * default mode: short (text)
17
 * 
18
 */
19 1
handlebars.registerHelper('texthelper', function(mode) {
20
	
21 3
	if (typeof mode !== 'string') {
22 1
		return texts['default'];
23
	}
24
	
25 2
	if (typeof texts[mode] === 'undefined') {
26 1
		return mode
27
	}
28
	
29 1
	return String( texts[mode] );
30
31
});
32