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

get-data-attributes

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


Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created

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