one
Version:
One is a React framework for web, iOS, and Android apps.
48 lines (46 loc) • 2.05 kB
JavaScript
function isFiniteNumber(value) {
return typeof value === "number" && Number.isFinite(value);
}
function assertCenter(center, verb) {
if (!center || typeof center !== "object") {
throw new TypeError(`Location.${verb}: region center must be an object`);
}
var candidate = center;
if (!isFiniteNumber(candidate.latitude) || Math.abs(candidate.latitude) > 90) {
throw new TypeError(`Location.${verb}: region center latitude must be a number from -90 to 90`);
}
if (!isFiniteNumber(candidate.longitude) || Math.abs(candidate.longitude) > 180) {
throw new TypeError(`Location.${verb}: region center longitude must be a number from -180 to 180`);
}
}
function assertRegion(region, verb) {
if (!region || typeof region !== "object") {
throw new TypeError(`Location.${verb}: region must be an object`);
}
var candidate = region;
if (typeof candidate.identifier !== "string" || candidate.identifier.trim() === "") {
throw new TypeError(`Location.${verb}: region identifier must be a non-empty string`);
}
assertCenter(candidate.center, verb);
if (!isFiniteNumber(candidate.radius) || candidate.radius <= 0) {
throw new TypeError(`Location.${verb}: region radius must be a number greater than 0`);
}
if (candidate.notifyOnEntry !== void 0 && typeof candidate.notifyOnEntry !== "boolean") {
throw new TypeError(`Location.${verb}: region notifyOnEntry must be a boolean`);
}
if (candidate.notifyOnExit !== void 0 && typeof candidate.notifyOnExit !== "boolean") {
throw new TypeError(`Location.${verb}: region notifyOnExit must be a boolean`);
}
}
function assertIdentifier(identifier, verb) {
if (typeof identifier !== "string" || identifier.trim() === "") {
throw new TypeError(`Location.${verb}: region identifier must be a non-empty string`);
}
}
function assertRegionListener(listener, verb) {
if (typeof listener !== "function") {
throw new TypeError(`Location.${verb}: listener must be a function`);
}
}
export { assertIdentifier, assertRegion, assertRegionListener };
//# sourceMappingURL=validation.native.js.map