siblings.js 614 B

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. var whiteSpace = require('hast-util-whitespace')
  3. exports.before = siblings(-1)
  4. exports.after = siblings(1)
  5. /* Factory to check siblings in a direction. */
  6. function siblings(increment) {
  7. return sibling
  8. /* Find applicable siblings in a direction. */
  9. function sibling(parent, index, includeWhiteSpace) {
  10. var siblings = parent && parent.children
  11. var next
  12. index += increment
  13. next = siblings && siblings[index]
  14. if (!includeWhiteSpace) {
  15. while (next && whiteSpace(next)) {
  16. index += increment
  17. next = siblings[index]
  18. }
  19. }
  20. return next
  21. }
  22. }