Skip to content

Commit 84f75af

Browse files
committed
Use ESM
1 parent acec11e commit 84f75af

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*.log
22
.DS_Store
3-
.nyc_output/
43
coverage/
54
node_modules/
65
yarn.lock

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
coverage/
2-
*.json
32
*.md

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict'
1+
import {parse} from 'space-separated-tokens'
22

3-
var spaceSeparatedTokens = require('space-separated-tokens')
4-
5-
module.exports = classnames
3+
var own = {}.hasOwnProperty
64

75
// A bit inspired by <https://github.com/JedWatson/classnames>, but for hast.
8-
function classnames(node) {
6+
export function classnames(node) {
97
var map = Object.create(null)
108
var list = []
119
var mutate = node && typeof node === 'object' && 'type' in node
@@ -42,7 +40,7 @@ function add(result, conditional) {
4240
if (typeof conditional === 'number') {
4341
result[conditional] = true
4442
} else if (typeof conditional === 'string') {
45-
conditional = spaceSeparatedTokens.parse(conditional)
43+
conditional = parse(conditional)
4644

4745
while (++index < conditional.length) {
4846
result[conditional[index]] = true
@@ -54,7 +52,9 @@ function add(result, conditional) {
5452
}
5553
} else {
5654
for (key in conditional) {
57-
result[key] = conditional[key]
55+
if (own.call(conditional, key)) {
56+
result[key] = conditional[key]
57+
}
5858
}
5959
}
6060
}

package.json

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,31 @@
2424
"contributors": [
2525
"Titus Wormer <[email protected]> (https://wooorm.com)"
2626
],
27+
"sideEffects": false,
28+
"type": "module",
29+
"main": "index.js",
2730
"files": [
2831
"index.js"
2932
],
3033
"dependencies": {
31-
"space-separated-tokens": "^1.0.0"
34+
"space-separated-tokens": "^2.0.0"
3235
},
3336
"devDependencies": {
34-
"hastscript": "^6.0.0",
35-
"nyc": "^15.0.0",
37+
"c8": "^7.0.0",
38+
"hastscript": "^7.0.0",
3639
"prettier": "^2.0.0",
3740
"remark-cli": "^9.0.0",
3841
"remark-preset-wooorm": "^8.0.0",
3942
"tape": "^5.0.0",
40-
"unist-builder": "^2.0.0",
41-
"xo": "^0.38.0"
43+
"unist-builder": "^3.0.0",
44+
"xo": "^0.39.0"
4245
},
4346
"scripts": {
4447
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
45-
"test-api": "node test",
46-
"test-coverage": "nyc --reporter lcov tape test.js",
48+
"test-api": "node test.js",
49+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
4750
"test": "npm run format && npm run test-coverage"
4851
},
49-
"nyc": {
50-
"check-coverage": true,
51-
"lines": 100,
52-
"functions": 100,
53-
"branches": 100
54-
},
5552
"prettier": {
5653
"tabWidth": 2,
5754
"useTabs": false,
@@ -62,13 +59,10 @@
6259
},
6360
"xo": {
6461
"prettier": true,
65-
"esnext": false,
6662
"rules": {
67-
"guard-for-in": "off"
68-
},
69-
"ignores": [
70-
"hast-util-classnames.js"
71-
]
63+
"no-var": "off",
64+
"prefer-arrow-callback": "off"
65+
}
7266
},
7367
"remarkConfig": {
7468
"plugins": [

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
## Install
1414

15+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
16+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
17+
1518
[npm][]:
1619

1720
```sh
@@ -21,8 +24,8 @@ npm install hast-util-classnames
2124
## Use
2225

2326
```js
24-
var h = require('hastscript')
25-
var classnames = require('hast-util-classnames')
27+
import {h} from 'hastscript'
28+
import {classnames} from 'hast-util-classnames'
2629

2730
console.log(classnames('alpha bravo', {bravo: false}, [123, 'charlie']))
2831

@@ -44,6 +47,9 @@ Yields:
4447

4548
## API
4649

50+
This package exports the following identifiers: `classnames`.
51+
There is no default export.
52+
4753
### `classnames(node, …conditionals)`
4854

4955
Utility to merge classes.

test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var u = require('unist-builder')
5-
var h = require('hastscript')
6-
var classnames = require('.')
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {h} from 'hastscript'
4+
import {classnames} from './index.js'
75

86
test('hast-util-classnames', function (t) {
97
t.throws(

0 commit comments

Comments
 (0)