Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minisearch

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minisearch - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

dist/minisearch.js

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("minisearch",[],e):"object"==typeof exports?exports.minisearch=e():t.minisearch=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var s=e[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)n.d(i,s,function(e){return t[e]}.bind(null,s));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);class i{constructor(t,e=s){const n=t._tree,i=Object.keys(n);this.set=t,this.type=e,this.path=i.length>0?[{node:n,keys:i}]:[]}next(){const t=this.dive();return this.backtrack(),t}dive(){if(0===this.path.length)return{done:!0};const{node:t,keys:e}=c(this.path);return c(e)===u?{done:!1,value:this.result()}:(this.path.push({node:t[c(e)],keys:Object.keys(t[c(e)])}),this.dive())}backtrack(){0!==this.path.length&&(c(this.path).keys.pop(),c(this.path).keys.length>0||(this.path.pop(),this.backtrack()))}key(){return this.set._prefix+this.path.map(({keys:t})=>c(t)).filter(t=>t!==u).join("")}value(){return c(this.path).node[u]}result(){return this.type===o?this.value():this.type===r?this.key():[this.key(),this.value()]}[Symbol.iterator](){return this}}const s="ENTRIES",r="KEYS",o="VALUES",u="",c=function(t){return t[t.length-1]},h=function(t,e,n,i=0,s=d){const r=[{distance:0,ia:i,ib:0,edit:s}],o=[],u=[];for(;r.length>0;){const{distance:i,ia:s,ib:c,edit:h}=r.pop();if(o[s]=o[s]||[],!(o[s][c]&&o[s][c]<=i))if(o[s][c]=i,c!==e.length)if(t[s]===e[c])r.push({distance:i,ia:s+1,ib:c+1,edit:d});else{if(i>=n)continue;h!==l&&r.push({distance:i+1,ia:s,ib:c+1,edit:a}),s<t.length&&(h!==a&&r.push({distance:i+1,ia:s+1,ib:c,edit:l}),h!==a&&h!==l&&r.push({distance:i+1,ia:s+1,ib:c+1,edit:f}))}else u.push({distance:i,i:s,edit:h})}return u},d=0,f=1,l=2,a=3;var p=function(t,e,n){const i=[{distance:0,i:0,key:"",node:t}],s={};for(;i.length>0;){const{node:t,distance:r,key:o,i:c,edit:d}=i.pop();Object.keys(t).forEach(f=>{if(f===u){const i=r+(e.length-c),[,u]=s[o]||[null,1/0];i<=n&&i<u&&(s[o]=[t[f],i])}else h(e,f,n-r,c,d).forEach(({distance:e,i:n,edit:s})=>{i.push({node:t[f],distance:r+e,key:o+f,i:n,edit:s})})})}return s};class y{constructor(t={},e=""){this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw new Error("Mismatched prefix");const[e,n]=m(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,i]=_(n),s=Object.keys(e).find(t=>t!==u&&t.startsWith(i));if(void 0!==s)return new y({[s.slice(i.length)]:e[s]},t)}return new y(e||{},t)}clear(){delete this._size,this._tree={}}delete(t){return delete this._size,k(this._tree,t)}entries(){return new i(this,s)}forEach(t){for(let[e,n]of this)t(e,n,this)}fuzzyGet(t,e){return p(this._tree,t,e)}get(t){const e=b(this._tree,t);return void 0!==e?e[u]:void 0}has(t){const e=b(this._tree,t);return void 0!==e&&e.hasOwnProperty(u)}keys(){return new i(this,r)}set(t,e=!0){if("string"!=typeof t)throw new Error("key must be a string");return delete this._size,g(this._tree,t)[u]=e,this}get size(){return this._size?this._size:(this._size=0,this.forEach(()=>{this._size+=1}),this._size)}update(t,e){if("string"!=typeof t)throw new Error("key must be a string");delete this._size;const n=g(this._tree,t);return n[u]=e(n[u]),this}values(){return new i(this,o)}[Symbol.iterator](){return this.entries()}}y.from=function(t){const e=new y;for(let[n,i]of t)e.set(n,i);return e},y.fromObject=function(t){return y.from(Object.entries(t))};const m=function(t,e,n=[]){if(0===e.length)return[t,n];const i=Object.keys(t).find(t=>t!==u&&e.startsWith(t));return void 0===i?m(void 0,"",[...n,[t,e]]):m(t[i],e.slice(i.length),[...n,[t,i]])},b=function(t,e){if(0===e.length)return t;const n=Object.keys(t).find(t=>t!==u&&e.startsWith(t));return void 0!==n?b(t[n],e.slice(n.length)):void 0},g=function(t,e){if(0===e.length)return t;const n=Object.keys(t).find(t=>t!==u&&e.startsWith(t));if(void 0===n){const n=Object.keys(t).find(t=>t!==u&&t.startsWith(e[0]));if(void 0!==n){const i=v(e,n);return t[i]={[n.slice(i.length)]:t[n]},delete t[n],g(t[i],e.slice(i.length))}return t[e]={},t[e]}return g(t[n],e.slice(n.length))},v=function(t,e,n=0,i=Math.min(t.length,e.length),s=""){return n>=i?s:t[n]!==e[n]?s:v(t,e,n+1,i,s+t[n])},k=function(t,e){const[n,i]=m(t,e);if(void 0===n)return;delete n[u];const s=Object.keys(n);0===s.length&&O(i),1===s.length&&x(i,s[0],n[s[0]])},O=function(t){if(0===t.length)return;const[e,n]=_(t);delete e[n],0===Object.keys(e).length&&O(t.slice(0,-1))},x=function(t,e,n){if(0===t.length)return;const[i,s]=_(t);i[s+e]=n,delete i[s]},_=function(t){return t[t.length-1]};var j=y;const z="or";class w{constructor(t={}){this.options={...T,...t},this.options.searchOptions={...W,...this.options.searchOptions||{}};const{fields:e}=this.options;if(null==e)throw new Error('Option "fields" must be provided');this.index=new j,this.documentCount=0,this.documentIds={},this.fieldIds={},I(this,e)}add(t){const{tokenize:e,processTerm:n,fields:i,idField:s}=this.options;if(null==t[s])throw new Error(`Document does not have ID field "${s}"`);const r=S(this,t[s]);i.filter(e=>null!=t[e]).forEach(i=>{e(t[i]).forEach(t=>{E(this,this.fieldIds[i],r,n(t))})})}addAll(t){t.forEach(t=>this.add(t))}search(t,e={}){const{tokenize:n,processTerm:i,searchOptions:s}=this.options;e={...s,...e};const r=n(t).map(i).map(e.termToQuery).map(t=>this.executeQuery(t,e)),o=this.combineResults(r,e.combineWith);return Object.entries(o).map(([t,e])=>({id:this.documentIds[t],score:e})).sort(({score:t},{score:e})=>t<e?1:-1)}executeQuery(t,e={}){const n=(e={...this.options.defaultSearchOptions,...e}).fields||this.options.fields;if(!t.fuzzy&&!t.prefix)return M(this,n,this.index.get(t.term),e.boost);const i=[];if(t.fuzzy){const s=t.fuzzy<1?Math.round(t.term.length*t.fuzzy):t.fuzzy;Object.values(this.index.fuzzyGet(t.term,s)).forEach(([s,r])=>{t.prefix&&0===r||i.push(M(this,n,s,e.boost,r))})}return t.prefix&&this.index.atPrefix(t.term).forEach((s,r)=>{i.push(M(this,n,r,e.boost,s.length-t.term.length))}),i.reduce(C[z],{})}combineResults(t,e=z){if(0===t.length)return{};const n=e.toLowerCase();return t.reduce(C[n],null)}toJSON(){return{index:this.index,documentCount:this.documentCount,documentIds:this.documentIds,fieldIds:this.fieldIds}}toJS(){this.toJSON()}}w.loadJSON=function(t,e={}){return w.loadJS(JSON.parse(t),e)},w.loadJS=function(t,e={}){const{index:{_tree:n,_prefix:i},documentCount:s,documentIds:r,fieldIds:o}=t,u=new w(e);return u.index=new j(n,i),u.documentCount=s,u.documentIds=r,u.fieldIds=o,u},w.SearchableMap=j;const E=function(t,e,n,i){t.index.update(i,t=>{const i=(t=t||{})[e]||{df:0,ds:{}};return null==i.ds[n]&&(i.df+=1),i.ds[n]=(i.ds[n]||0)+1,{...t,[e]:i}})},S=function(t,e){const n=t.documentCount;return t.documentIds[n]=e,t.documentCount+=1,n},I=function(t,e){e.forEach((e,n)=>{t.fieldIds[e]=n})},M=function(t,e,n,i,s=0){return null==n?{}:e.reduce((e,r)=>{const{df:o,ds:u}=n[t.fieldIds[r]]||{ds:{}};return Object.entries(u).forEach(([n,u])=>{const c=((i||{})[r]||1)*(1/(1+.2*s));e[n]=(e[n]||0)+c*P(u,o,t.documentCount)}),e},{})},C={[z]:function(t,e){return Object.entries(e).reduce((t,[e,n])=>(t[e]=(t[e]||0)+n,t),t||{})},and:function(t,e){return null==t?e:Object.entries(e).reduce((e,[n,i])=>void 0===t[n]?e:(e[n]=Math.min(t[n],i),e),{})}},P=function(t,e,n){return t*Math.log(n/e)},T={idField:"id",tokenize:t=>t.split(/\W+/).filter(t=>t.length>1),processTerm:t=>t.toLowerCase()},W={termToQuery:t=>({term:t})};var J=w;n.d(e,"SearchableMap",function(){return j});e.default=J}]).default});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("minisearch",[],e):"object"==typeof exports?exports.minisearch=e():t.minisearch=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var s=e[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)n.d(i,s,function(e){return t[e]}.bind(null,s));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(1).default},function(t,e,n){"use strict";n.r(e);class i{constructor(t,e=s){const n=t._tree,i=Object.keys(n);this.set=t,this.type=e,this.path=i.length>0?[{node:n,keys:i}]:[]}next(){const t=this.dive();return this.backtrack(),t}dive(){if(0===this.path.length)return{done:!0};const{node:t,keys:e}=c(this.path);return c(e)===u?{done:!1,value:this.result()}:(this.path.push({node:t[c(e)],keys:Object.keys(t[c(e)])}),this.dive())}backtrack(){0!==this.path.length&&(c(this.path).keys.pop(),c(this.path).keys.length>0||(this.path.pop(),this.backtrack()))}key(){return this.set._prefix+this.path.map(({keys:t})=>c(t)).filter(t=>t!==u).join("")}value(){return c(this.path).node[u]}result(){return this.type===o?this.value():this.type===r?this.key():[this.key(),this.value()]}[Symbol.iterator](){return this}}const s="ENTRIES",r="KEYS",o="VALUES",u="",c=function(t){return t[t.length-1]},h=function(t,e,n,i=0,s=d){const r=[{distance:0,ia:i,ib:0,edit:s}],o=[],u=[];for(;r.length>0;){const{distance:i,ia:s,ib:c,edit:h}=r.pop();if(o[s]=o[s]||[],!(o[s][c]&&o[s][c]<=i))if(o[s][c]=i,c!==e.length)if(t[s]===e[c])r.push({distance:i,ia:s+1,ib:c+1,edit:d});else{if(i>=n)continue;h!==l&&r.push({distance:i+1,ia:s,ib:c+1,edit:a}),s<t.length&&(h!==a&&r.push({distance:i+1,ia:s+1,ib:c,edit:l}),h!==a&&h!==l&&r.push({distance:i+1,ia:s+1,ib:c+1,edit:f}))}else u.push({distance:i,i:s,edit:h})}return u},d=0,f=1,l=2,a=3;var p=function(t,e,n){const i=[{distance:0,i:0,key:"",node:t}],s={};for(;i.length>0;){const{node:t,distance:r,key:o,i:c,edit:d}=i.pop();Object.keys(t).forEach(f=>{if(f===u){const i=r+(e.length-c),[,u]=s[o]||[null,1/0];i<=n&&i<u&&(s[o]=[t[f],i])}else h(e,f,n-r,c,d).forEach(({distance:e,i:n,edit:s})=>{i.push({node:t[f],distance:r+e,key:o+f,i:n,edit:s})})})}return s};class y{constructor(t={},e=""){this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw new Error("Mismatched prefix");const[e,n]=m(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,i]=_(n),s=Object.keys(e).find(t=>t!==u&&t.startsWith(i));if(void 0!==s)return new y({[s.slice(i.length)]:e[s]},t)}return new y(e||{},t)}clear(){delete this._size,this._tree={}}delete(t){return delete this._size,v(this._tree,t)}entries(){return new i(this,s)}forEach(t){for(let[e,n]of this)t(e,n,this)}fuzzyGet(t,e){return p(this._tree,t,e)}get(t){const e=b(this._tree,t);return void 0!==e?e[u]:void 0}has(t){const e=b(this._tree,t);return void 0!==e&&e.hasOwnProperty(u)}keys(){return new i(this,r)}set(t,e=!0){if("string"!=typeof t)throw new Error("key must be a string");return delete this._size,g(this._tree,t)[u]=e,this}get size(){return this._size?this._size:(this._size=0,this.forEach(()=>{this._size+=1}),this._size)}update(t,e){if("string"!=typeof t)throw new Error("key must be a string");delete this._size;const n=g(this._tree,t);return n[u]=e(n[u]),this}values(){return new i(this,o)}[Symbol.iterator](){return this.entries()}}y.from=function(t){const e=new y;for(let[n,i]of t)e.set(n,i);return e},y.fromObject=function(t){return y.from(Object.entries(t))};const m=function(t,e,n=[]){if(0===e.length)return[t,n];const i=Object.keys(t).find(t=>t!==u&&e.startsWith(t));return void 0===i?m(void 0,"",[...n,[t,e]]):m(t[i],e.slice(i.length),[...n,[t,i]])},b=function(t,e){if(0===e.length)return t;const n=Object.keys(t).find(t=>t!==u&&e.startsWith(t));return void 0!==n?b(t[n],e.slice(n.length)):void 0},g=function(t,e){if(0===e.length)return t;const n=Object.keys(t).find(t=>t!==u&&e.startsWith(t));if(void 0===n){const n=Object.keys(t).find(t=>t!==u&&t.startsWith(e[0]));if(void 0!==n){const i=k(e,n);return t[i]={[n.slice(i.length)]:t[n]},delete t[n],g(t[i],e.slice(i.length))}return t[e]={},t[e]}return g(t[n],e.slice(n.length))},k=function(t,e,n=0,i=Math.min(t.length,e.length),s=""){return n>=i?s:t[n]!==e[n]?s:k(t,e,n+1,i,s+t[n])},v=function(t,e){const[n,i]=m(t,e);if(void 0===n)return;delete n[u];const s=Object.keys(n);0===s.length&&O(i),1===s.length&&x(i,s[0],n[s[0]])},O=function(t){if(0===t.length)return;const[e,n]=_(t);delete e[n],0===Object.keys(e).length&&O(t.slice(0,-1))},x=function(t,e,n){if(0===t.length)return;const[i,s]=_(t);i[s+e]=n,delete i[s]},_=function(t){return t[t.length-1]};var j=y;const z="or";class w{constructor(t={}){this.options={...T,...t},this.options.searchOptions={...W,...this.options.searchOptions||{}};const{fields:e}=this.options;if(null==e)throw new Error('Option "fields" must be provided');this.index=new j,this.documentCount=0,this.documentIds={},this.fieldIds={},I(this,e)}add(t){const{tokenize:e,processTerm:n,fields:i,idField:s}=this.options;if(null==t[s])throw new Error(`Document does not have ID field "${s}"`);const r=S(this,t[s]);i.filter(e=>null!=t[e]).forEach(i=>{e(t[i]).forEach(t=>{E(this,this.fieldIds[i],r,n(t))})})}addAll(t){t.forEach(t=>this.add(t))}search(t,e={}){const{tokenize:n,processTerm:i,searchOptions:s}=this.options;e={...s,...e};const r=n(t).map(i).map(e.termToQuery).map(t=>this.executeQuery(t,e)),o=this.combineResults(r,e.combineWith);return Object.entries(o).map(([t,e])=>({id:this.documentIds[t],score:e})).sort(({score:t},{score:e})=>t<e?1:-1)}executeQuery(t,e={}){const n=(e={...this.options.defaultSearchOptions,...e}).fields||this.options.fields;if(!t.fuzzy&&!t.prefix)return C(this,n,this.index.get(t.term),e.boost);const i=[];if(t.fuzzy){const s=t.fuzzy<1?Math.round(t.term.length*t.fuzzy):t.fuzzy;Object.values(this.index.fuzzyGet(t.term,s)).forEach(([s,r])=>{t.prefix&&0===r||i.push(C(this,n,s,e.boost,r))})}return t.prefix&&this.index.atPrefix(t.term).forEach((s,r)=>{i.push(C(this,n,r,e.boost,s.length-t.term.length))}),i.reduce(M[z],{})}combineResults(t,e=z){if(0===t.length)return{};const n=e.toLowerCase();return t.reduce(M[n],null)}toJSON(){return{index:this.index,documentCount:this.documentCount,documentIds:this.documentIds,fieldIds:this.fieldIds}}toJS(){this.toJSON()}}w.loadJSON=function(t,e={}){return w.loadJS(JSON.parse(t),e)},w.loadJS=function(t,e={}){const{index:{_tree:n,_prefix:i},documentCount:s,documentIds:r,fieldIds:o}=t,u=new w(e);return u.index=new j(n,i),u.documentCount=s,u.documentIds=r,u.fieldIds=o,u},w.SearchableMap=j;const E=function(t,e,n,i){t.index.update(i,t=>{const i=(t=t||{})[e]||{df:0,ds:{}};return null==i.ds[n]&&(i.df+=1),i.ds[n]=(i.ds[n]||0)+1,{...t,[e]:i}})},S=function(t,e){const n=t.documentCount;return t.documentIds[n]=e,t.documentCount+=1,n},I=function(t,e){e.forEach((e,n)=>{t.fieldIds[e]=n})},C=function(t,e,n,i,s=0){return null==n?{}:e.reduce((e,r)=>{const{df:o,ds:u}=n[t.fieldIds[r]]||{ds:{}};return Object.entries(u).forEach(([n,u])=>{const c=((i||{})[r]||1)*(1/(1+.2*s));e[n]=(e[n]||0)+c*P(u,o,t.documentCount)}),e},{})},M={[z]:function(t,e){return Object.entries(e).reduce((t,[e,n])=>(t[e]=(t[e]||0)+n,t),t||{})},and:function(t,e){return null==t?e:Object.entries(e).reduce((e,[n,i])=>void 0===t[n]?e:(e[n]=Math.min(t[n],i),e),{})}},P=function(t,e,n){return t*Math.log(n/e)},T={idField:"id",tokenize:t=>t.split(/\W+/).filter(t=>t.length>1),processTerm:t=>t.toLowerCase()},W={termToQuery:t=>({term:t})};e.default=w}]).default});
{
"name": "minisearch",
"version": "0.1.1",
"version": "0.1.2",
"description": "fun with fulltext search",

@@ -5,0 +5,0 @@ "main": "dist/minisearch.js",

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

import SearchableMap from './SearchableMap/SearchableMap.js'
import MiniSearch from './MiniSearch.js'
export { SearchableMap }
export default MiniSearch
module.exports = require('./MiniSearch.js').default
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc