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 Apr 26, 2021
1 parent 3b95bd2 commit 3f15a3b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 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: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {isElement} from 'hast-util-is-element'
import {convertElement} from 'hast-util-is-element'
import {hasProperty} from 'hast-util-has-property'
import {embedded} from 'hast-util-embedded'
import bodyOkLink from 'hast-util-is-body-ok-link'

var list = [
var basic = convertElement([
'a',
'abbr',
// `area` is in fact only phrasing if it is inside a `map` element.
Expand Down Expand Up @@ -51,14 +51,21 @@ var list = [
'u',
'var',
'wbr'
]
])

var meta = convertElement('meta')

/**
* @param {unknown} node
* @returns {boolean}
*/
export function phrasing(node) {
return (
node.type === 'text' ||
isElement(node, list) ||
// @ts-ignore Looks like a text.
(node && node.type === 'text') ||
basic(node) ||
embedded(node) ||
bodyOkLink(node) ||
(isElement(node, 'meta') && hasProperty(node, 'itemProp'))
(meta(node) && hasProperty(node, 'itemProp'))
)
}
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
Expand All @@ -36,20 +38,26 @@
"hast-util-is-element": "^2.0.0"
},
"devDependencies": {
"@types/tape": "^4.13.0",
"c8": "^7.0.0",
"hastscript": "^6.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.2",
"tape": "^5.0.0",
"type-coverage": "^2.17.3",
"typescript": "^4.2.4",
"unist-builder": "^3.0.0",
"xo": "^0.39.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"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 +78,10 @@
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"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 3f15a3b

Please sign in to comment.