Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bobylito/data-attrs-to-js
Parse your data attributes as JavaScript objects.
https://github.com/bobylito/data-attrs-to-js
Last synced: 22 days ago
JSON representation
Parse your data attributes as JavaScript objects.
- Host: GitHub
- URL: https://github.com/bobylito/data-attrs-to-js
- Owner: bobylito
- Created: 2015-04-28T13:01:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-28T13:02:54.000Z (over 9 years ago)
- Last Synced: 2024-10-15T17:26:36.348Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 92.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# data-attrs-to-js [![Dependency Status](http://img.shields.io/david/ThankYouMotion/data-attrs-to-js.svg?style=flat-square)](https://david-dm.org/ThankYouMotion/data-attrs-to-js) [![devDependency Status](http://img.shields.io/david/dev/ThankYouMotion/data-attrs-to-js.svg?style=flat-square)](https://david-dm.org/ThankYouMotion/data-attrs-to-js#info=devDependencies)
Parse your [data attributes](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes) as JavaScript objects.
## Usage
```html
``````js
var tojs = require('data-attrs-to-js');
var elem = document.querySelector('dataz');console.log(tojs(elem));
// {
// browser: 'ie6',
// user: {
// id: '9',
// name: 'John'
// },
// awesome: {
// 'colors.red': '#ff0000'
// }
// }console.log(
tojs(elem, {
pattern: /^user/
})
);// {
// user: {
// id: '9',
// name: 'John'
// }
// }console.log(
tojs(elem, {
separator: '.'
})
);// {
// 'user-name': 'John',
// 'user-id': '9',
// browser: 'ie6',
// 'awesome-colors': {
// red: '#ff0000'
// }
// }
```