@@ -4,14 +4,16 @@ const debounce = require('debounce');
44
55module . exports = geoplete ;
66
7- /* global AbortController */
8-
97const Suggestions = {
10- 'address' : {
11- toString ( ) { return this . address || this . place ; }
8+ address : {
9+ toString ( ) {
10+ return this . address || this . place ;
11+ }
1212 } ,
13- 'place' : {
14- toString ( ) { return this . place || this . address ; }
13+ place : {
14+ toString ( ) {
15+ return this . place || this . address ;
16+ }
1517 }
1618} ;
1719
@@ -28,18 +30,16 @@ function geoQuery(query) {
2830}
2931
3032function regExpEscape ( s ) {
31- return s . replace ( / [ - \\ ^ $ * + ? . ( ) | [ \] { } ] / g, " \\$&" ) ;
33+ return s . replace ( / [ - \\ ^ $ * + ? . ( ) | [ \] { } ] / g, ' \\$&' ) ;
3234}
3335
34- function geoplete ( el , options ) {
35- options = options || { } ;
36+ function geoplete ( el , options = { } ) {
3637 options . type = Suggestions [ options . type ] ? options . type : 'address' ;
37- options . minChars = options . minChars || 4 ;
38- options . trigger = options . trigger || trigger ;
39-
40- options . geoQuery = options . geoQuery || geoQuery ;
41- options . minMatching = options . minMatching || 2 ;
42- options . filterMatches = options . filterMatches || filterMatches ;
38+ options . minChars ??= 4 ;
39+ options . trigger ??= trigger ;
40+ options . geoQuery ??= geoQuery ;
41+ options . minMatching ??= 2 ;
42+ options . filterMatches ??= filterMatches ;
4343 const acOptions = {
4444 minChars : 0 ,
4545 filter : displayAll ,
@@ -52,7 +52,6 @@ function geoplete(el, options) {
5252 acOptions . container = options . container ;
5353 }
5454
55-
5655 const geoOptions = options . geocoder ;
5756
5857 let lastValue ;
@@ -61,16 +60,16 @@ function geoplete(el, options) {
6160 const ac = new Awesomplete ( el , acOptions ) ;
6261
6362 if ( options . keepOpen ) {
64- ac . close = function ( close , o ) {
65- if ( o && o . reason && keepOpen [ o . reason ] ) {
63+ ac . close = function ( close , o , ... args ) {
64+ if ( o ? .reason && keepOpen [ o . reason ] ) {
6665 return ;
6766 }
68- close . apply ( this , Array . prototype . slice . call ( arguments , 1 ) ) ;
67+ close . call ( this , o , ... args ) ;
6968 } . bind ( ac , ac . close ) ;
7069 el . removeEventListener ( 'blur' , ac . _events . input . blur ) ;
7170 }
7271
73- const oninput = debounce ( function ( ) {
72+ const oninput = debounce ( ( ) => {
7473 const value = el . value . trim ( ) ;
7574 if ( ! options . trigger ( value ) ) {
7675 populate ( [ ] ) ;
@@ -95,9 +94,7 @@ function geoplete(el, options) {
9594
9695 function filterMatches ( result , value ) {
9796 value = new RegExp ( regExpEscape ( value ) , 'i' ) ;
98- return result . filter ( function ( entry ) {
99- return value . test ( entry ) ;
100- } ) ;
97+ return result . filter ( entry => value . test ( entry ) ) ;
10198 }
10299
103100 function matching ( lastValue , value , bounds ) {
@@ -110,7 +107,7 @@ function geoplete(el, options) {
110107 if ( lastValue . value . length > value . length ) {
111108 return ;
112109 }
113- if ( ! ( lastValue . result && lastValue . result . length ) ) {
110+ if ( ! lastValue . result ?. length ) {
114111 return ;
115112 }
116113 const result = options . filterMatches ( lastValue . result , value ) ;
@@ -146,13 +143,13 @@ function geoplete(el, options) {
146143 el . classList . add ( 'geoplete-in-progress' ) ;
147144 abortController = new AbortController ( ) ;
148145 const result = await geocode ( options . geoQuery ( params ) , { signal : abortController . signal } ) ;
149- if ( result && result . places ) {
146+ if ( result ? .places ) {
150147 lastValue . result = result . places . map ( fromPlace ) ;
151148 populate ( lastValue . result , result ) ;
152149 }
153150 } catch ( error ) {
154151 // ignore abort and timeout errors
155- if ( error . name !== " AbortError" && error . cause !== Symbol . for ( 'timeout' ) ) {
152+ if ( error . name !== ' AbortError' && error . cause !== Symbol . for ( 'timeout' ) ) {
156153 throw error ;
157154 }
158155 } finally {
0 commit comments