@itrocks/autocomplete 0.0.10 → 0.1.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.
Files changed (2) hide show
  1. package/autocomplete.js +6 -3
  2. package/package.json +1 -1
package/autocomplete.js CHANGED
@@ -46,7 +46,7 @@ export class AutoComplete {
46
46
  return;
47
47
  const input = this.input;
48
48
  const suggestion = this.suggestions.selected();
49
- idInput.value = (input.value === suggestion?.caption)
49
+ idInput.value = (suggestion && (toInsensitive(input.value) === toInsensitive(suggestion.caption)))
50
50
  ? '' + suggestion.id
51
51
  : '';
52
52
  }
@@ -58,9 +58,9 @@ export class AutoComplete {
58
58
  const summaryRoute = dataFetch + (input.value ? ('?startsWith=' + input.value) : '');
59
59
  fetch(summaryRoute, requestInit).then(response => response.text()).then(json => {
60
60
  const summary = JSON.parse(json).map(([id, caption]) => ({ caption, id: +id }));
61
- const startsWith = input.value.toLowerCase();
61
+ const startsWith = toInsensitive(input.value);
62
62
  const suggestions = startsWith.length
63
- ? summary.filter(item => item.caption.toLowerCase().startsWith(startsWith))
63
+ ? summary.filter(item => toInsensitive(item.caption).startsWith(startsWith))
64
64
  : summary;
65
65
  this.suggestions.update(suggestions);
66
66
  if (!['Backspace', 'Delete'].includes(lastKey)) {
@@ -299,3 +299,6 @@ class Suggestions {
299
299
  }
300
300
  }
301
301
  }
302
+ function toInsensitive(text) {
303
+ return text.normalize('NFD').replace(/\p{M}+/gu, '').toLowerCase();
304
+ }
package/package.json CHANGED
@@ -40,5 +40,5 @@
40
40
  },
41
41
  "type": "module",
42
42
  "types": "./autocomplete.d.ts",
43
- "version": "0.0.10"
43
+ "version": "0.1.0"
44
44
  }