All files / src/loaders dbf.js

100% Statements 4/4
100% Branches 4/4
100% Functions 3/3
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20          26x   26x 26x         24x            
/* istanbul ignore next */
var shapefile = require('shapefile')
import identity from '../utils/identity'
 
export default function dbf (filePath, parser, parserOptions, cb) {
  var values = []
  parserOptions = parserOptions || {}
  var map = parserOptions.map || identity
  var i = 0
  shapefile.openDbf(filePath)
    .then(source => source.read()
      .then(function log (result) {
        i++
        if (result.done) return cb(null, values)
        values.push(map(result.value, i))
        return source.read().then(log)
      }))
    .catch(error => cb(error.stack))
}