diff --git a/README.md b/README.md index 1dae87d..ee12827 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,20 @@ is `class` v.s. `className`. With this package, you can do this: ```js -var vnode = h('div', { class: 'my-class' }) +const vnode = h('div', { class: 'my-class' }) ``` Instead of this: ```js -var vnode = h('div', { className: 'my-class' }) +const vnode = h('div', { className: 'my-class' }) ``` Works with [virtual-dom](https://www.npmjs.com/package/virtual-dom), [react](https://www.npmjs.com/package/react), [hyperscript](https://www.npmjs.com/package/hyperscript), or any DOM builder with a hyperscript-style API: `h(tagName, attrs, children)`. ## install -``` +```bash npm install hyperscript-attribute-to-property ``` @@ -39,8 +39,10 @@ npm install hyperscript-attribute-to-property ### example ```js -var attrToProp = require('hyperscript-attribute-to-property') -var h = attrToProp(require('virtual-dom/h')) +import attrToProp from 'hyperscript-attribute-to-property' +import pkg from 'virtual-dom/h.js' + +const h = attrToProp(pkg) ``` ### hyperx diff --git a/index.js b/index.js index 8b757ce..fe2a5d2 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,12 @@ -module.exports = attributeToProperty - -var transform = { +const transform = { class: 'className', for: 'htmlFor', 'http-equiv': 'httpEquiv' } -function attributeToProperty (h) { +export default function attributeToProperty (h) { return function (tagName, attrs, children) { - for (var attr in attrs) { + for (const attr in attrs) { if (attr in transform) { attrs[transform[attr]] = attrs[attr] delete attrs[attr] diff --git a/package.json b/package.json index f9665ab..8820c31 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "hyperscript-attribute-to-property", "description": "Convert hyperscript attributes to properties", "version": "1.0.2", + "type": "module", "author": { "name": "Feross Aboukhadijeh", "email": "feross@feross.org", diff --git a/test/basic.js b/test/basic.js index 0da67a8..2f2f2c5 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,21 +1,23 @@ -var attrToProp = require('../') -var h = attrToProp(require('virtual-dom/h')) -var test = require('tape') +import attrToProp from '../index.js' +import pkg from 'virtual-dom/h.js' +import test from 'tape' + +const h = attrToProp(pkg) test('class -> className', function (t) { - var vnode = h('div', { class: 'value' }) + const vnode = h('div', { class: 'value' }) t.equal(vnode.properties.className, 'value') t.end() }) test('for -> htmlFor', function (t) { - var vnode = h('div', { for: 'value' }) + const vnode = h('div', { for: 'value' }) t.equal(vnode.properties.htmlFor, 'value') t.end() }) test('http-equiv -> httpEquiv', function (t) { - var vnode = h('div', { 'http-equiv': 'value' }) + const vnode = h('div', { 'http-equiv': 'value' }) t.equal(vnode.properties.httpEquiv, 'value') t.end() })