npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ss-search

v1.12.0

Published

The most basic, yet powerful text search.

Downloads

5,030

Readme

npm npm bundle size build Coveralls github Commitizen friendly semantic-release

s(imply)s(tupid)-search

The most basic, yet powerful text search.

Stop searching, start finding.

  • Ease of Use: Get appropriate results instantly without any configuration.
  • Local Array Search: Effortlessly search through a local array of objects.
  • Automatic Indexing: No manual indexing required.
  • Precision: Always get exactly what you're looking for.
  • Lightweight: Depends on just 5 lodash functions for a minimized size after tree shaking.

Demo

Still not convinced? Experience its power firsthand with this interactive demo.

Benchmark

How does it compare to other search libraries? Test out for yourself with this interactive benchmark ;)

Install

ss-search is available on npm. Install it with:

npm install ss-search

Usage

Basic

import { search } from 'ss-search'

const data = [
  {
    number: 1,
    text: 'A search function should be fast',
  },
  {
    number: 2,
    text: 'A search function should provide accurate results',
  },
]
const searchKeys = ['text']
const searchText = 'fast search'

const results = search(data, searchKeys, searchText)
// results: [{ number: 1, text: "A search function should be fast" }]

It's that straightforward. No configurations, it just works.

Data Types

Almost all data types are supported [boolean, number, string, object, array].

// This dataset will be used as a common starting point for our type examples
const data = [
  {
    boolean: true,
    number: 1,
    string: 'search',
    object: { nestedProperty: 'nested value' },
    array: ['value1', 'value2'],
    arrayObjects: [{ arrayObjectProperty: 'array object value' }],
  },
]

Boolean

const results = search(data, ['boolean'], 'true')
// results: will return our original dataset

Number

const results = search(data, ['number'], '1')
// results: will return our original dataset

String

const results = search(data, ['string'], 'search')
// results: will return our original dataset

Object

Providing a key which refers to an object will stringify that object using JSON.stringify

const results = search(data, ['object'], 'property')
// results: will return our original dataset as it matches the property key "nestedProperty" of our object

If you want to access a nested property of an object to extract only a single value

const results = search(data, ['object.nestedProperty'], 'property')
// results: will return an empty array as we extracted the value of our nested object
// if we had searched for "nested value" we would of had the original dataset

Array

Providing a key which refers to an array will stringify that array using JSON.stringify

const results = search(data, ['array'], 'value2')
// results: will return our original dataset

If you have an array of objects on which you want to search all properties

const results = search(data, ['arrayObjects'], 'arrayObjectProperty')
// results: will return an our original dataset as it's treated just like a regular array
// thus the arrayObjectProperty is part of the searchable text

If you have an array of objects where you want only specific properties to be searchable

const results = search(data, ['arrayObjects[arrayObjectProperty]'], 'arrayObjectProperty')
// results: will return an empty array as we extracted the value of our nested array of objects
// if we had searched for "value object" we would of had the original dataset

Options for the search function

Customize your search experience using the following options:

| Option parameter | Value | Description | | ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | withScore | true | When set to true, the search function will return an array of objects, each containing the matched element and its corresponding score. The score represents how closely the element matches the search text, with a higher score indicating a closer match. Even if the search doesn't match, it will return a score of 0. | | withScore | false | When set to false or not provided, the function will return an array of matched elements without their scores. |

Example Usage

Without withScore option:

const data = [{ name: 'John' }, { name: 'Jane' }, { name: 'Doe' }]
const result = search(data, ['name'], 'John')
console.log(result) // [{ name: 'John' }]

With withScore option:

const data = [{ name: 'John' }, { name: 'Jane' }, { name: 'Doe' }]
const result = search(data, ['name'], 'John', { withScore: true })
console.log(result)
// [
//  { element: { name: 'John' }, score: 1 },
//  { element: { name: 'Jane' }, score: 0 },
//  { element: { name: 'Doe' }, score: 0 }
// ]

Developing

To better manage dependencies across the monorepo I'm using NX.

Install dependencies: npm i

Start the web-app: npm run web-app:serve

Test the library: npm run test:all