@elgervb/mock-data
Version:
Mock data made easy, while maintaining type safety
33 lines • 1.38 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomGeolocation = exports.GeoType = exports.maxGeolocLat = exports.minGeolocLat = exports.maxGeolocLong = exports.minGeolocLong = void 0;
var number_1 = require("./number");
exports.minGeolocLong = -180;
exports.maxGeolocLong = 180;
exports.minGeolocLat = -90;
exports.maxGeolocLat = 90;
/**
* The geolocation type (long or lat)
*/
var GeoType;
(function (GeoType) {
GeoType["long"] = "long";
GeoType["lat"] = "lat";
})(GeoType = exports.GeoType || (exports.GeoType = {}));
/**
* Renerates a random geo location point
*/
function randomGeolocation(from, to, type) {
if (from === void 0) { from = exports.minGeolocLong; }
if (to === void 0) { to = exports.maxGeolocLong; }
if (type === void 0) { type = GeoType.long; }
var minGeoloc = type === GeoType.long ? exports.minGeolocLong : exports.minGeolocLat;
var maxGeoloc = type === GeoType.long ? exports.maxGeolocLong : exports.maxGeolocLat;
if (from < minGeoloc || to > maxGeoloc) {
throw new Error("randomGeolocation ".concat(type, " range should be between ").concat(minGeoloc, " and ").concat(maxGeoloc));
}
var fractionDigits = 5;
return (0, number_1.randomNumber)(from, to, fractionDigits);
}
exports.randomGeolocation = randomGeolocation;
//# sourceMappingURL=geolocation.js.map
;