Skip to content

src/index.ts

89 lines · 2.2 KB · TypeScript
Raw
import { getSnapshot as fetchSnapshot, type GetSnapshotInput, AQI_STANDARDS } from './getSnapshot'
import { getAirQuality as fetchAirQuality, type GetAirQualityResult } from './getAirQuality'
import { getPollen as fetchPollen, type GetPollenResult } from './getPollen'
import { searchPlaces as fetchSearchPlaces } from './searchPlaces'
import type {
	AirQualitySnapshot,
	AqiStandard,
	PlaceHit,
	Pollutants,
	PollenSnapshot,
	WeatherSnapshot,
} from './types'

export type {
	GetSnapshotInput,
	GetAirQualityResult,
	GetPollenResult,
	AirQualitySnapshot,
	AqiStandard,
	PlaceHit,
	Pollutants,
	PollenSnapshot,
	WeatherSnapshot,
}

export { AQI_STANDARDS }

/**
 * Full outdoor snapshot from air-quality.com scrape (AQI, pollutants, pollen, weather).
 * Use when you need the HA-style field set in one call.
 *
 * @param input - `location` and/or `place`, optional `standard`, `fallback`
 * @returns Unified snapshot with source and summary
 *
 * @example
 * import { getSnapshot } from 'kody:@reng/air-quality'
 *
 * const bj = await getSnapshot({ location: '北京' })
 */
export async function getSnapshot(input: GetSnapshotInput = {}) {
	return fetchSnapshot(input)
}

/**
 * AQI + pollutants only.
 *
 * @param input - Same as getSnapshot
 * @returns Slim air-quality result
 *
 * @example
 * import { getAirQuality } from 'kody:@reng/air-quality'
 *
 * const sh = await getAirQuality({ location: '上海' })
 */
export async function getAirQuality(input: GetSnapshotInput = {}) {
	return fetchAirQuality(input)
}

/**
 * Pollen + allergy risk slice.
 *
 * @param input - Same as getSnapshot
 * @returns Pollen result
 *
 * @example
 * import { getPollen } from 'kody:@reng/air-quality'
 *
 * const p = await getPollen({ location: 'Berlin' })
 */
export async function getPollen(input: GetSnapshotInput = {}) {
	return fetchPollen(input)
}

/**
 * Search places on air-quality.com.
 *
 * @param input - term + optional limit
 * @returns Place hits
 *
 * @example
 * import { searchPlaces } from 'kody:@reng/air-quality'
 *
 * const hits = await searchPlaces({ term: '朝阳' })
 */
export async function searchPlaces(input: { term: string; limit?: number }) {
	return fetchSearchPlaces(input)
}

export default getSnapshot