3.1.0 • Published 5 years ago

attrobj v3.1.0

Weekly downloads
136
License
MIT
Repository
github
Last release
5 years ago

attrobj

Build Status npm

Transforms data-attributes into an array based on key.

Installation

npm install attrobj

Example usage

<div id="example" data-example-name="Test Name" data-example-color="red"></div>
const attrobj = require('attrobj');
const el = document.getElementById('example');

const exampleData = attrobj('example', el);

console.log(exampleData);
// { name: 'Test Name', color: 'red' }

Global Values

Data can be pulled from window.* by using data-<somekey>-global-<valuename>.

Example:

<div id="example2" data-weather-global-rain="rain" data-weather-cloudy="true"></div>
window.rain = '2.1';

const attrobj = require('attrobj');
const el = document.getElementById('example2');

const exampleData = attrobj('weather', el);

console.log(exampleData);
// { rain: '2,1', cloudy: 'true' }
3.1.0

5 years ago

3.0.0

5 years ago

2.0.0

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago