1 | module.exports = function(className, attr) {
|
2 | return Array.from(
|
3 | document.getElementsByClassName(className || 'data')
|
4 | ).reduce(function(data, element) {
|
5 | return (data[
|
6 | element.getAttribute('data-' + (attr || 'attribute'))
|
7 | ] = JSON.parse(
|
8 | element.textContent
|
9 | .replace(/&/g, '&')
|
10 | .replace(/"/g, '"')
|
11 | .replace(/'/g, "'")
|
12 | .replace(/</g, '<')
|
13 | .replace(/>/g, '>')
|
14 | )), data;
|
15 | }, {});
|
16 | };
|