Skip to content

Commit ff38b3e

Browse files
committed
feat: upgrade typings and behavior, release 2.0
1 parent 14fd1f3 commit ff38b3e

File tree

5 files changed

+49
-41
lines changed

5 files changed

+49
-41
lines changed

.github/workflows/main.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ jobs:
77
name: ${{matrix.node}}
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
11-
- uses: dcodeIO/setup-node-nvm@master
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-node@v3
1212
with:
1313
node-version: ${{matrix.node}}
1414
- run: npm install
1515
- run: npm test
16-
- uses: codecov/codecov-action@v1
16+
- uses: codecov/codecov-action@v3
1717
strategy:
1818
matrix:
1919
node:
20-
- lts/erbium
20+
- lts/gallium
2121
- node

index.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export const slugs = new Slugger()
2323
* enableCustomId?: boolean,
2424
* maintainCase?: boolean,
2525
* removeAccents?: boolean
26-
* }} props
26+
* }} properties
2727
*/
28-
export function getHeaderNodeId(node, props = {}) {
28+
export function getHeaderNodeId(node, properties = {}) {
2929
const {
3030
enableCustomId = false,
3131
maintainCase = false,
3232
removeAccents = false
33-
} = props
33+
} = properties
3434

3535
/**
3636
* @type {Node & HTMLElement}
@@ -70,19 +70,25 @@ export function getHeaderNodeId(node, props = {}) {
7070
/**
7171
* Plugin to add `id`s to headings.
7272
*
73-
* @type {import('unified').Plugin<[{
73+
* @param {{
7474
* enableCustomId?: boolean,
7575
* maintainCase?: boolean,
7676
* removeAccents?: boolean
77-
* }], Root>}
77+
* }} properties
7878
*/
79-
export default function rehypeSlug(props = {}) {
79+
export default function rehypeSlug(properties = {}) {
80+
/**
81+
* @param {Root} tree
82+
* Tree.
83+
* @returns {undefined}
84+
* Nothing.
85+
*/
8086
return (tree) => {
8187
slugs.reset()
8288

8389
visit(tree, 'element', (node) => {
8490
if (headingRank(node) && node.properties && !hasProperty(node, 'id')) {
85-
const {id, isCustomId} = getHeaderNodeId(node, props)
91+
const {id, isCustomId} = getHeaderNodeId(node, properties)
8692

8793
if (isCustomId) node.children.pop()
8894
node.properties.id = id

package.json

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rehype-slug-custom-id",
3-
"version": "1.1.0",
3+
"version": "2.0.0",
44
"description": "plugin to add `id` attributes to headings similar to gatsby-remark-autolink-headers ",
55
"license": "MIT",
66
"keywords": [
@@ -24,32 +24,31 @@
2424
"index.js"
2525
],
2626
"dependencies": {
27-
"@types/hast": "^2.0.0",
28-
"github-slugger": "^1.1.1",
29-
"hast-util-has-property": "^2.0.0",
30-
"hast-util-heading-rank": "^2.0.0",
31-
"hast-util-to-string": "^2.0.0",
27+
"@types/hast": "^3.0.4",
28+
"github-slugger": "^2.0.0",
29+
"hast-util-has-property": "^3.0.0",
30+
"hast-util-heading-rank": "^3.0.0",
31+
"hast-util-to-string": "^3.0.0",
3232
"lodash": "^4.17.21",
33-
"unified": "^10.0.0",
34-
"unist-util-visit": "^4.0.0"
33+
"unified": "^11.0.5",
34+
"unist-util-visit": "^5.0.0"
3535
},
3636
"devDependencies": {
37-
"@types/github-slugger": "^1.0.0",
3837
"@types/lodash": "^4.14.177",
39-
"@types/tape": "^4.0.0",
40-
"c8": "^7.0.0",
41-
"prettier": "^2.0.0",
42-
"rehype": "^12.0.0",
43-
"remark-cli": "^10.0.0",
44-
"remark-preset-wooorm": "^9.0.0",
45-
"rimraf": "^3.0.0",
38+
"@types/tape": "^5.6.4",
39+
"c8": "^10.1.2",
40+
"prettier": "^3.3.2",
41+
"rehype": "^13.0.1",
42+
"remark-cli": "^12.0.1",
43+
"remark-preset-wooorm": "^10.0.0",
44+
"rimraf": "^5.0.7",
4645
"tape": "^5.0.0",
4746
"type-coverage": "^2.0.0",
48-
"typescript": "^4.0.0",
49-
"xo": "^0.44.0"
47+
"typescript": "^5.5.2",
48+
"xo": "^0.58.0"
5049
},
5150
"scripts": {
52-
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
51+
"build": "rimraf --glob \"*.d.ts\" && tsc && type-coverage",
5352
"format": "remark . -qo && prettier . -w --loglevel warn && xo --fix",
5453
"test-api": "node --conditions development test.js",
5554
"test-coverage": "c8 --check-coverage --branches 80 --functions 90 --lines 90 --statements 90 --reporter lcov npm run test-api",
@@ -64,7 +63,10 @@
6463
"trailingComma": "none"
6564
},
6665
"xo": {
67-
"prettier": true
66+
"prettier": true,
67+
"rules": {
68+
"unicorn/prefer-at": "off"
69+
}
6870
},
6971
"remarkConfig": {
7072
"plugins": [

readme.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ Uses [**github-slugger**][ghslug] to create GitHub style `id`s, or a custom ID i
7676

7777
We support the following options for the plugin:
7878

79-
* `enableCustomId`: `Boolean`. Enable custom header IDs with {#id} (optional)
80-
* `maintainCase`: `Boolean`. Maintains the case for markdown header (optional)
81-
* `removeAccents`: `Boolean`. Remove accents from generated headings IDs (optional)
79+
* `enableCustomId`: `Boolean`. Enable custom header IDs with {#id} (optional)
80+
* `maintainCase`: `Boolean`. Maintains the case for markdown header (optional)
81+
* `removeAccents`: `Boolean`. Remove accents from generated headings IDs (optional)
8282

8383
## Security
8484

@@ -92,12 +92,12 @@ Always be wary with user input and use [`rehype-sanitize`][sanitize].
9292

9393
## Related
9494

95-
* [`rehype-slug`](https://github.com/rehypejs/rehype-slug)
96-
— Add slugs to headings in html
97-
* [`remark-slug`](https://github.com/wooorm/remark-slug)
98-
— Add slugs to headings in markdown
99-
* [`gatsby-remark-autolink-headers`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-autolink-headers)
100-
— Add slugs to headings in markdown for Gatsby
95+
* [`rehype-slug`](https://github.com/rehypejs/rehype-slug)
96+
— Add slugs to headings in html
97+
* [`remark-slug`](https://github.com/wooorm/remark-slug)
98+
— Add slugs to headings in markdown
99+
* [`gatsby-remark-autolink-headers`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-autolink-headers)
100+
— Add slugs to headings in markdown for Gatsby
101101

102102
<!-- Definitions -->
103103

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"include": ["*.js"],
33
"compilerOptions": {
44
"target": "ES2020",
5-
"lib": ["ES2020", "DOM"],
5+
"lib": ["ES2020", "DOM", "ES2020.String"],
66
"module": "ES2020",
77
"moduleResolution": "node",
88
"allowJs": true,

0 commit comments

Comments
 (0)