npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

effortless-complete

v1.1.3

Published

Input autocompletion made simple

Downloads

21

Readme

Effortless-Complete

Node JS library for simplifying user input autocompletion. Simple, fast and allows for custom styling.

Installation

NPM:

$ npm install effortless-complete

or

CDN:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js"></script>

Features

  • Custom styling
  • Simple
  • Implement autocompletion in a few lines
  • Typescript declarations included

Links

Usage

Functions

Import the library:

import {autoComplete, autoCompleteHref} from "effortless-complete"

autoComplete() function, takes a config object and is used to do basic autocompletion:

const config = {
  suggestionContainer: // Takes a div element in which the autocomplete suggestions are going to be displayed. You have to create this one yourself
  data: // Takes an array of strings, that will serve as reference.
  inputElement: // Takes an input element
  clickAction: // Is an optional property. It takes a function that contains an argument, which will be ran after you click on a certain suggestion.
  filtering: // Takes a string: 'all' or 'starts'. This property defines, which suggestions are going to be shown. More on this lower.
};
autoComplete(config);

'all' parameter: filters the suggestions that includes the user input.

'starts' parameter: filters the suggestions that starts with the user input.

clickAction Takes a function that has one argument.

function doSomething(suggestion) {
  console.log(suggestion);
};

The textContent of the clicked suggestion will be assigned to it.

autoCompleteHref() function takes config too, but it's used to assign a url to a suggestion:

const config = {
 suggestionContainer: // Takes a div element in which the autocomplete suggestions are going to be displayed.
 data: // Takes an array of objects, that contain url and an item. More on this lower.
 inputElement: // Takes an input element
 clickAction: // Works the same as in autoComplete() function shown previously
 filtering: // Takes a string: 'all' or 'starts'. This property defines, which suggestions are going to be shown. More on this lower.
};
autoCompleteHref(config);

The array that serves as a reference should look like this:

const data = [
 {
   item: "groceries"
   link: "https://www.example.com/groceries"
 },
 {
   item: "electronics"
   link: "https://www.example.com/electronics"
 }
];

You can define it as long as you want, but keep this format.

Now if you click on a suggestion it will redirect you to the url that you specified.

Styling

You can style it as you want. The class name for the suggestions inside the your div is "suggestionElement".

Example

let  inputElement = document.getElementById('inputElement');
const  suggestionContainer = document.getElementById('suggestionsContainer');
let  selectedSuggestion: string;

const  config = {
  suggestionContainer:  suggestionContainer,
  data:  kaufland,
  inputElement:  inputElement,
  filtering:  'all',
  selectedSuggestionsVar:  selectedSuggestion
};

autoComplete(config);

https://github.com/Adam-Simon1/Effortless-Complete/assets/134161057/98bcfe44-2b53-4cae-8ecd-ede2651da06d

This is an example i made. It uses a long array i extracted from my database. It's for a project i am working on.

Typescript declarations

The npm module already includes a declarations file.