Giter Site home page Giter Site logo

suggest.js's Introduction

suggest.js

Javascript autocorrect library built using jQuery.
Check out /example for a quick demo of suggest.js!

Use cases:

  • Dynamic dictionary search: Get definitions of words or search for words by definition.
  • Translation dictionary: Translate words, viewing definitions before choosing a suggestion.
  • Django ORM Schema Analysis
    • Configure help_text and verbose_name of fields into complex dictionary
    • Map from common names to database column names to facilitate easier queries
    • For example the Young Stellar Object Coral (YSOC) uses this module to map from names such as Spitzer to specific database names such as S3p6.

Dictionary format

// Simple dictionary
{'word': 'definition', ...} 
// Simple dictionary with arrays
{'word': ['def1', 'def2'], ...} 
// Complex/Translation dictionary
{'word': {'value': 'translated text', 
                         'help_text': 'definition text'},  ...  }   
// Complex dictionary with arrays 
{'word': [ {'value': 'text',  'help_text': 'text'},
           {'value': 'text', 'help_text': 'text'} ],  ... } 

API

/**
 * Make user_input have suggestions appear in suggest_div.
 *
 * @param {string} user_input -- $(selector) for input to add suggestions.
 * @param {string} suggest_div -- $(selector) where suggestions will go.
 * @param {string} delimiter -- Delimiter to tokenize words with.
 *     (Default is ' '.)
 *
 * @effect -- Adds suggest event handler to all appropriate inputs in
 *     $(user_input).
 */
suggest.add(user_input, suggest_div, delimiter);

/**
 * Adds a dictionary to suggestion dictionary.
 *
 * @param {Object} new_dict -- Object representing suggestion dictionary.
 *
 * @effect -- Adds the new_dict's key/value pairs to the current dictionary,
 *     overriding keys that appear in both dictionaries.
 */
suggest.updateDict(new_dict);

/**
 * Sets the suggestion dictionary, replacing the old one.
 *
 * @param {Object} new_dict -- Object representing suggestion dictionary.
 *
 * @effect -- Erases the current dictionary, and sets dict to the given
 *     dictionary.
 */
suggest.setDict(new_dict);

/**
 * Returns suggestion dictionary.
 *
 * @return {Object} -- Suggestion dictionary (Note this is a reference,
 *     not a copy, so any changes to the returned dictionary
 *     will be made to the suggest dictionary).
 */
suggest.getDict();

suggest.js's People

Contributors

dqu123 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

suggest.js's Issues

Module Logic

Currently, the module set-up is not very elegant. (Not checking for environment, etc.)

TODO

  • Check jQuery dependency and complain if not defined.
    • Possibly consider dropping jQuery dependency (for those legacy coders) ... if we get bored I suppose.
    • Alternatively, we can also consider converting this to a jQuery plugin if it is preferred. (A matter of whether supporting jQuery selector syntax is desired).
  • Make it so you can suggest.init() to set up API instances with different dictionaries
    • Alternatively, store a dictionary of dictionaries, and let suggest.add() have an option to pick which dictionary to configure with.

Security

I don't think there should be any security vulnerabilities from using this with a static dictionary,
or internally defined dictionary (making a searchable schema dictionary). However, there is the possibility for XSS right now if you let users define dictionary terms.

TODO

  • Escape html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.