UNPKG

state_city_pincode

Version:

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

95 lines (72 loc) 2.37 kB
## state_city_pincode state_city_pincode is a Node.js library that provides a simple way to retrieve a list of pincodes based on the provided state and city. ## Installation You can install the Pincode Lookup library using npm: ``` npm install state_city_pincode ``` ## Usage Here's how you can use the Pincode Lookup library in your Node.js application: ```javascript const {pincodeList} = require("state_city_pincode"); // Use the pincodeList function to retrieve pincodes function lookupPincodes(state, city) { try { const pincodes = pincodeList(state, city); console.log(`Pincodes for ${city}, ${state}:`, pincodes); } catch (error) { console.error("Error:", error.message); } } // Example usage: lookupPincodes("Karnataka", "Bengaluru"); ``` ```javascript const {stateCityName} = require("state_city_pincode"); // Use the pincodeLookup function to retrieve pincodes function lookupStateCity(pincode) { try { const stateCity = stateCityName(pincode); console.log(stateCity); } catch (error) { console.error("Error:", error.message); } } // Example usage: lookupStateCity(560103); ``` ```javascript const {getStates} = require("state_city_pincode"); // Use the pincodeLookup function to retrieve pincodes function states() { try { console.log(getStates()) } catch (error) { console.error("Error:", error.message); } } // Example usage: states(); ``` ```javascript const {getCities} = require("state_city_pincode"); // Use the pincodeLookup function to retrieve pincodes function cities(state) { try { console.log(getCities(state)) } catch (error) { console.error("Error:", error.message); } } // Example usage: cities(); ``` ## API pincodeLookup(state, city) 1. state (string): The state for which you want to fetch pincodes. 2. city (string): The city within the state for which you want to fetch pincodes. Returns a promise that resolves to an array of pincodes corresponding to the provided state and city. If no pincodes are found, an empty array is returned. ## Acknowledgments This library uses data from https://data.opendatasoft.com/explore/dataset/geonames-postal-code%40public/?sort=-latitude for pincode information. ## Contact If you have any questions or suggestions, please feel free to contact us.