amaran-light-cli
Version:
Command line tool for controlling Aputure Amaran lights via WebSocket to a local Amaran desktop app.
30 lines • 1.15 kB
JavaScript
/**
* Formats a coordinate (latitude or longitude) with privacy redaction by default.
*/
export function formatCoordinate(coord, privacyOff = false) {
return privacyOff ? coord.toFixed(4) : `${Math.round(coord)}.XXXX`;
}
/**
* Formats a location source (e.g., "geoip (1.2.3.4)") with privacy redaction by default.
*/
export function formatSource(source, privacyOff = false) {
if (privacyOff || !source.includes('('))
return source;
const ipMatch = source.match(/(\d+\.\d+\.\d+\.\d+)/);
if (ipMatch) {
const ipParts = ipMatch[1].split('.');
// Redact first three octets
return source.replace(ipMatch[1], `XXX.XXX.XXX.${ipParts[3]}`);
}
return source;
}
/**
* Formats a full location string with privacy redaction by default.
*/
export function formatLocation(lat, lon, source, privacyOff = false) {
const formattedLat = formatCoordinate(lat, privacyOff);
const formattedLon = formatCoordinate(lon, privacyOff);
const formattedSrc = formatSource(source, privacyOff);
return `${formattedLat}°, ${formattedLon}° (${formattedSrc})`;
}
//# sourceMappingURL=privacyUtil.js.map