digipinjs
Version:
A comprehensive TypeScript library for encoding and decoding Indian geographic coordinates into DIGIPIN format (Indian Postal Digital PIN system). Features CLI tools, caching, batch processing, and Express middleware for seamless integration.
24 lines (23 loc) • 774 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.digiPinMiddleware = digiPinMiddleware;
const core_1 = require("./core");
/**
* Express middleware: reads x-lat & x-lng headers, adds X-DIGIPIN
*/
function digiPinMiddleware() {
return (req, res, next) => {
const lat = parseFloat(req.header('x-lat') || '');
const lng = parseFloat(req.header('x-lng') || '');
if (!isNaN(lat) && !isNaN(lng)) {
try {
res.setHeader('X-DIGIPIN', (0, core_1.getDigiPin)(lat, lng));
}
catch (error) {
// Silently handle out of bounds errors
// The middleware will continue without setting X-DIGIPIN
}
}
next();
};
}