0.3.0 • Published 7 years ago

slim-bot v0.3.0

Weekly downloads
11
License
ISC
Repository
github
Last release
7 years ago

##Slim-bot

Module for adding command features to an input field

Attaches an event listener to the provided input element. When prefix is entered, input gets .console-mode class and starts listening for commands

##Installation

npm install slim-bot

##Usage

HTML

<!-- Element to listen to -->
<input type="text" id="input-element" />

CSS

/* Class that gets applied when input enters console-mode */
.console-mode {
    background-color: lightred;
}

JS

// Import Tokenize from slim-bot
const Tokenize = require('slim-bot');

// Define HTMLInputElement
const inputElement = document.getElementById('input-element');

// Define commands
const myCommands = {
  'open': {
      params: ['Enter a URL or path'],
      operation: function(path) {
          window.open(path);
      }
  },
  'backgroundColor': {
      params: ['Enter a hex code'],
      operation: function(color) {
          document.body.style.backgroundColor = color;
      }
  },
  'big': {
      params: [],
      operation: function() {
          input.blur();
          input.classList.add('big');
          setTimeout(function() {
            input.classList.remove('big');
            input.focus();
          }, 1000);
      }
   }
};

// Instantiate Tokenize
const slimBot = new Tokenize({
    commands: myCommands,
    element: inputElement,
    prefix: '/'
});

##Demo Play around with the demo git clone https://github.com/daviddiefenderfer/slim-bot.git && cd slim-bot/demo && npm start

App served at localhost:8080

0.3.0

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago