Skip to content

Commit

Permalink
Add JSDoc based types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 26, 2021
1 parent f84811c commit 5d69c7f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
*.d.ts
*.log
coverage/
node_modules/
Expand Down
19 changes: 18 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import fs from 'fs'
import https from 'https'
import concat from 'concat-stream'
import bail from 'bail'
import {bail} from 'bail'
import unified from 'unified'
import html from 'rehype-parse'
// @ts-ignore
import select from 'hast-util-select'
// @ts-ignore
import toString from 'hast-util-to-string'
import {htmlTagNames} from './index.js'

Expand All @@ -18,12 +20,19 @@ https.get('https://w3c.github.io/elements-of-html/', onw3c)
// Crawl WHATWG.
https.get('https://html.spec.whatwg.org/multipage/indices.html', onwhatwg)

/**
* @param {import('http').IncomingMessage} response
*/
function onw3c(response) {
response.pipe(concat(onconcat)).on('error', bail)

/**
* @param {Buffer} buf
*/
function onconcat(buf) {
var nodes = select.selectAll('[scope="row"] code', proc.parse(buf))
var index = -1
/** @type {string} */
var data

while (++index < nodes.length) {
Expand All @@ -38,13 +47,21 @@ function onw3c(response) {
}
}

/**
* @param {import('http').IncomingMessage} response
*/
function onwhatwg(response) {
response.pipe(concat(onconcat)).on('error', bail)

/**
* @param {Buffer} buf
*/
function onconcat(buf) {
var nodes = select.selectAll('tbody th code', proc.parse(buf))
var index = -1
/** @type {string?} */
var id
/** @type {string} */
var data

while (++index < nodes.length) {
Expand Down
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"devDependencies": {
"bail": "^1.0.0",
"@types/concat-stream": "^1.0.0",
"@types/node": "^14.0.0",
"@types/tape": "^4.0.0",
"bail": "^2.0.0",
"c8": "^7.0.0",
"concat-stream": "^2.0.0",
"hast-util-select": "^4.0.0",
Expand All @@ -39,16 +44,21 @@
"rehype-parse": "^7.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unified": "^9.0.0",
"xo": "^0.38.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"generate": "node build",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -70,5 +80,10 @@
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"files": ["index.js"],
"include": ["*.js"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
}
}

0 comments on commit 5d69c7f

Please sign in to comment.