Socket
Socket
Sign inDemoInstall

suggestions

Package Overview
Dependencies
2
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.1.0

CHANGELOG.md

2

dist/suggestions.js

@@ -1,1 +0,1 @@

!function t(e,i,n){function s(h,r){if(!i[h]){if(!e[h]){var a="function"==typeof require&&require;if(!r&&a)return a(h,!0);if(o)return o(h,!0);var l=new Error("Cannot find module '"+h+"'");throw l.code="MODULE_NOT_FOUND",l}var u=i[h]={exports:{}};e[h][0].call(u.exports,function(t){var i=e[h][1][t];return s(i?i:t)},u,u.exports,t,e,i,n)}return i[h].exports}for(var o="function"==typeof require&&require,h=0;h<n.length;h++)s(n[h]);return s}({1:[function(t,e,i){"use strict";function n(t,e,i){return new s(t,e,i)}var s=t("./src/suggestions");window.Suggestions=e.exports=n},{"./src/suggestions":4}],2:[function(t,e,i){function n(){for(var t={},e=0;e<arguments.length;e++){var i=arguments[e];for(var n in i)i.hasOwnProperty(n)&&(t[n]=i[n])}return t}e.exports=n},{}],3:[function(t,e,i){"Use strict";var n=function(t){return this.component=t,this.items=[],this.active=0,this.element=document.createElement("ul"),this.element.className="suggestions",t.el.parentNode.insertBefore(this.element,t.el.nextSibling),this};n.prototype.show=function(){this.element.style.display="block"},n.prototype.hide=function(){this.element.style.display="none"},n.prototype.add=function(t){this.items.push(t)},n.prototype.clear=function(){this.items=[],this.active=0},n.prototype.isEmpty=function(){return 0===this.element.children.length},n.prototype.draw=function(){if(this.element.innerHTML="",0===this.items.length)return void this.hide();for(var t=0;t<this.items.length;t++)this.drawItem(this.items[t],this.active===t);this.show()},n.prototype.drawItem=function(t,e){var i=document.createElement("li"),n=document.createElement("a");e&&(i.className+=" active"),n.innerHTML=this.component.highlight(t),i.appendChild(n),this.element.appendChild(i),i.addEventListener("mousedown",function(){this.handleMouseDown.call(this,t)}.bind(this))},n.prototype.handleMouseDown=function(t){this.component.value(t),this.clear(),this.draw()},n.prototype.move=function(t){this.active=t,this.draw()},n.prototype.previous=function(){this.move(0===this.active?this.items.length-1:this.active-1)},n.prototype.next=function(){this.move(this.active===this.items.length-1?0:this.active+1)},e.exports=n},{}],4:[function(t,e,i){"use strict";var n=t("xtend"),s=t("./list"),o=function(t,e,i){return i=i||{},this.options=n({minLength:2,limit:5},i),this.el=t,this.data=e||[],this.list=new s(this),this.query="",this.selected=null,this.list.draw(),this.el.addEventListener("keyup",function(t){this.handleKeyUp.call(this,t.keyCode)}.bind(this),!1),this.el.addEventListener("keydown",function(t){this.handleKeyDown.call(this,t)}.bind(this)),this.el.addEventListener("focus",function(){this.handleFocus.call(this)}.bind(this)),this.el.addEventListener("blur",function(){this.handleBlur.call(this)}.bind(this)),this.update=function(t){this.data=t,this.handleKeyUp.call(this)}.bind(this),this};o.prototype.handleKeyUp=function(t){return 40!==t&&38!==t&&27!==t&&13!==t&&9!==t?(this.query=this.filter(this.el.value),this.list.clear(),this.query.length<this.options.minLength?void this.list.draw():void this.getCandidates(function(t){for(var e=0;e<t.length&&(this.list.add(t[e]),this.options.limit===!1||e!==this.limit);e++);this.list.draw()}.bind(this))):void 0},o.prototype.handleKeyDown=function(t){var e=t.keyCode;switch(e){case 13:this.list.isEmpty()||(this.value(this.list.items[this.list.active]),this.list.hide());break;case 27:case 9:this.list.isEmpty()||this.list.hide();break;case 38:this.list.previous();break;case 40:this.list.next()}},o.prototype.handleBlur=function(){this.list.hide()},o.prototype.handleFocus=function(){this.list.isEmpty()||this.list.show()},o.prototype.filter=function(t){return t=t.toLowerCase()},o.prototype.match=function(t){return t.indexOf(this.query)>-1},o.prototype.value=function(t){if(this.selected=t,this.el.value=this.getItemValue(t),document.createEvent){var e=document.createEvent("HTMLEvents");e.initEvent("change",!0,!1),this.el.dispatchEvent(e)}else this.el.fireEvent("onchange")},o.prototype.getCandidates=function(t){for(var e=[],i=0;i<this.data.length;i++){var n=this.getItemValue(this.data[i]);this.match(this.filter(n))&&e.push(this.data[i])}t(e)},o.prototype.getItemValue=function(t){return t},o.prototype.highlight=function(t){return this.getItemValue(t).replace(new RegExp("^("+this.query+")","ig"),function(t,e){return"<strong>"+e+"</strong>"})},e.exports=o},{"./list":3,xtend:2}]},{},[1]);
!function t(e,i,n){function s(o,h){if(!i[o]){if(!e[o]){var a="function"==typeof require&&require;if(!h&&a)return a(o,!0);if(r)return r(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var l=i[o]={exports:{}};e[o][0].call(l.exports,function(t){var i=e[o][1][t];return s(i?i:t)},l,l.exports,t,e,i,n)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;o<n.length;o++)s(n[o]);return s}({1:[function(t,e,i){"use strict";function n(t,e,i){return new s(t,e,i)}var s=t("./src/suggestions");window.Suggestions=e.exports=n},{"./src/suggestions":5}],2:[function(t,e,i){!function(){var t=this,n={};"undefined"!=typeof i?e.exports=n:t.fuzzy=n,n.simpleFilter=function(t,e){return e.filter(function(e){return n.test(t,e)})},n.test=function(t,e){return null!==n.match(t,e)},n.match=function(t,e,i){i=i||{};var n,s=0,r=[],o=e.length,h=0,a=0,u=i.pre||"",l=i.post||"",c=i.caseSensitive&&e||e.toLowerCase();t=i.caseSensitive&&t||t.toLowerCase();for(var d=0;o>d;d++)n=e[d],c[d]===t[s]?(n=u+n+l,s+=1,a+=1+a):a=0,h+=a,r[r.length]=n;return s===t.length?{rendered:r.join(""),score:h}:null},n.filter=function(t,e,i){return i=i||{},e.reduce(function(e,s,r,o){var h=s;i.extract&&(h=i.extract(s));var a=n.match(t,h,i);return null!=a&&(e[e.length]={string:a.rendered,score:a.score,index:r,original:s}),e},[]).sort(function(t,e){var i=e.score-t.score;return i?i:t.index-e.index})}}()},{}],3:[function(t,e,i){function n(){for(var t={},e=0;e<arguments.length;e++){var i=arguments[e];for(var n in i)i.hasOwnProperty(n)&&(t[n]=i[n])}return t}e.exports=n},{}],4:[function(t,e,i){"Use strict";var n=function(t){return this.component=t,this.items=[],this.active=0,this.element=document.createElement("ul"),this.element.className="suggestions",t.el.parentNode.insertBefore(this.element,t.el.nextSibling),this};n.prototype.show=function(){this.element.style.display="block"},n.prototype.hide=function(){this.element.style.display="none"},n.prototype.add=function(t){this.items.push(t)},n.prototype.clear=function(){this.items=[],this.active=0},n.prototype.isEmpty=function(){return 0===this.element.children.length},n.prototype.draw=function(){if(this.element.innerHTML="",0===this.items.length)return void this.hide();for(var t=0;t<this.items.length;t++)this.drawItem(this.items[t],this.active===t);this.show()},n.prototype.drawItem=function(t,e){var i=document.createElement("li"),n=document.createElement("a");e&&(i.className+=" active"),n.innerHTML=t.string,i.appendChild(n),this.element.appendChild(i),i.addEventListener("mousedown",function(){this.handleMouseDown.call(this,t)}.bind(this))},n.prototype.handleMouseDown=function(t){this.component.value(t),this.clear(),this.draw()},n.prototype.move=function(t){this.active=t,this.draw()},n.prototype.previous=function(){this.move(0===this.active?this.items.length-1:this.active-1)},n.prototype.next=function(){this.move(this.active===this.items.length-1?0:this.active+1)},e.exports=n},{}],5:[function(t,e,i){"use strict";var n=t("xtend"),s=t("fuzzy"),r=t("./list"),o=function(t,e,i){return i=i||{},this.options=n({minLength:2,limit:5},i),this.el=t,this.data=e||[],this.list=new r(this),this.query="",this.selected=null,this.list.draw(),this.el.addEventListener("keyup",function(t){this.handleKeyUp(t.keyCode)}.bind(this),!1),this.el.addEventListener("keydown",function(t){this.handleKeyDown(t)}.bind(this)),this.el.addEventListener("focus",function(){this.handleFocus()}.bind(this)),this.el.addEventListener("blur",function(){this.handleBlur()}.bind(this)),this};o.prototype.handleKeyUp=function(t){return 40!==t&&38!==t&&27!==t&&13!==t&&9!==t?(this.query=this.normalize(this.el.value),this.list.clear(),this.query.length<this.options.minLength?void this.list.draw():void this.getCandidates(function(t){for(var e=0;e<t.length&&(this.list.add(t[e]),e!==this.options.limit-1);e++);this.list.draw()}.bind(this))):void 0},o.prototype.handleKeyDown=function(t){switch(t.keyCode){case 13:case 9:this.list.isEmpty()||(this.value(this.list.items[this.list.active].original),this.list.hide());break;case 27:this.list.isEmpty()||this.list.hide();break;case 38:this.list.previous();break;case 40:this.list.next()}},o.prototype.handleBlur=function(){this.list.hide()},o.prototype.handleFocus=function(){this.list.isEmpty()||this.list.show()},o.prototype.update=function(t){this.data=t},o.prototype.normalize=function(t){return t=t.toLowerCase()},o.prototype.match=function(t,e){return t.indexOf(e)>-1},o.prototype.value=function(t){if(this.selected=t,this.el.value=this.getItemValue(t),document.createEvent){var e=document.createEvent("HTMLEvents");e.initEvent("change",!0,!1),this.el.dispatchEvent(e)}else this.el.fireEvent("onchange")},o.prototype.getCandidates=function(t){var e={pre:"<strong>",post:"</strong>",extract:function(t){return this.getItemValue(t)}.bind(this)},i=s.filter(this.query,this.data,e);t(i)},o.prototype.getItemValue=function(t){return t},e.exports=o},{"./list":4,fuzzy:2,xtend:3}]},{},[1]);
{
"name": "suggestions",
"version": "1.0.3",
"version": "1.1.0",
"description": "A typeahead component for inputs",
"main": "index.js",
"scripts": {
"start": "budo index.js --serve=dist/suggestions.js --live -d | bistre",
"start": "budo index.js --serve=dist/suggestions.js --live -d",
"build": "browserify index.js | uglifyjs -c -m > dist/suggestions.js",

@@ -29,5 +29,4 @@ "lint": "eslint --no-eslintrc -c .eslintrc index.js src",

"devDependencies": {
"bistre": "^1.0.1",
"browserify": "^12.0.1",
"budo": "^5.1.5",
"budo": "^7.0.2",
"documentation": "^3.0.0",

@@ -41,4 +40,5 @@ "eslint": "^1.7.3",

"dependencies": {
"fuzzy": "^0.1.1",
"xtend": "^4.0.0"
}
}

@@ -56,3 +56,3 @@ 'Use strict';

a.innerHTML = this.component.highlight(item);
a.innerHTML = item.string;

@@ -59,0 +59,0 @@ li.appendChild(a);

'use strict';
var extend = require('xtend');
var fuzzy = require('fuzzy');
var List = require('./list');

@@ -24,15 +25,15 @@

this.el.addEventListener('keyup', function(e) {
this.handleKeyUp.call(this, e.keyCode);
this.handleKeyUp(e.keyCode);
}.bind(this), false);
this.el.addEventListener('keydown', function(e) {
this.handleKeyDown.call(this, e);
this.handleKeyDown(e);
}.bind(this));
this.el.addEventListener('focus', function() {
this.handleFocus.call(this);
this.handleFocus();
}.bind(this));
this.el.addEventListener('blur', function() {
this.handleBlur.call(this);
this.handleBlur();
}.bind(this));

@@ -79,3 +80,3 @@

if (!this.list.isEmpty()) {
this.value(this.list.items[this.list.active]);
this.value(this.list.items[this.list.active].original);
this.list.hide();

@@ -149,11 +150,10 @@ }

Suggestions.prototype.getCandidates = function(callback) {
var items = [];
var options = {
pre: '<strong>',
post: '</strong>',
extract: function(d) { return this.getItemValue(d); }.bind(this)
};
for (var i = 0; i < this.data.length; i++) {
var candidate = this.getItemValue(this.data[i]);
if (this.match(this.normalize(candidate), this.query)) {
items.push(this.data[i]);
}
}
callback(items);
var results = fuzzy.filter(this.query, this.data, options);
callback(results);
};

@@ -171,15 +171,2 @@

/**
* Intercept an item from the results list & highlight the portion in the result
* string that matches the query
*
* @param {String} item an item that qualifies as a result from the data array
* @return {String} A formated string (HTML allowed).
*/
Suggestions.prototype.highlight = function(item) {
return this.getItemValue(item).replace(new RegExp(this.query, 'ig'), function($1) {
return '<strong>' + $1 + '</strong>';
});
};
module.exports = Suggestions;

@@ -20,3 +20,3 @@ 'use strict';

input.value = 'bear';
input.value = 'ear';

@@ -23,0 +23,0 @@ var keyUpEvent = document.createEvent('HTMLEvents');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc