Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: syntax-tree/hast-util-heading
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.0.1
Choose a base ref
...
head repository: syntax-tree/hast-util-heading
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.0.0
Choose a head ref
  • 10 commits
  • 7 files changed
  • 1 contributor

Commits on Jan 16, 2023

  1. Use Node 16 in Actions

    Signed-off-by: Titus <[email protected]>
    wooorm authored Jan 16, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    66b9e38 View commit details

Commits on Aug 1, 2023

  1. Update dev-dependencies

    wooorm committed Aug 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    a85ad8a View commit details
  2. Update @types/hast, utilities

    wooorm committed Aug 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    431dd4c View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    6e18c98 View commit details
  4. Refactor .npmrc

    wooorm committed Aug 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    7a51a9f View commit details
  5. Refactor code-style

    wooorm committed Aug 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    422cabe View commit details
  6. Refactor docs

    wooorm committed Aug 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    d2f17c9 View commit details
  7. Change to use exports

    wooorm committed Aug 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    899b69c View commit details
  8. Change to require Node.js 16

    wooorm committed Aug 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    4dcbc35 View commit details
  9. 3.0.0

    wooorm committed Aug 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    1967314 View commit details
Showing with 100 additions and 91 deletions.
  1. +1 −1 .github/workflows/main.yml
  2. +1 −1 .npmrc
  3. +11 −15 lib/index.js
  4. +20 −20 package.json
  5. +14 −10 readme.md
  6. +47 −36 test.js
  7. +6 −8 tsconfig.json
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -17,5 +17,5 @@ jobs:
strategy:
matrix:
node:
- lts/hydrogen
- lts/gallium
- node
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package-lock=false
ignore-scripts=true
package-lock=false
26 changes: 11 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/**
* @typedef {import('hast').Element} Element
*/

import {convertElement} from 'hast-util-is-element'

const names = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hgroup'])

/**
* Check if the given value is a *heading content* element.
*
* @type {import('hast-util-is-element').AssertPredicate<Element & {tagName: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'hgroup'}>}
* @param node
* Thing to check (typically `Node`).
* @returns
@@ -16,13 +13,12 @@ import {convertElement} from 'hast-util-is-element'
* The elements `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, and `hgroup` are
* heading content.
*/
// @ts-expect-error Sure, the assertion matches.
export const heading = convertElement([
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'hgroup'
])
export const heading = convertElement(
/**
* @param element
* @returns {element is {tagName: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'hgroup'}}
*/
function (element) {
return names.has(element.tagName)
}
)
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hast-util-heading",
"version": "2.0.1",
"version": "3.0.0",
"description": "hast utility to check if a node is a heading element",
"license": "MIT",
"keywords": [
@@ -25,54 +25,54 @@
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/hast": "^2.0.0",
"hast-util-is-element": "^2.0.0"
"@types/hast": "^3.0.0",
"hast-util-is-element": "^3.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"xo": "^0.55.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true
}
}
24 changes: 14 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ looking for!
## Install

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

```sh
npm install hast-util-heading
@@ -41,14 +41,14 @@ npm install hast-util-heading
In Deno with [`esm.sh`][esmsh]:

```js
import {heading} from 'https://esm.sh/hast-util-heading@2'
import {heading} from 'https://esm.sh/hast-util-heading@3'
```

In browsers with [`esm.sh`][esmsh]:

```html
<script type="module">
import {heading} from 'https://esm.sh/hast-util-heading@2?bundle'
import {heading} from 'https://esm.sh/hast-util-heading@3?bundle'
</script>
```

@@ -69,13 +69,14 @@ heading({
heading({
type: 'element',
tagName: 'h1',
properties: {},
children: [{type: 'text', value: 'Delta'}]
}) // => true
```

## API

This package exports the identifier [`heading`][heading].
This package exports the identifier [`heading`][api-heading].
There is no default export.

### `heading(value)`
@@ -101,10 +102,13 @@ It exports no additional types.

## Compatibility

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
Our projects sometimes work with older versions, but this is not guaranteed.

When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `hast-util-heading@^3`,
compatible with Node.js 16.

## Security

@@ -176,9 +180,9 @@ abide by its terms.

[downloads]: https://www.npmjs.com/package/hast-util-heading

[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-heading.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-heading

[size]: https://bundlephobia.com/result?p=hast-util-heading
[size]: https://bundlejs.com/?q=hast-util-heading

[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

@@ -218,4 +222,4 @@ abide by its terms.

[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

[heading]: #headingvalue
[api-heading]: #headingvalue
83 changes: 47 additions & 36 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,60 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import {heading} from './index.js'
import * as mod from './index.js'
import {heading} from 'hast-util-heading'

test('heading', () => {
assert.deepEqual(
Object.keys(mod).sort(),
['heading'],
'should expose the public api'
)
test('heading', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('hast-util-heading')).sort(), [
'heading'
])
})

assert.equal(heading(), false, 'should return `false` without node')
await t.test('should return `false` without node', async function () {
// @ts-expect-error: check how a missing `node` is handled.
assert.equal(heading(), false)
})

assert.equal(heading(null), false, 'should return `false` with `null`')
await t.test('should return `false` with `null`', async function () {
assert.equal(heading(null), false)
})

assert.equal(
heading({type: 'text'}),
false,
'should return `false` when without `element`'
await t.test(
'should return `false` when without `element`',
async function () {
assert.equal(heading({type: 'text'}), false)
}
)

assert.equal(
heading({type: 'element'}),
false,
'should return `false` when with invalid `element`'
await t.test(
'should return `false` when with invalid `element`',
async function () {
assert.equal(heading({type: 'element'}), false)
}
)

assert.equal(
heading({
type: 'element',
tagName: 'a',
properties: {href: '#alpha', title: 'Bravo'},
children: [{type: 'text', value: 'Charlie'}]
}),
false,
'should return `false` when without not heading'
await t.test(
'should return `false` when without not heading',
async function () {
assert.equal(
heading({
type: 'element',
tagName: 'a',
properties: {href: '#alpha', title: 'Bravo'},
children: [{type: 'text', value: 'Charlie'}]
}),
false
)
}
)

assert.equal(
heading({
type: 'element',
tagName: 'h1',
children: [{type: 'text', value: 'Delta'}]
}),
true,
'should return `true` when with heading'
)
await t.test('should return `true` when with heading', async function () {
assert.equal(
heading({
type: 'element',
tagName: 'h1',
children: [{type: 'text', value: 'Delta'}]
}),
true
)
})
})
14 changes: 6 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"include": ["**/**.js"],
"exclude": ["coverage/", "node_modules/"],
"compilerOptions": {
"checkJs": true,
"customConditions": ["development"],
"declaration": true,
"emitDeclarationOnly": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2020"],
"lib": ["es2022"],
"module": "node16",
"newLine": "lf",
"skipLibCheck": true,
"strict": true,
"target": "es2020"
}
"target": "es2022"
},
"exclude": ["coverage/", "node_modules/"],
"include": ["**/*.js"]
}