-
Notifications
You must be signed in to change notification settings - Fork 316
/
index.d.ts
78 lines (74 loc) · 2.63 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
declare module "cep-promise" {
/** Represents the result of a CEP search */
export interface CEP {
/** The retrieved CEP number */
cep: string;
/** The state associated with the CEP */
state: string;
/** The city associated with the CEP */
city: string;
/** The street associated with the CEP */
street: string;
/** The neighborhood associated with the CEP */
neighborhood: string;
/** The provider which returned the result */
service: string;
}
/**
* Available providers:
*
* | Provider | Browser | Node.js |
* | ------------ | ------- | ------- |
* | brasilapi | ✅ | ✅ |
* | viacep | ✅ | ✅ |
* | widenet | ✅ | ✅ |
* | correios | ❌ | ✅ |
* | correios-alt | ❌ | ✅ |
*/
export const AvailableProviders: {
/** Supported in both **Node.js** and **Browser** environments. */
readonly brasilapi: "brasilapi";
/** Supported in both **Node.js** and **Browser** environments. */
readonly viacep: "viacep";
/** Supported in both **Node.js** and **Browser** environments. */
readonly widenet: "widenet";
/** Supported only in **Node.js** environment. */
readonly correios: "correios";
/** Supported only in **Node.js** environment. */
readonly correiosAlt: "correios-alt";
};
/** Configuration options to customize the CEP search, by selecting specific providers and/or setting a timeout */
export interface Configurations {
/** Specifies the providers to be used for CEP searches, otherwise all available providers will be used.
*
* ---
*
* Available providers:
*
* | Provider | Browser | Node.js |
* | ------------ | ------- | ------- |
* | brasilapi | ✅ | ✅ |
* | viacep | ✅ | ✅ |
* | widenet | ✅ | ✅ |
* | correios | ❌ | ✅ |
* | correios-alt | ❌ | ✅ |
*/
providers?: (typeof AvailableProviders)[keyof typeof AvailableProviders][];
/** Timeout (in milliseconds) after which the CEP search will be cancelled. */
timeout?: number;
}
/**
* Searches for CEP directly integrated with the services of Correios, ViaCEP, and WideNet (Node.js and Browser).
*
* ---
*
* @param cep The CEP (postal code) to search for.
* @param configurations Optional configurations to customize the CEP search.
* @returns A promise that resolves with the CEP details.
*/
export function cep(
cep: string | number,
configurations?: Configurations
): Promise<CEP>;
export default cep;
}