# attrobj

> Creates an object based on element attributes

Latest version **3.1.0** (published 2019-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install attrobj
pnpm add attrobj
yarn add attrobj
bun add attrobj
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2019-06-26 |
| First published | 2016-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | First+Third |
| Maintainers | alaguna, aleperez92, dawnerd, ecwillis, jga, orthagonal1 |
| Keywords | attributes, browser, dom |

## Links

- npm: https://www.npmjs.com/package/attrobj
- Repository: https://github.com/firstandthird/attrobj
- Homepage: https://github.com/firstandthird/attrobj#readme
- Issues: https://github.com/firstandthird/attrobj/issues
- npm.io page: https://npm.io/package/attrobj

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2019-06-26
- 3.0.0 — 2019-02-22
- 2.0.0 — 2017-10-10
- 1.2.0 — 2017-02-02
- 1.1.1 — 2017-01-27
- 1.1.0 — 2016-12-23
- 1.0.0 — 2016-12-23

## README

# attrobj

[![Build Status](https://travis-ci.org/firstandthird/attrobj.svg?branch=master)](https://travis-ci.org/firstandthird/attrobj) ![npm](https://img.shields.io/npm/v/attrobj.svg)

Transforms data-attributes into an array based on key.

## Installation

```sh
npm install attrobj
```

## Example usage

```html
<div id="example" data-example-name="Test Name" data-example-color="red"></div>
```

```js
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:

```html
<div id="example2" data-weather-global-rain="rain" data-weather-cloudy="true"></div>
```

```js
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' }
```

---
_Source: https://npm.io/package/attrobj · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
