├── .gitignore ├── tea.yaml ├── src └── autocomplete.js ├── test └── index.test.js ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Directories 2 | node_modules/ 3 | dist/ 4 | coverage/ 5 | .cache/ 6 | 7 | # Files 8 | .env 9 | .DS_Store -------------------------------------------------------------------------------- /tea.yaml: -------------------------------------------------------------------------------- 1 | # https://tea.xyz/what-is-this-file 2 | --- 3 | version: 1.0.0 4 | codeOwners: 5 | - '0x9BAac40A197bbb110ae5B2f31342D8d15D734832' 6 | - '0xC4C902Ada8DB1dDae5e7641E4c392C1abF0b785A' 7 | quorum: 1 8 | -------------------------------------------------------------------------------- /src/autocomplete.js: -------------------------------------------------------------------------------- 1 | class Autocomplete { 2 | constructor(data) { 3 | this.data = data; 4 | } 5 | 6 | search(query) { 7 | return this.data.filter(item => item.toLowerCase().includes(query.toLowerCase())); 8 | } 9 | } 10 | 11 | module.exports = Autocomplete; 12 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const Autocomplete = require('../src/autocomplete'); 3 | 4 | describe('Autocomplete', function () { 5 | it('should return matching items', function () { 6 | const data = ['apple', 'banana', 'orange', 'pineapple', 'grape']; 7 | const autocomplete = new Autocomplete(data); 8 | const result = autocomplete.search('ap'); 9 | 10 | assert.deepStrictEqual(result, ['apple', 'pineapple', 'grape']); 11 | }); 12 | 13 | it('should return empty array for no match', function () { 14 | const data = ['apple', 'banana', 'orange', 'pineapple', 'grape']; 15 | const autocomplete = new Autocomplete(data); 16 | const result = autocomplete.search('z'); 17 | 18 | assert.deepStrictEqual(result, []); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "onedionys-input-autocomplete", 3 | "version": "5.0.0", 4 | "description": "One Dionys (Input Autocomplete) - Functions to provide recommendations or auto-complete user input in forms.", 5 | "main": "src/autocomplete.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/onedionys/onedionys-input-autocomplete.git" 15 | }, 16 | "keywords": [ 17 | "onedionys", 18 | "tea", 19 | "package-manager", 20 | "input-autocomplete" 21 | ], 22 | "author": "One Dionys", 23 | "license": "ISC", 24 | "bugs": { 25 | "url": "https://github.com/onedionys/onedionys-input-autocomplete/issues" 26 | }, 27 | "homepage": "https://github.com/onedionys/onedionys-input-autocomplete#readme", 28 | "dependencies": { 29 | "@types/chai": "^4.3.12", 30 | "@types/mocha": "^10.0.6", 31 | "chai": "^5.1.0", 32 | "mocha": "^10.3.0" 33 | }, 34 | "devDependencies": { 35 | "chai": "^5.1.0", 36 | "mocha": "^10.3.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 ONE DIONYS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
Functions to provide recommendations or auto-complete user input in forms. 💖
4 | 5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |