india-state-district
Version:
A lightweight TypeScript library for handling Indian states and districts data with type safety, geolocation support, and easy integration
59 lines (58 loc) • 1.67 kB
TypeScript
export interface StateData {
[stateCode: string]: string[];
}
export interface State {
name: string;
code: string;
districts: string[];
}
export interface IndiaStateDistrictOptions {
stateSelectId?: string;
districtSelectId?: string;
defaultState?: string;
defaultDistrict?: string;
onChange?: (state: string, district: string) => void;
onStateChange?: (state: string, stateCode: string) => void;
onDistrictChange?: (district: string, stateCode: string) => void;
placeholder?: {
state?: string;
district?: string;
};
validation?: {
required?: boolean;
customValidation?: (state: string, district: string) => boolean;
};
displayStateCode?: boolean;
}
export interface StateDistrictSelection {
state: string;
stateCode: string;
district: string;
}
export interface ValidationResult {
isValid: boolean;
errors: string[];
}
export type FilterFunction = (state: State) => boolean;
export interface GeolocationResult {
state: string;
stateCode: string;
district?: string;
latitude: number;
longitude: number;
}
export interface GeolocationOptions {
/** Enable high accuracy mode (uses more battery) */
enableHighAccuracy?: boolean;
/** Maximum time to wait for location (ms) */
timeout?: number;
/** Maximum age of cached position (ms) */
maximumAge?: number;
}
export interface GeolocationError {
code: "PERMISSION_DENIED" | "POSITION_UNAVAILABLE" | "TIMEOUT" | "NOT_SUPPORTED" | "REVERSE_GEOCODE_FAILED" | "STATE_NOT_FOUND";
message: string;
}
export declare const STATE_NAMES: {
[key: string]: string;
};