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.
34 lines (33 loc) • 969 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeDigiPin = normalizeDigiPin;
exports.digiPinValidator = digiPinValidator;
const errors_1 = require("./errors");
const ALLOWED_CHARS = new Set([
'F', 'C', '9', '8',
'J', '3', '2', '7',
'K', '4', '5', '6',
'L', 'M', 'P', 'T',
]);
/**
* Validate a DIGIPIN and return it in normalized compact form (uppercase, no hyphen).
*/
function normalizeDigiPin(pin) {
const cleaned = pin.replace(/-/g, '').trim().toUpperCase();
if (cleaned.length !== 10) {
throw new errors_1.PinFormatError(pin);
}
for (const ch of cleaned) {
if (!ALLOWED_CHARS.has(ch)) {
throw new errors_1.InvalidCharacterError(ch);
}
}
return cleaned;
}
/**
* Validate DIGIPIN without returning normalized value (legacy helper).
* Returns void for backwards compatibility.
*/
function digiPinValidator(pin) {
normalizeDigiPin(pin);
}