Skip to content

Commit 35fcd69

Browse files
committed
feat(index.d.ts): flexible AvailableProviders and minimal documentation
1 parent 887608f commit 35fcd69

File tree

1 file changed

+69
-19
lines changed

1 file changed

+69
-19
lines changed

index.d.ts

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,78 @@
1-
declare module 'cep-promise' {
1+
declare module "cep-promise" {
2+
/** Represents the result of a CEP search */
23
export interface CEP {
3-
cep: string,
4-
state: string,
5-
city: string,
6-
street: string,
7-
neighborhood: string,
8-
service: string
9-
}
10-
11-
export enum AvailableProviders {
12-
brasilapi = "brasilapi",
13-
correios = "correios",
14-
correiosAlt = "correios-alt",
15-
viacep = "viacep",
16-
widenet = "widenet"
4+
/** The retrieved CEP number */
5+
cep: string;
6+
/** The state associated with the CEP */
7+
state: string;
8+
/** The city associated with the CEP */
9+
city: string;
10+
/** The street associated with the CEP */
11+
street: string;
12+
/** The neighborhood associated with the CEP */
13+
neighborhood: string;
14+
/** The provider which returned the result */
15+
service: string;
1716
}
1817

18+
/**
19+
* Available providers:
20+
*
21+
* | Provider | Browser | Node.js |
22+
* | ------------ | ------- | ------- |
23+
* | brasilapi | ✅ | ✅ |
24+
* | viacep | ✅ | ✅ |
25+
* | widenet | ✅ | ✅ |
26+
* | correios | ❌ | ✅ |
27+
* | correios-alt | ❌ | ✅ |
28+
*/
29+
export const AvailableProviders: {
30+
/** Supported in both **Node.js** and **Browser** environments. */
31+
readonly brasilapi: "brasilapi";
32+
/** Supported in both **Node.js** and **Browser** environments. */
33+
readonly viacep: "viacep";
34+
/** Supported in both **Node.js** and **Browser** environments. */
35+
readonly widenet: "widenet";
36+
/** Supported only in **Node.js** environment. */
37+
readonly correios: "correios";
38+
/** Supported only in **Node.js** environment. */
39+
readonly correiosAlt: "correios-alt";
40+
};
1941

42+
/** Configuration options to customize the CEP search, by selecting specific providers and/or setting a timeout */
2043
export interface Configurations {
21-
providers?: AvailableProviders[],
22-
timeout?: number
44+
/** Specifies the providers to be used for CEP searches, otherwise all available providers will be used.
45+
*
46+
* ---
47+
*
48+
* Available providers:
49+
*
50+
* | Provider | Browser | Node.js |
51+
* | ------------ | ------- | ------- |
52+
* | brasilapi | ✅ | ✅ |
53+
* | viacep | ✅ | ✅ |
54+
* | widenet | ✅ | ✅ |
55+
* | correios | ❌ | ✅ |
56+
* | correios-alt | ❌ | ✅ |
57+
*/
58+
providers?: (typeof AvailableProviders)[keyof typeof AvailableProviders][];
59+
/** Timeout (in milliseconds) after which the CEP search will be cancelled. */
60+
timeout?: number;
2361
}
2462

25-
export function cep(cep: string | number, configurations?: Configurations): Promise<CEP>
63+
/**
64+
* Searches for CEP directly integrated with the services of Correios, ViaCEP, and WideNet (Node.js and Browser).
65+
*
66+
* ---
67+
*
68+
* @param cep The CEP (postal code) to search for.
69+
* @param configurations Optional configurations to customize the CEP search.
70+
* @returns A promise that resolves with the CEP details.
71+
*/
72+
export function cep(
73+
cep: string | number,
74+
configurations?: Configurations
75+
): Promise<CEP>;
2676

27-
export default cep
77+
export default cep;
2878
}

0 commit comments

Comments
 (0)