read-gedcom
Version:
Gedcom file reader
34 lines • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseLongitude = exports.parseLatitude = void 0;
const parseCoordinate = (regex, orientation, value) => {
if (!value) {
return null;
}
const groups = regex.exec(value);
if (!groups) {
return null;
}
const sign = groups[1] !== undefined ? orientation[groups[1]] : groups[2] === '-' ? -1 : 1;
const decimal = parseFloat(groups[3]);
return sign * decimal;
};
/**
* @param value
* @category Value parsers
*/
const parseLatitude = (value) => {
const rLatitude = /^(?:([NS])|([+-]?))([0-9]{1,2}(?:\.[0-9]{1,6})?)$/;
return parseCoordinate(rLatitude, { N: 1, S: -1 }, value);
};
exports.parseLatitude = parseLatitude;
/**
* @param value
* @category Value parsers
*/
const parseLongitude = (value) => {
const rLongitude = /^(?:([EW])|([+-]?))([0-9]{1,3}(?:\.[0-9]{1,6})?)$/;
return parseCoordinate(rLongitude, { E: 1, W: -1 }, value);
};
exports.parseLongitude = parseLongitude;
//# sourceMappingURL=coordinates.js.map