-
Notifications
You must be signed in to change notification settings - Fork 61
/
wade.min.js
6 lines (6 loc) · 2.57 KB
/
wade.min.js
1
2
3
4
5
6
/**
* Wade v0.3.3
* Copyright 2017 Kabir Shah
* Released under the MIT License
*/
!function(e,n){"object"==typeof module&&module.exports?module.exports=n():e.Wade=n()}(this,function(){var e={stopWords:["about","after","all","also","am","an","and","another","any","are","as","at","be","because","been","before","being","between","both","but","by","came","can","come","could","did","do","each","for","from","get","got","has","had","he","have","her","here","him","himself","his","how","if","in","into","is","it","like","make","many","me","might","more","most","much","must","my","never","now","of","on","only","or","other","our","out","over","said","same","see","should","since","some","still","such","take","than","that","the","their","them","then","there","these","they","this","those","through","to","too","under","up","very","was","way","we","well","were","what","where","which","while","who","with","would","you","your","a","i"],punctuationRE:/[.,!?:;"']/g},n=function(e,n){for(var r=n,o=0;o<e.length&&void 0!==(r=r[e[o]]);o++);return r},r=function(e,n,r,o){for(var t=null,i=0;i<e.length;i++){var a=e[i];void 0===(t=r[a])?(r[a]=n.length,n.push({index:a,score:o})):n[t].score+=o}},o=function(e,o,t,i,a){var u=n(e,o);void 0!==u&&void 0!==u.id&&r(u.id,t,i,a)},t=function(e,o,t,i,a){var u=n(e,o);if(void 0!==u)for(var h=[u],s=null,d=0;0!==h.length;){void 0!==(s=h[d]).id&&r(s.id,t,i,a),h.pop(),d--;for(var l in s)h.push(s[l]),d++}},i=function(e){var n=e.length-1;return" "===e[0]&&(e=e.substring(1))," "===e[n]&&(e=e.substring(0,n)),e.split(" ")},a=function(e){return e.toLowerCase()},u=function(n){return n.replace(e.punctuationRE,"")},h=function(e){for(var n=i(e),r=n.length;0!=r--;)-1!==s.config.stopWords.indexOf(n[r])&&n.splice(r,1);return n.join(" ")},s=function(e){var n=function(e){var r=n.index,a=s.process(e);if(!1===a)return[];for(var u=i(a),h=u.length,d=h-1,l=1/h,f=[],c={},v=0;v<d;v++)o(u[v],r,f,c,l);return t(u[d],r,f,c,l),f};if(Array.isArray(e)){for(var r=e.length,a=new Array(r),u=null,h=0;h<r;h++)!1!==(u=s.process(e[h]))&&(a[h]=u);n.index=s.index(a),n.data=a}else n.index=e.index,n.data=e.data;return n};return s.pipeline=[a,u,h],s.process=function(e){for(var n=s.pipeline,r=0;r<n.length;r++)e=n[r](e);return 0!==e.length&&e},s.index=function(e){for(var n={},r=0;r<e.length;r++){var o=e[r];if(void 0!==o)for(var t=i(o),a=0;a<t.length;a++){for(var u=t[a],h=u.length-1,s=n,d=0;d<h;d++){var l=u[d],f=s[l];f=void 0===f?{}:f,s[l]=f,s=f}var c=u[h];void 0===s[c]?s[c]={id:[r]}:void 0===(s=s[c]).id?s.id=[r]:s.id.push(r)}}return n},s.save=function(e){return{data:e.data,index:e.index}},s.config=e,s.version="0.3.3",s});