hast-util-heading-rank
Advanced tools
Comparing version 1.0.1 to 2.0.0
29
index.js
@@ -1,20 +0,19 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('hast').Element} HastElement | ||
*/ | ||
module.exports = headingRank | ||
var lowercaseH = 104 // `h` | ||
var digit0 = 48 // `0` | ||
var digit6 = 54 // `6` | ||
// Rank of a heading: H1 -> 1, H2 -> 2, etc. | ||
function headingRank(node) { | ||
var name = ( | ||
(node && node.type === 'element' && node.tagName) || | ||
'' | ||
).toLowerCase() | ||
/** | ||
* Rank of a heading: H1 -> 1, H2 -> 2, etc. | ||
* | ||
* @param {HastElement} node | ||
* @returns {number|null} | ||
*/ | ||
export function headingRank(node) { | ||
var name = | ||
(node && node.type === 'element' && node.tagName.toLowerCase()) || '' | ||
var code = | ||
name.length === 2 && name.charCodeAt(0) === lowercaseH | ||
name.length === 2 && name.charCodeAt(0) === 104 /* `h` */ | ||
? name.charCodeAt(1) | ||
: 0 | ||
return code > digit0 && code <= digit6 ? code - digit0 : null | ||
return code > 48 /* `0` */ && code < 55 /* `7` */ ? code - 48 /* `0` */ : null | ||
} |
{ | ||
"name": "hast-util-heading-rank", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "hast utility to get the rank (or depth, level) of headings", | ||
@@ -28,20 +28,33 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": {}, | ||
"dependencies": { | ||
"@types/hast": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"hastscript": "^5.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.27.0" | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"hastscript": "^7.0.0", | ||
"prettier": "^2.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", | ||
"xo": "^0.39.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run test-coverage" | ||
"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 build && npm run format && npm run test-coverage" | ||
}, | ||
@@ -58,10 +71,7 @@ "prettier": { | ||
"prettier": true, | ||
"esnext": false | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"remarkConfig": { | ||
@@ -71,3 +81,8 @@ "plugins": [ | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true | ||
} | ||
} |
@@ -15,2 +15,5 @@ # hast-util-heading-rank | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -34,2 +37,5 @@ | ||
This package exports the following identifiers: `headingRank`. | ||
There is no default export. | ||
### `headingRank(node)` | ||
@@ -75,5 +81,5 @@ | ||
[build-badge]: https://img.shields.io/travis/syntax-tree/hast-util-heading-rank.svg | ||
[build-badge]: https://github.com/syntax-tree/hast-util-heading-rank/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/syntax-tree/hast-util-heading-rank | ||
[build]: https://github.com/syntax-tree/hast-util-heading-rank/actions | ||
@@ -98,5 +104,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-heading-rank.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/syntax-tree | ||
[chat]: https://github.com/syntax-tree/unist/discussions | ||
@@ -109,7 +115,7 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/syntax-tree/.github/blob/master/support.md | ||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md | ||
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md | ||
@@ -116,0 +122,0 @@ [hast]: https://github.com/syntax-tree/hast |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7235
5
29
122
Yes
1
11
+ Added@types/hast@^2.0.0
+ Added@types/hast@2.3.10(transitive)
+ Added@types/unist@2.0.11(transitive)