Completed
Pull Request — master (#107)
by Johan
01:12
created

src/help/getOptionsFromElement.js   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 28
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 28
rs 10
c 4
b 1
f 0
wmc 4
mnd 2
bc 3
fnc 2
bpm 1.5
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B getOptionsFromElement.js ➔ getOptionsFromElement 0 24 3
1
import optionsFromStrings from "./optionsFromStrings.js";
2
3
function getOptionsFromElement(element){
4
	var options = {};
5
6
	var attributes = element.attributes;
7
	for(var i = 0; i < attributes.length; i++){
8
		var name = attributes[i].name;
9
		var value = attributes[i].value;
10
11
		var match = name.match(/(jsbarcode|data)-([A-Za-z0-9-]+)/i);
12
		if(match){
13
			var property = match[2];
14
15
			// Transforms foo-bar to fooBar
16
			property = property.replace(/-[a-zA-Z]/, (val) => val[1].toUpperCase());
17
18
			options[property] = value;
19
		}
20
	}
21
22
	// Since all atributes are string they need to be converted to integers
23
	options = optionsFromStrings(options);
24
25
	return options;
26
}
27
28
export default getOptionsFromElement;
29