UNPKG

extract-search-index

Version:

Extract unique keyword input list string for search

11 lines (9 loc) 1.21 kB
/** * @name extract-search-index * @fileoverview Extract unique keyword input list string for search * @version 2.1.0 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/extract-search-index/} */ import{stripHtml as n}from"string-strip-html";import{unfancy as i}from"string-unfancy";var r="2.1.0";var a=r;function d(t){if(typeof t!="string")throw new Error(`extract-search-index: [THROW_ID_01] The input is not string! It was given as ${JSON.stringify(t,null,4)} (typeof is ${typeof t})`);return[...new Set(n(i(t.split("").map(e=>e.charCodeAt(0)<55291?e:" ").join("")),{stripTogetherWithTheirContents:["script","style","xml","code","pre"]}).result.toLowerCase().replace(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g,"").replace(/\.|,|;|:|"|\+|=|'|`|\^|\?|!|\/|\(|\)|{|}|>|<|#|-|–|—|\n|\r|\t|\[|\]|\d/g," ").split(/\s+/))].filter(e=>!["a","all","am","an","and","as","at","be","but","d","do","for","has","i","if","in","is","it","ll","me","my","no","not","of","off","on","or","s","so","to","up","ve","was","we","you","the"].includes(e)&&e.length>1).filter(e=>!e.includes("\\")).join(" ").trim()}export{d as extract,a as version};