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.

32 lines (31 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const core_1 = require("../core"); const defaultEncodeOptions = { format: 'hyphenated', roundTo: 6, useCache: false, }; describe('DigiPIN core encode/decode', () => { it('encodes known coordinates', () => { const pin = (0, core_1.getDigiPin)(28.6139, 77.209, defaultEncodeOptions); (0, chai_1.expect)(pin).to.equal('39J-438-TJC7'); }); it('decodes known DIGIPIN', () => { const coords = (0, core_1.getLatLngFromDigiPin)('39J-438-TJC7', { useCache: false }); (0, chai_1.expect)(coords.latitude).to.be.closeTo(28.6139, 0.1); (0, chai_1.expect)(coords.longitude).to.be.closeTo(77.209, 0.1); }); it('round trips through encode -> decode -> encode', () => { const randomInRange = (min, max) => min + Math.random() * (max - min); for (let i = 0; i < 200; i++) { const lat = randomInRange(core_1.BOUNDS.minLat, core_1.BOUNDS.maxLat); const lon = randomInRange(core_1.BOUNDS.minLon, core_1.BOUNDS.maxLon); const pin = (0, core_1.getDigiPin)(lat, lon, defaultEncodeOptions); const decoded = (0, core_1.getLatLngFromDigiPin)(pin, { useCache: false }); const reencoded = (0, core_1.getDigiPin)(decoded.latitude, decoded.longitude, defaultEncodeOptions); (0, chai_1.expect)(reencoded).to.equal(pin); } }); });