Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 26, 2021
1 parent d58808e commit f2d9f78
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
strategy:
matrix:
node:
- lts/dubnium
- lts/erbium
- node
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.DS_Store
*.log
coverage/
node_modules/
html-void-elements.js
html-void-elements.min.js
yarn.lock
4 changes: 0 additions & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
.nyc_output/
coverage/
*.md
*.json
html-void-elements.js
html-void-elements.min.js
32 changes: 18 additions & 14 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict'

var fs = require('fs')
var https = require('https')
var concat = require('concat-stream')
var unified = require('unified')
var html = require('rehype-parse')
var q = require('hast-util-select')
var toString = require('hast-util-to-string')
var bail = require('bail')
var list = require('.')
import fs from 'fs'
import https from 'https'
import concat from 'concat-stream'
import unified from 'unified'
import html from 'rehype-parse'
import q from 'hast-util-select'
import toString from 'hast-util-to-string'
import {bail} from 'bail'
import {htmlVoidElements} from './index.js'

var proc = unified().use(html)

Expand All @@ -27,10 +25,16 @@ function onconcat(buf) {
while (++index < nodes.length) {
value = toString(nodes[index])

if (value && !/\s/.test(value) && !list.includes(value)) {
list.push(value)
if (value && !/\s/.test(value) && !htmlVoidElements.includes(value)) {
htmlVoidElements.push(value)
}
}

fs.writeFile('index.json', JSON.stringify(list.sort(), 0, 2) + '\n', bail)
fs.writeFile(
'index.js',
'export var htmlVoidElements = ' +
JSON.stringify(htmlVoidElements.sort(), null, 2) +
'\n',
bail
)
}
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export var htmlVoidElements = [
'area',
'base',
'basefont',
'bgsound',
'br',
'col',
'command',
'embed',
'frame',
'hr',
'image',
'img',
'input',
'isindex',
'keygen',
'link',
'menuitem',
'meta',
'nextid',
'param',
'source',
'track',
'wbr'
]
25 changes: 0 additions & 25 deletions index.json

This file was deleted.

29 changes: 13 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"main": "index.json",
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.json"
"index.js"
],
"devDependencies": {
"bail": "^1.0.0",
"browserify": "^17.0.0",
"bail": "^2.0.0",
"c8": "^7.0.0",
"concat-stream": "^2.0.0",
"hast-util-select": "^4.0.0",
"hast-util-to-string": "^1.0.0",
Expand All @@ -38,18 +40,15 @@
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"unified": "^9.0.0",
"xo": "^0.38.0"
},
"scripts": {
"generate": "node build",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s htmlVoidElements -o html-void-elements.js",
"build-mangle": "browserify . -s htmlVoidElements -p tinyify -o html-void-elements.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test": "npm run format && npm run build && npm run test-api"
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -61,13 +60,11 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"unicorn/no-array-callback-reference": "off"
},
"ignores": [
"html-void-elements.min.js"
]
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
25 changes: 17 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# html-void-elements

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]

List of known void HTML elements.
Includes ancient (such as `nextid` and `basefont`) and modern (such as `img` and
`meta`) tag names from the HTML living standard.

**Note**: there’s one special case: `menuitem`.
W3C specifies it to be void, but WHATWG doesn’t.
I suggest using the void form.

## Install

This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.

[npm][]:

```sh
Expand All @@ -23,15 +23,16 @@ npm install html-void-elements
## Use

```js
var htmlVoidElements = require('html-void-elements')
import {htmlVoidElements} from 'html-void-elements'

console.log(htmlVoidElements)
```

Yields:

```js
[ 'area',
[
'area',
'base',
'basefont',
'bgsound',
Expand All @@ -53,14 +54,18 @@ Yields:
'param',
'source',
'track',
'wbr' ]
'wbr'
]
```

## API

This package exports the following identifiers: `htmlVoidElements`.
There is no default export.

### `htmlVoidElements`

`Array.<string>` — List of lower-case tag names.
`string[]` — List of lowercase tag names.

## License

Expand All @@ -72,6 +77,10 @@ Yields:

[build]: https://github.com/wooorm/html-void-elements/actions

[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/html-void-elements.svg

[coverage]: https://codecov.io/github/wooorm/html-void-elements

[downloads-badge]: https://img.shields.io/npm/dm/html-void-elements.svg

[downloads]: https://www.npmjs.com/package/html-void-elements
Expand Down
6 changes: 2 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

var test = require('tape')
var htmlVoidElements = require('.')
import test from 'tape'
import {htmlVoidElements} from './index.js'

test('htmlVoidElements', function (t) {
var index = -1
Expand Down

0 comments on commit f2d9f78

Please sign in to comment.