1234567891011121314151617181920212223242526272829303132 |
- 'use strict'
- var convert = require('./convert')
- module.exports = is
- is.convert = convert
- function is(node, test, index, parent, context) {
- var check = convert(test)
- if (
- index != null &&
- (typeof index !== 'number' || index < 0 || index === Infinity)
- ) {
- throw new Error('Expected positive finite index')
- }
- if (parent != null && (!is(parent) || !parent.children)) {
- throw new Error('Expected parent node')
- }
- if ((parent == null) !== (index == null)) {
- throw new Error('Expected both parent and index')
- }
- return node && node.type && typeof node.type === 'string'
- ? Boolean(check.call(context, node, index, parent))
- : false
- }
|