Skip to content

Commit f2d9f78

Browse files
committed
Use ESM
1 parent d58808e commit f2d9f78

File tree

9 files changed

+77
-74
lines changed

9 files changed

+77
-74
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
strategy:
1818
matrix:
1919
node:
20-
- lts/dubnium
20+
- lts/erbium
2121
- node

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.DS_Store
22
*.log
3+
coverage/
34
node_modules/
4-
html-void-elements.js
5-
html-void-elements.min.js
65
yarn.lock

.prettierignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
.nyc_output/
21
coverage/
32
*.md
4-
*.json
5-
html-void-elements.js
6-
html-void-elements.min.js

build.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
'use strict'
2-
3-
var fs = require('fs')
4-
var https = require('https')
5-
var concat = require('concat-stream')
6-
var unified = require('unified')
7-
var html = require('rehype-parse')
8-
var q = require('hast-util-select')
9-
var toString = require('hast-util-to-string')
10-
var bail = require('bail')
11-
var list = require('.')
1+
import fs from 'fs'
2+
import https from 'https'
3+
import concat from 'concat-stream'
4+
import unified from 'unified'
5+
import html from 'rehype-parse'
6+
import q from 'hast-util-select'
7+
import toString from 'hast-util-to-string'
8+
import {bail} from 'bail'
9+
import {htmlVoidElements} from './index.js'
1210

1311
var proc = unified().use(html)
1412

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

30-
if (value && !/\s/.test(value) && !list.includes(value)) {
31-
list.push(value)
28+
if (value && !/\s/.test(value) && !htmlVoidElements.includes(value)) {
29+
htmlVoidElements.push(value)
3230
}
3331
}
3432

35-
fs.writeFile('index.json', JSON.stringify(list.sort(), 0, 2) + '\n', bail)
33+
fs.writeFile(
34+
'index.js',
35+
'export var htmlVoidElements = ' +
36+
JSON.stringify(htmlVoidElements.sort(), null, 2) +
37+
'\n',
38+
bail
39+
)
3640
}

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export var htmlVoidElements = [
2+
'area',
3+
'base',
4+
'basefont',
5+
'bgsound',
6+
'br',
7+
'col',
8+
'command',
9+
'embed',
10+
'frame',
11+
'hr',
12+
'image',
13+
'img',
14+
'input',
15+
'isindex',
16+
'keygen',
17+
'link',
18+
'menuitem',
19+
'meta',
20+
'nextid',
21+
'param',
22+
'source',
23+
'track',
24+
'wbr'
25+
]

index.json

Lines changed: 0 additions & 25 deletions
This file was deleted.

package.json

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
"contributors": [
2424
"Titus Wormer <[email protected]> (https://wooorm.com)"
2525
],
26-
"main": "index.json",
26+
"sideEffects": false,
27+
"type": "module",
28+
"main": "index.js",
2729
"files": [
28-
"index.json"
30+
"index.js"
2931
],
3032
"devDependencies": {
31-
"bail": "^1.0.0",
32-
"browserify": "^17.0.0",
33+
"bail": "^2.0.0",
34+
"c8": "^7.0.0",
3335
"concat-stream": "^2.0.0",
3436
"hast-util-select": "^4.0.0",
3537
"hast-util-to-string": "^1.0.0",
@@ -38,18 +40,15 @@
3840
"remark-cli": "^9.0.0",
3941
"remark-preset-wooorm": "^8.0.0",
4042
"tape": "^5.0.0",
41-
"tinyify": "^3.0.0",
4243
"unified": "^9.0.0",
4344
"xo": "^0.38.0"
4445
},
4546
"scripts": {
4647
"generate": "node build",
4748
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
48-
"build-bundle": "browserify . -s htmlVoidElements -o html-void-elements.js",
49-
"build-mangle": "browserify . -s htmlVoidElements -p tinyify -o html-void-elements.min.js",
50-
"build": "npm run build-bundle && npm run build-mangle",
51-
"test-api": "node test",
52-
"test": "npm run format && npm run build && npm run test-api"
49+
"test-api": "node test.js",
50+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
51+
"test": "npm run format && npm run test-coverage"
5352
},
5453
"prettier": {
5554
"tabWidth": 2,
@@ -61,13 +60,11 @@
6160
},
6261
"xo": {
6362
"prettier": true,
64-
"esnext": false,
6563
"rules": {
66-
"unicorn/no-array-callback-reference": "off"
67-
},
68-
"ignores": [
69-
"html-void-elements.min.js"
70-
]
64+
"import/no-mutable-exports": "off",
65+
"no-var": "off",
66+
"prefer-arrow-callback": "off"
67+
}
7168
},
7269
"remarkConfig": {
7370
"plugins": [

readme.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# html-void-elements
22

33
[![Build][build-badge]][build]
4+
[![Coverage][coverage-badge]][coverage]
45
[![Downloads][downloads-badge]][downloads]
56
[![Size][size-badge]][size]
67

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

11-
**Note**: there’s one special case: `menuitem`.
12-
W3C specifies it to be void, but WHATWG doesn’t.
13-
I suggest using the void form.
14-
1512
## Install
1613

14+
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
15+
instead of `require`d.
16+
1717
[npm][]:
1818

1919
```sh
@@ -23,15 +23,16 @@ npm install html-void-elements
2323
## Use
2424

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

2828
console.log(htmlVoidElements)
2929
```
3030

3131
Yields:
3232

3333
```js
34-
[ 'area',
34+
[
35+
'area',
3536
'base',
3637
'basefont',
3738
'bgsound',
@@ -53,14 +54,18 @@ Yields:
5354
'param',
5455
'source',
5556
'track',
56-
'wbr' ]
57+
'wbr'
58+
]
5759
```
5860

5961
## API
6062

63+
This package exports the following identifiers: `htmlVoidElements`.
64+
There is no default export.
65+
6166
### `htmlVoidElements`
6267

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

6570
## License
6671

@@ -72,6 +77,10 @@ Yields:
7277

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

80+
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/html-void-elements.svg
81+
82+
[coverage]: https://codecov.io/github/wooorm/html-void-elements
83+
7584
[downloads-badge]: https://img.shields.io/npm/dm/html-void-elements.svg
7685

7786
[downloads]: https://www.npmjs.com/package/html-void-elements

test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var htmlVoidElements = require('.')
1+
import test from 'tape'
2+
import {htmlVoidElements} from './index.js'
53

64
test('htmlVoidElements', function (t) {
75
var index = -1

0 commit comments

Comments
 (0)