We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 878eaec commit 2f6230eCopy full SHA for 2f6230e
index.js
@@ -8,7 +8,10 @@ var digit6 = 54 // `6`
8
9
// Rank of a heading: H1 -> 1, H2 -> 2, etc.
10
function headingRank(node) {
11
- var name = (node.type === 'element' ? node.tagName : '').toLowerCase()
+ var name = (
12
+ (node && node.type === 'element' && node.tagName) ||
13
+ ''
14
+ ).toLowerCase()
15
var code =
16
name.length === 2 && name.charCodeAt(0) === lowercaseH
17
? name.charCodeAt(1)
test.js
@@ -5,6 +5,8 @@ var h = require('hastscript')
5
var rank = require('.')
6
7
test('rank', function(t) {
+ t.equal(rank(), null, 'should return null for non-nodes')
+
t.equal(
rank({type: 'text', value: '!'}),
null,
0 commit comments