parseCode.js 751 B

123456789101112131415161718192021222324252627282930313233343536
  1. var defs = require('./defs');
  2. var wkt = require('./wkt');
  3. var projStr = require('./projString');
  4. function testObj(code){
  5. return typeof code === 'string';
  6. }
  7. function testDef(code){
  8. return code in defs;
  9. }
  10. function testWKT(code){
  11. var codeWords = ['GEOGCS','GEOCCS','PROJCS','LOCAL_CS'];
  12. return codeWords.reduce(function(a,b){
  13. return a+1+code.indexOf(b);
  14. },0);
  15. }
  16. function testProj(code){
  17. return code[0] === '+';
  18. }
  19. function parse(code){
  20. if (testObj(code)) {
  21. //check to see if this is a WKT string
  22. if (testDef(code)) {
  23. return defs[code];
  24. }
  25. else if (testWKT(code)) {
  26. return wkt(code);
  27. }
  28. else if (testProj(code)) {
  29. return projStr(code);
  30. }
  31. }else{
  32. return code;
  33. }
  34. }
  35. module.exports = parse;