Skip to content

Commit 6ccd136

Browse files
committed
Merge remote-tracking branch 'origin/biome'
2 parents 36857e0 + f6318b7 commit 6ccd136

File tree

7 files changed

+133
-92
lines changed

7 files changed

+133
-92
lines changed

.jshintrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

Makefile

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
NODE_BIN=./node_modules/.bin
2-
SRC = index.js $(wildcard lib/*.js)
3-
41
check: lint test
52

6-
node_modules: package.json
7-
yarn
8-
touch $@
3+
lint:
4+
./node_modules/.bin/biome ci
5+
6+
format:
7+
./node_modules/.bin/biome check --fix
98

10-
lint: | node_modules
11-
$(NODE_BIN)/jshint $(SRC) test
9+
test:
10+
node --test $(TEST_OPTS)
1211

13-
test: | node_modules
14-
node --test
12+
test-cov: TEST_OPTS := --experimental-test-coverage
13+
test-cov: test
1514

16-
.PHONY: lint check test
15+
.PHONY: check format lint test test-cov

biome.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
3+
"assist": {
4+
"actions": {
5+
"source": {
6+
"organizeImports": "on"
7+
}
8+
}
9+
},
10+
"vcs": {
11+
"enabled": true,
12+
"clientKind": "git",
13+
"useIgnoreFile": true
14+
},
15+
"files": {
16+
"ignoreUnknown": true
17+
},
18+
"formatter": {
19+
"enabled": true,
20+
"useEditorconfig": true,
21+
"lineWidth": 120
22+
},
23+
"javascript": {
24+
"formatter": {
25+
"quoteStyle": "single",
26+
"trailingCommas": "none",
27+
"arrowParentheses": "asNeeded"
28+
}
29+
},
30+
"json": {
31+
"formatter": {
32+
"expand": "always"
33+
}
34+
},
35+
"linter": {
36+
"enabled": true,
37+
"rules": {
38+
"recommended": true,
39+
"correctness": {
40+
"noUndeclaredVariables": "error",
41+
"noUnusedVariables": "error"
42+
},
43+
"complexity": {
44+
"noForEach": "off"
45+
},
46+
"style": {
47+
"noParameterAssign": "off",
48+
"useDefaultParameterLast": "error",
49+
"useSingleVarDeclarator": "error",
50+
"noUnusedTemplateLiteral": "error",
51+
"useNumberNamespace": "error",
52+
"noUselessElse": "error"
53+
},
54+
"performance": {
55+
"noDelete": "off"
56+
},
57+
"suspicious": {
58+
"noAssignInExpressions": "off"
59+
}
60+
}
61+
}
62+
}

demo/index.js

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,21 @@ const keys = {
1111
};
1212

1313
function geocoder(name) {
14-
const g = {
15-
order: [name]
14+
return {
15+
order: [name],
16+
[`${name}_key`]: keys[name],
17+
[`${name}_parameters`]: { interval: 1000 },
18+
[`${name}_enable`]: () => true
1619
};
17-
g[name + '_key'] = keys[name];
18-
g[name + '_parameters'] = { interval : 1000 };
19-
g[name + '_enable'] = () => true;
20-
return g;
2120
}
2221

23-
const geocoderAddress = [
24-
'geocodio',
25-
'graphhopper',
26-
'locationiq',
27-
'opencage',
28-
'pelias',
29-
'positionstack'
30-
].find(name => keys[name]);
31-
32-
const geocoderPlace = [
33-
'maptiler',
34-
'graphhopper',
35-
'locationiq',
36-
'opencage',
37-
'pelias',
38-
'positionstack'
39-
].find(name => keys[name]);
22+
const geocoderAddress = ['geocodio', 'graphhopper', 'locationiq', 'opencage', 'pelias', 'positionstack'].find(
23+
name => keys[name]
24+
);
25+
26+
const geocoderPlace = ['maptiler', 'graphhopper', 'locationiq', 'opencage', 'pelias', 'positionstack'].find(
27+
name => keys[name]
28+
);
4029

4130
const result = document.getElementById('result');
4231
function onchange(event) {
@@ -55,6 +44,6 @@ geoplete(address, { type: 'address', geocoder: geocoder(geocoderAddress) });
5544
function item(text) {
5645
const v = text.value;
5746
const li = document.createElement('li');
58-
li.innerHTML = '<mark>' + (v.place || '') + '</mark> <em>' + v.address + '</em>';
47+
li.innerHTML = `<mark>${v.place || ''}</mark> <em>${v.address}</em>`;
5948
return li;
6049
}

lib/geoplete.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ const debounce = require('debounce');
44

55
module.exports = geoplete;
66

7-
/* global AbortController */
8-
97
const 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

3032
function 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 {

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"email": "pirxpilot@furkot.com",
88
"url": "https://pirxpilot.com"
99
},
10-
"repository": "github:furkot/geoplete",
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/furkot/geoplete.git"
13+
},
1114
"license": "ISC",
1215
"keywords": [
1316
"geoplete",
@@ -20,7 +23,7 @@
2023
"debounce": "^1.1.0||^2.0.0"
2124
},
2225
"devDependencies": {
23-
"@pirxpilot/jshint": "~3",
26+
"@biomejs/biome": "2.0.5",
2427
"jsdom": "~24",
2528
"jsdom-global": "~3"
2629
},

test/geoplete.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const assert = require('node:assert/strict');
33

44
const geoplete = require('../');
55

6-
describe('geoplete', function () {
6+
describe('geoplete', () => {
77
before(function () {
88
this.jsdom = require('jsdom-global')();
99
});
@@ -12,7 +12,7 @@ describe('geoplete', function () {
1212
this.jsdom();
1313
});
1414

15-
beforeEach(function () {
15+
beforeEach(() => {
1616
document.body.innerHTML = '<input id="test" type="text">';
1717
});
1818

@@ -22,7 +22,7 @@ describe('geoplete', function () {
2222

2323
it('attach', function () {
2424
const input = document.getElementById('test');
25-
const ac = this.ac = geoplete(input);
25+
const ac = (this.ac = geoplete(input));
2626

2727
assert.ok(ac, 'should create autocomplete object');
2828
});
@@ -54,25 +54,30 @@ describe('geoplete', function () {
5454
assert.fail();
5555
}
5656
},
57-
synchronous_enable() { return true; }
57+
synchronous_enable() {
58+
return true;
59+
}
5860
}
5961
});
6062
input.value = 'san franc';
61-
input.dispatchEvent(new Event('input', {
62-
'bubbles': true,
63-
'cancelable': true
64-
}));
65-
setTimeout(function () {
63+
input.dispatchEvent(
64+
new Event('input', {
65+
bubbles: true,
66+
cancelable: true
67+
})
68+
);
69+
setTimeout(() => {
6670
input.value = 'san franci';
67-
input.dispatchEvent(new Event('input', {
68-
'bubbles': true,
69-
'cancelable': true
70-
}));
71-
setTimeout(function () {
71+
input.dispatchEvent(
72+
new Event('input', {
73+
bubbles: true,
74+
cancelable: true
75+
})
76+
);
77+
setTimeout(() => {
7278
assert.equal(count, 1);
7379
done();
7480
}, 500);
7581
}, 500);
7682
});
7783
});
78-

0 commit comments

Comments
 (0)