UNPKG

state_city_pincode

Version:

A utility package giving a list of postal codes for the received state and city. Currently works for India

52 lines (42 loc) 1.47 kB
// Import the pincode map from a separate module const pincodeMap = require("./state_city_code.js"); const pincodeStateMap = require("./code_city_state.js") const states = require("./state.js") const cities = require("./city.js") /** * Retrieve a list of pincodes based on the provided state and city. * @param {string} state - The state for which you want to fetch pincodes. * @param {string} city - The city within the state for which you want to fetch pincodes. * @returns {Promise<Array<string>>} An array of pincodes corresponding to the state and city. */ function pincodeList(state, city) { // Create a key to look up in the pincodeMap const key = state.toLowerCase() + "_" + city.toLowerCase(); // Check if the key exists in the map if (pincodeMap[key]) { return pincodeMap[key]; } // If the key is not found, return an empty array return []; } function stateCityName(pincode) { const key = pincode; // Check if the key exists in the map if (pincodeStateMap[key]) { return pincodeStateMap[key]; } // If the key is not found, return an empty array return {}; } function getStates() { return states; } function getCities(state) { const key = state.toLowerCase() if (cities[key]) { return cities[key] } return [] } // Export the pincodeList function so it can be used in other modules module.exports = { pincodeList, stateCityName, getStates, getCities }