@pretto/places 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,7 +21,7 @@ import { municipalitySearch } from '@pretto/places'
21
21
  const result = await municipalitySearch.get("paris", { limit: 21 })
22
22
 
23
23
  // expected result : Paris (75001), Paris (75002), Paris (75003), ..., Paris (75020)
24
- // result object format :
24
+ // result object format :
25
25
  [
26
26
  {
27
27
  "label": "Paris (75001)",
@@ -51,7 +51,7 @@ import { municipalitySearch } from '@pretto/places'
51
51
  const result = await municipalitySearch.get("paris", { departmentOnly: true, limit: 21 })
52
52
 
53
53
  // expected result : Paris (75), Parisot(81), Parisot (82), Cormeilles-en-Parisis (95), ...
54
- // result object format :
54
+ // result object format :
55
55
  [
56
56
  {
57
57
  "label": "Paris (75)",
@@ -81,7 +81,7 @@ import { addressSearch } from '@pretto/places'
81
81
  const result = await addressSearch.get("55 rue de paradis", { limit: 10 })
82
82
 
83
83
  // expected result : 55 Rue de Paradis 75010 Paris (75010), 55 Rue de Paradis 51160 Hautvillers (51160)...
84
- // result object format :
84
+ // result object format :
85
85
  [
86
86
  {
87
87
  "label": "55 Rue de Paradis 75010 Paris (75010)",
@@ -111,26 +111,34 @@ For country
111
111
  import { countrySearch } from '@pretto/places'
112
112
 
113
113
  const countriesApi = countrySearch.init(ALGOLIA_COUNTRIES_APP_ID, ALGOLIA_COUNTRIES_API_KEY)
114
- const results = await countriesApi.get("al", { limit: 10 })
115
-
116
- // expected result : Allemagne (99109), Albanie (99125), Algerie (99352)
117
- // result object format :
118
- [
119
- {
120
- "label": "Allemagne (99109)",
121
- "value": "de"
122
- },
123
- {
124
- "label": "Albanie (99125)",
125
- "value": "al"
126
- },
127
- {
128
- "label": "Algerie (99352)",
129
- "value": "dz"
130
- }
114
+ const results = await countriesApi.get('al', { limit: 10 })[
115
+ // expected result : Allemagne (99109), Albanie (99125), Algerie (99352)
116
+ // result object format :
117
+ ({
118
+ label: 'Allemagne (99109)',
119
+ value: 'de',
120
+ },
121
+ {
122
+ label: 'Albanie (99125)',
123
+ value: 'al',
124
+ },
125
+ {
126
+ label: 'Algerie (99352)',
127
+ value: 'dz',
128
+ })
131
129
  ]
132
130
  ```
133
131
 
132
+ ### Debounce
133
+
134
+ `addressSearch` and `municipalitySearch` have defaut debounce value fixed to **300ms**\
135
+ You can override this value by passing `debounceValue` as last argument
136
+
137
+ ```jsx
138
+ const debounceValue = 1000 // --- 1000 = 1s
139
+ const results = await countriesApi.get('al', { limit: 10 }, debounceValue)
140
+ ```
141
+
134
142
  ### How to publish a new version?
135
143
 
136
144
  When a branch is merged into master, it will automatically deploy a new version to npm.
@@ -1,3 +1,12 @@
1
+ interface AddressSearchResult {
2
+ label: string;
3
+ value: {
4
+ city: string;
5
+ country: string;
6
+ street: string;
7
+ zipcode: string;
8
+ };
9
+ }
1
10
  export interface AddressApiResult {
2
11
  properties: {
3
12
  label: string;
@@ -12,6 +21,7 @@ interface Options {
12
21
  country: string;
13
22
  limit: number;
14
23
  }
15
- export declare const get: (search: string, options?: Options | undefined, debounceValue?: 300 | undefined) => number;
24
+ declare type DebouncedAddressSearch = (search: string, options?: Options, debounceValue?: number) => Promise<AddressSearchResult[] | string>;
25
+ export declare const get: DebouncedAddressSearch;
16
26
  export {};
17
27
  //# sourceMappingURL=addressSearch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"addressSearch.d.ts","sourceRoot":"","sources":["../src/addressSearch.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AAuCD,eAAO,MAAM,GAAG,WAAY,MAAM,2EAQjC,CAAA"}
1
+ {"version":3,"file":"addressSearch.d.ts","sourceRoot":"","sources":["../src/addressSearch.ts"],"names":[],"mappings":"AAAA,UAAU,mBAAmB;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AAED,aAAK,sBAAsB,GAAG,CAC5B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,EACjB,aAAa,CAAC,EAAE,MAAM,KACnB,OAAO,CAAC,mBAAmB,EAAE,GAAG,MAAM,CAAC,CAAA;AAuC5C,eAAO,MAAM,GAAG,EAAE,sBAQjB,CAAA"}
package/dist/index.js CHANGED
@@ -134,12 +134,13 @@ const getData$1 = (search, options) => __awaiter(void 0, void 0, void 0, functio
134
134
  }
135
135
  });
136
136
  let getDelayedData$1;
137
- const get$2 = (search, options, debounceValue) => {
137
+ const get$2 = (search, options, debounceValue = 300) => {
138
138
  clearTimeout(getDelayedData$1);
139
- getDelayedData$1 = setTimeout(() => {
140
- getData$1(search, options);
141
- }, debounceValue);
142
- return getDelayedData$1;
139
+ return new Promise((resolve, reject) => {
140
+ getDelayedData$1 = setTimeout(() => {
141
+ resolve(getData$1(search, options));
142
+ }, debounceValue);
143
+ });
143
144
  };
144
145
 
145
146
  var municipalitySearch = /*#__PURE__*/Object.freeze({
@@ -149,7 +150,7 @@ var municipalitySearch = /*#__PURE__*/Object.freeze({
149
150
  });
150
151
 
151
152
  const getData = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
152
- if (!search)
153
+ if (!search || search.length < 2)
153
154
  return [];
154
155
  try {
155
156
  const { country = 'fr', limit = 5 } = options || {};
@@ -182,12 +183,13 @@ const getData = (search, options) => __awaiter(void 0, void 0, void 0, function*
182
183
  }
183
184
  });
184
185
  let getDelayedData;
185
- const get$1 = (search, options, debounceValue) => {
186
+ const get$1 = (search, options, debounceValue = 300) => {
186
187
  clearTimeout(getDelayedData);
187
- getDelayedData = setTimeout(() => {
188
- getData(search, options);
189
- }, debounceValue);
190
- return getDelayedData;
188
+ return new Promise((resolve, reject) => {
189
+ getDelayedData = setTimeout(() => {
190
+ resolve(getData(search, options));
191
+ }, debounceValue);
192
+ });
191
193
  };
192
194
 
193
195
  var addressSearch = /*#__PURE__*/Object.freeze({
package/dist/module.js CHANGED
@@ -124,12 +124,13 @@ const getData$1 = (search, options) => __awaiter(void 0, void 0, void 0, functio
124
124
  }
125
125
  });
126
126
  let getDelayedData$1;
127
- const get$2 = (search, options, debounceValue) => {
127
+ const get$2 = (search, options, debounceValue = 300) => {
128
128
  clearTimeout(getDelayedData$1);
129
- getDelayedData$1 = setTimeout(() => {
130
- getData$1(search, options);
131
- }, debounceValue);
132
- return getDelayedData$1;
129
+ return new Promise((resolve, reject) => {
130
+ getDelayedData$1 = setTimeout(() => {
131
+ resolve(getData$1(search, options));
132
+ }, debounceValue);
133
+ });
133
134
  };
134
135
 
135
136
  var municipalitySearch = /*#__PURE__*/Object.freeze({
@@ -139,7 +140,7 @@ var municipalitySearch = /*#__PURE__*/Object.freeze({
139
140
  });
140
141
 
141
142
  const getData = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
142
- if (!search)
143
+ if (!search || search.length < 2)
143
144
  return [];
144
145
  try {
145
146
  const { country = 'fr', limit = 5 } = options || {};
@@ -172,12 +173,13 @@ const getData = (search, options) => __awaiter(void 0, void 0, void 0, function*
172
173
  }
173
174
  });
174
175
  let getDelayedData;
175
- const get$1 = (search, options, debounceValue) => {
176
+ const get$1 = (search, options, debounceValue = 300) => {
176
177
  clearTimeout(getDelayedData);
177
- getDelayedData = setTimeout(() => {
178
- getData(search, options);
179
- }, debounceValue);
180
- return getDelayedData;
178
+ return new Promise((resolve, reject) => {
179
+ getDelayedData = setTimeout(() => {
180
+ resolve(getData(search, options));
181
+ }, debounceValue);
182
+ });
181
183
  };
182
184
 
183
185
  var addressSearch = /*#__PURE__*/Object.freeze({
@@ -19,8 +19,9 @@ interface Options {
19
19
  limit?: number;
20
20
  departmentOnly?: boolean;
21
21
  }
22
+ declare type DebouncedMunicipalitySearch = (search: string, options?: Options, debounceValue?: number) => Promise<MunicipalitySearchResult[] | string>;
22
23
  declare type MunicipalitySearch = (search: string, options?: Options) => Promise<MunicipalitySearchResult[] | string>;
23
24
  export declare const getData: MunicipalitySearch;
24
- export declare const get: (search: string, options?: Options | undefined, debounceValue?: 300 | undefined) => number;
25
+ export declare const get: DebouncedMunicipalitySearch;
25
26
  export {};
26
27
  //# sourceMappingURL=municipalitySearch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"municipalitySearch.d.ts","sourceRoot":"","sources":["../src/municipalitySearch.ts"],"names":[],"mappings":"AAKA,UAAU,wBAAwB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,GAA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OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,wBAAwB,EAAE,GAAG,MAAM,CAAC,CAAA;AAmD7G,eAAO,MAAM,OAAO,EAAE,kBAoCrB,CAAA;AAID,eAAO,MAAM,GAAG,EAAE,2BAQjB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretto/places",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",