Skip to content

src/searchPlaces.ts

23 lines · 785 B · TypeScript
Raw
import { searchPlaces as scrapeSearch } from './scrape'
import type { PlaceHit } from './types'

export type { PlaceHit }

/**
 * Search air-quality.com places by Chinese or English name.
 * Use before getSnapshot when you need to pick among stations/districts.
 *
 * @param input - Search term and optional limit
 * @returns Ranked place hits with `place` paths usable by getSnapshot
 *
 * @example
 * import { searchPlaces } from 'kody:@reng/air-quality/searchPlaces'
 *
 * const hits = await searchPlaces({ term: '海淀', limit: 5 })
 * // [{ name, place: 'china/.../...', ... }]
 */
export async function searchPlaces(input: { term: string; limit?: number } = { term: '' }): Promise<PlaceHit[]> {
	return scrapeSearch(input.term, input.limit ?? 20)
}

export default searchPlaces