
Company News
Socket Joins the OpenJS Foundation
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.
@frankhoodbs/data-attributes-utils
Advanced tools
A simple JavaScript utility to fetch and parse data attributes from HTML elements. Perfect for modern web development, this utility helps you easily extract custom data attributes and converts them to their respective JavaScript types where possible.
Via NPM:
npm install @frankhoodbs/data-attributes-utils
Here's a basic example on how to use the getDataAttributes utility:
import { getDataAttributes } from '@frankhoodbs/data-attributes-utils';
const element = document.querySelector('.your-element-class');
const dataAttributes = getDataAttributes(element);
console.log(dataAttributes);
The function will retrieve all data attributes from the provided HTML element and return them as a parsed JavaScript object. If a data attribute contains a stringified JSON, the utility will automatically parse it into its appropriate JS type.
el: The HTML element from which you want to retrieve the data attributes.Returns a JavaScript object containing the data attributes and their parsed values.
Given the following HTML:
<div
class="example"
data-name="John Doe"
data-age='30'
data-hobbies='["reading", "cycling"]'
>
Example Element
</div>
And the usage:
const element = document.querySelector('.example');
const dataAttributes = getDataAttributes(element);
console.log(dataAttributes);
This will output:
{
name: "John Doe",
age: "30",
hobbies: ["reading", "cycling"]
}
FAQs
An set of utilities to deal with data attributes
We found that @frankhoodbs/data-attributes-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

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.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.