UNPKG

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.

36 lines (35 loc) 1.05 kB
import LRU from 'lru-cache'; const encodeCache = new LRU({ max: 10000 }); const decodeCache = new LRU({ max: 10000 }); function encodeKey(lat, lng, format) { return `${lat},${lng}:${format}`; } export function getCachedEncode(lat, lng, format) { return encodeCache.get(encodeKey(lat, lng, format)); } export function setCachedEncode(lat, lng, pin, format) { encodeCache.set(encodeKey(lat, lng, format), pin); } export function getCachedDecode(pin) { return decodeCache.get(pin); } export function setCachedDecode(pin, coordinates) { decodeCache.set(pin, coordinates); } // Backwards compatible helpers (default hyphenated format) export function getCached(lat, lng) { return getCachedEncode(lat, lng, 'hyphenated'); } export function setCached(lat, lng, pin) { setCachedEncode(lat, lng, pin, 'hyphenated'); } export function clearEncodeCache() { encodeCache.clear(); } export function clearDecodeCache() { decodeCache.clear(); } export function clearCache() { clearEncodeCache(); clearDecodeCache(); }