Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→extract-search-indexnext

extract-search-index2.2.1

Extract unique keyword input list string for search

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — EXTRACT()
  • API — VERSION
  • Changelog

Installation

Quick Take

Examples

  • Keep the first occurrence of each case-insensitive word
  • Strip HTML tags and decode entities
  • Normalise fancy punctuation and omit digits and emoji
  • Exclude code, preformatted text, and CSS from the index
  • Remove URLs and stop words from search-index text

Purpose

Search programs such as fuse.jsopens in a new tab work on a set of data, for example, it’s this list argument below:

const options = {
  keys: ["title", "author.firstName"],
};

const fuse = new Fuse(list, options);

// Change the pattern
const pattern = "";

return fuse.search(pattern);

What if you want to implement a search function which would search within large strings, let’s say blog articles?

It would be inefficient to bundle up raw article string, send it to user’s browser, initiate fuse.js there and perform a search.

It’s better to pre-format the sources — search function does not care about words present more than once; it does not care about letter case or article words.

This program prepares optimised strings to be consumed by the likes of fuse.js.

PS. Also, you might want to pre-indexopens in a new tab the list, to speed up the search, but that’s a separate thing.

API — extract()

The main function extract() is imported like this:

It’s a function which takes one input argument:

Input argumentTypeObligatoryDescription
str
Type: String
Obligatory: yes
strStringyesString to process

This function will return a string.

API — version

You can import version:

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab