Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

attrobj

Package Overview
Dependencies
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attrobj

Creates an object based on element attributes

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
549
decreased by-21.23%
Maintainers
6
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 26 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc