index.js 527 B

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. var start = factory('start')
  3. var end = factory('end')
  4. module.exports = position
  5. position.start = start
  6. position.end = end
  7. function position(node) {
  8. return {start: start(node), end: end(node)}
  9. }
  10. function factory(type) {
  11. point.displayName = type
  12. return point
  13. function point(node) {
  14. var point = (node && node.position && node.position[type]) || {}
  15. return {
  16. line: point.line || null,
  17. column: point.column || null,
  18. offset: isNaN(point.offset) ? null : point.offset
  19. }
  20. }
  21. }