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

getOptionsFromElement.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
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