New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

get-data-attributes

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-data-attributes

Minimal function that returns an element's data attributes as an object

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

get-data-attributes npm File Size

Minimal function that returns an element's data attributes as an object.

Make sure you escape your attributes if they're not extremely simple.

https://henrygd.me/get-data-attributes

Install

$ npm install get-data-attributes

Usage

import getDataAttributes from 'get-data-attributes'
<div
	id="example"
	data-example="one"
	data-my-string="it is a string"
	data-my-array='["one", true, 3]'
	data-my-object='{"The Last of Us": 10, "The Last of Us Part II": 10, "10 of 10 games": ["The Last of Us", "The Last of Us Part II"]}'
></div>
let data = getDataAttributes(document.getElementById('example'))

// data will be this
{
  example: "one",
  myString: "it is a string",
  myArray: [
    "one",
    true,
    3
  ],
  myObject: {
    "The Last of Us": 10,
    "The Last of Us Part II": 10,
    "10 of 10 games": [
      "The Last of Us",
      "The Last of Us Part II"
    ]
  }
}

License

MIT

FAQs

Package last updated on 28 Sep 2021

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