UNPKG

county

Version:

A JavaScript library for working with state-wise county names in the United States.

29 lines (24 loc) 587 B
// countyLibrary.js const countyData = require("./constant.js"); function getCountiesByState(state) { return countyData[state] || []; } function getAllStates() { return Object.keys(countyData); } function searchCounties(query) { const matchingCounties = []; Object.values(countyData).forEach((counties) => { counties.forEach((county) => { if (county.toLowerCase().includes(query.toLowerCase())) { matchingCounties.push(county); } }); }); return matchingCounties; } module.exports = { getCountiesByState, getAllStates, searchCounties, };