🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

svelte-fuzzy

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-fuzzy

Fuse.js binding for fuzzy text match highlighting.

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
53
120.83%
Maintainers
1
Weekly downloads
 
Created
Source

svelte-fuzzy

NPM

Fuse.js binding for fuzzy text match highlighting.

Installation

Yarn

yarn add -D svelte-fuzzy

NPM

npm i -D svelte-fuzzy

Usage

<script>
  import Fuzzy from "svelte-fuzzy";

  let query = "old";

  // Fuse.js options
  let options = { keys: ["title"] };

  // Fuse.js data
  let data = [
    {
      title: "Frankenstein; Or, The Modern Prometheus",
      author: "Mary Wollstonecraft Shelley",
    },
    {
      title: "A Christmas Carol in Prose; Being a Ghost Story of Christmas",
      author: "Charles Dickens",
    },
    { title: "Pride and Prejudice", author: "Jane Austen" },
    { title: "The Scarlet Letter", author: "Nathaniel Hawthorne" },
    { title: "Alice's Adventures in Wonderland", author: "Lewis Carroll" },
  ];

  let formatted = [];
</script>

<input bind:value={query} />

<br />

<button on:click={() => (query = "carol")}>Search "carol"</button>
<button on:click={() => (query = "")}>Clear</button>

<Fuzzy {query} {data} {options} bind:formatted />

{#each formatted as item}
  {#each item as line}
    <li>
      {#each line as { matches, text }}
        {#if matches}
          <mark>{text}</mark>
        {:else}
          {text}
        {/if}
      {/each}
    </li>
  {/each}
{/each}

Highlighter

You can use the Highlighter component for fuzzy text highlighting. Matching characters are wrapped in a mark element.

<script>
  import { Highlighter } from "svelte-fuzzy";
</script>

{#each formatted as item}
  {#each item as line}
    <li>
      <Highlighter {line} />
    </li>
  {/each}
{/each}

API

Props

Fuzzy

Prop nameValue
querystring (default: "")
dataFuzzyData (default: [])
optionsFuzzyOptions
resultFuzzyResult (default: [])
formattedFuzzyFormattedResult (default: [])

Highlighter

Prop nameValue
lineHighlighterLine (default: [])

TypeScript

Svelte version 3.31 or greater is required to use this component with TypeScript.

TypeScript definitions are located in the types folder.

Changelog

Changelog

License

MIT

Keywords

svelte

FAQs

Package last updated on 08 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts