All files / lib/helpers get-collection-crs.js

100% Statements 15/15
100% Branches 6/6
100% Functions 1/1
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191x 1x     8x 8x   4x 4x   3x 3x 3x 2x 2x     1x  
const _ = require('lodash')
const OGC_WGS84 = 'ogc:1.3:crs84'
 
function getCollectionCrs (collection) {
  const collectionCrs = _.get(collection, 'crs.properties.name')
  if (!collectionCrs) return
 
  const crs = collectionCrs.toLowerCase().replace(/urn:ogc:def:crs:/, '')
  if (crs === OGC_WGS84) return
 
  const crsRegex = /(?<authority>[a-z]+)(::|:)(?<srid>.+)/
  const result = crsRegex.exec(crs)
  if (!result) return
  const { groups: { srid } } = result
  return srid
}
 
module.exports = getCollectionCrs