Skip to content

Commit 8aabe35

Browse files
committed
Refactor code-style
1 parent 0fdf89f commit 8aabe35

File tree

3 files changed

+63
-59
lines changed

3 files changed

+63
-59
lines changed

lib/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/**
2-
* @typedef {import('hast').Root} Root
3-
* @typedef {import('hast').Content} Content
4-
*/
5-
6-
/**
7-
* @typedef {Root | Content} Node
2+
* @typedef {import('hast').Nodes} Nodes
83
*/
94

105
const own = {}.hasOwnProperty
@@ -33,7 +28,7 @@ export function hasProperty(node, field) {
3328

3429
/**
3530
* @param {unknown} value
36-
* @returns {value is Node}
31+
* @returns {value is Nodes}
3732
*/
3833
function isNode(value) {
3934
return Boolean(value && typeof value === 'object' && 'type' in value)

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"index.d.ts",
3434
"index.js"
3535
],
36+
"dependencies": {
37+
"@types/hast": "^3.0.0"
38+
},
3639
"devDependencies": {
3740
"@types/node": "^20.0.0",
3841
"c8": "^8.0.0",

test.js

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,73 @@
11
import assert from 'node:assert/strict'
22
import test from 'node:test'
33
import {hasProperty} from './index.js'
4-
import * as mod from './index.js'
54

6-
test('hasProperty', () => {
7-
assert.deepEqual(
8-
Object.keys(mod).sort(),
9-
['hasProperty'],
10-
'should expose the public api'
11-
)
5+
test('hasProperty', async function (t) {
6+
await t.test('should expose the public api', async function () {
7+
assert.deepEqual(Object.keys(await import('./index.js')).sort(), [
8+
'hasProperty'
9+
])
10+
})
1211

13-
assert.equal(
14-
hasProperty(null, 'alpha'),
15-
false,
16-
'should return `false` without node'
17-
)
12+
await t.test('should return `false` without node', async function () {
13+
assert.equal(hasProperty(null, 'alpha'), false)
14+
})
1815

19-
assert.equal(
20-
hasProperty({type: 'text', value: 'alpha'}, 'bravo'),
21-
false,
22-
'should return `false` without `element`'
23-
)
16+
await t.test('should return `false` without `element`', async function () {
17+
assert.equal(hasProperty({type: 'text', value: 'alpha'}, 'bravo'), false)
18+
})
2419

25-
assert.equal(
26-
hasProperty({type: 'element'}, 'charlie'),
27-
false,
28-
'should return `false` without properties'
29-
)
20+
await t.test('should return `false` without properties', async function () {
21+
assert.equal(hasProperty({type: 'element'}, 'charlie'), false)
22+
})
3023

31-
assert.equal(
32-
hasProperty({type: 'element', properties: {}}, 'toString'),
33-
false,
34-
'should return `false` for prototypal properties'
24+
await t.test(
25+
'should return `false` for prototypal properties',
26+
async function () {
27+
assert.equal(
28+
hasProperty({type: 'element', properties: {}}, 'toString'),
29+
false
30+
)
31+
}
3532
)
3633

37-
assert.equal(
38-
hasProperty(
39-
{
40-
type: 'element',
41-
properties: {id: 'delta'}
42-
},
43-
'echo'
44-
),
45-
false,
46-
'should return `false` if the property does not exist'
34+
await t.test(
35+
'should return `false` if the property does not exist',
36+
async function () {
37+
assert.equal(
38+
hasProperty(
39+
{
40+
type: 'element',
41+
properties: {id: 'delta'}
42+
},
43+
'echo'
44+
),
45+
false
46+
)
47+
}
4748
)
4849

49-
assert.equal(
50-
// @ts-expect-error runtime.
51-
hasProperty({type: 'element', properties: {id: 'delta'}}),
52-
false,
53-
'should return `false` if without `name`'
54-
)
50+
await t.test('should return `false` if without `name`', async function () {
51+
assert.equal(
52+
// @ts-expect-error: check how a missing name is handled.
53+
hasProperty({type: 'element', properties: {id: 'delta'}}),
54+
false
55+
)
56+
})
5557

56-
assert.equal(
57-
hasProperty(
58-
{
59-
type: 'element',
60-
properties: {id: 'delta'}
61-
},
62-
'id'
63-
),
64-
true,
65-
'should return `true` if the property does exist'
58+
await t.test(
59+
'should return `true` if the property does exist',
60+
async function () {
61+
assert.equal(
62+
hasProperty(
63+
{
64+
type: 'element',
65+
properties: {id: 'delta'}
66+
},
67+
'id'
68+
),
69+
true
70+
)
71+
}
6672
)
6773
})

0 commit comments

Comments
 (0)