Total Complexity | 5 |
Complexity/F | 5 |
Lines of Code | 28 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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 |