src/help/getOptionsFromElement.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 5

Size

Lines of Code 28
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
B getOptionsFromElement.js ➔ getOptionsFromElement 0 23 5
1
import optionsFromStrings from "./optionsFromStrings.js";
2
import defaults from "../options/defaults.js";
3
4
function getOptionsFromElement(element){
5
	var options = {};
6
	for(var property in defaults){
7
		if(defaults.hasOwnProperty(property)){
8
			// jsbarcode-*
9
			if(element.hasAttribute("jsbarcode-" + property.toLowerCase())){
10
				options[property] = element.getAttribute("jsbarcode-" + property.toLowerCase());
11
			}
12
13
			// data-*
14
			if(element.hasAttribute("data-" + property.toLowerCase())){
15
				options[property] = element.getAttribute("data-" + property.toLowerCase());
16
			}
17
		}
18
	}
19
20
	options["value"] = element.getAttribute("jsbarcode-value") || element.getAttribute("data-value");
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