dataset-transpiler
raw JSON → 0.1.2 verified Fri May 01 auth: no javascript deprecated
A JavaScript utility that transforms `.dataset.X` property access into equivalent `getAttribute('data-X')` and `setAttribute('data-X', value)` calls for backward compatibility with older browsers. Version 0.1.2 (last released Jan 2015) fixes simple setters/getters; nested `.dataset` calls remain unsupported. This package is a relic of the pre-standard `HTMLElement.dataset` era and is superseded by native browser support. It has no active maintenance and is only useful for legacy project archaeology.
Common errors
error Cannot find module 'dataset-transpiler' ↓
cause Package uses ES module format; CommonJS require fails.
fix
Use ES import syntax: import x from 'dataset-transpiler'
error TypeError: transpile is not a function ↓
cause Attempted to use a named export that does not exist.
fix
Use default import: import transpile from 'dataset-transpiler'
error ReferenceError: element is not defined ↓
cause The transpiler does not validate inputs; expects valid JS string.
fix
Ensure input is a string containing valid JavaScript with .dataset usage.
Warnings
breaking Nested .dataset calls are not transpiled (e.g. element.dataset.foo.bar) ↓
fix Manually rewrite nested accesses or avoid using them.
deprecated Package is unmaintained since 2015; modern browsers support HTMLElement.dataset natively. ↓
fix Remove dependency and use element.dataset directly for modern browsers (IE11+).
gotcha runtimePrefix option fixed in 0.1.1 but still case-sensitive; wrong casing silently produces incorrect output. ↓
fix Ensure runtimePrefix matches exactly (camelCase).
Install
npm install dataset-transpiler yarn add dataset-transpiler pnpm add dataset-transpiler Imports
- transpile wrong
const datasetTranspiler = require('dataset-transpiler')correctimport { transpile } from 'dataset-transpiler' - default wrong
import { transpile } from 'dataset-transpiler'correctimport transpile from 'dataset-transpiler' - runtimePrefix wrong
transpile('element.dataset.foo', { runtimePrefix: 'myapp' })correcttranspile('element.dataset.foo', { runtimePrefix: 'myApp' })
Quickstart
import transpile from 'dataset-transpiler';
const input = `element.dataset.foo = 'bar';
const x = element.dataset.baz;`;
const output = transpile(input);
console.log(output);
// Output:
// element.setAttribute('data-foo', 'bar');
// const x = element.getAttribute('data-baz');