1.9.0 • Published 8 months ago

ss-search v1.9.0

Weekly downloads
180
License
-
Repository
github
Last release
8 months ago

npm npm bundle size Travis (.org) Coveralls github Commitizen friendly semantic-release

s(imply)s(tupid)-search

The most basic, yet powerful text search.

Stop searching, start finding.

  • Easy to use; will return you appropriate results out of the box, no need to configure anything
  • Search local array of objects as easily as never before
  • Automatic indexing
  • Will return exactly what you are looking for
  • Very small size; only depends on 5 lodash functions which are extracted using rollup, which means we have a zero dependency library

Demo

npm.io

If you're not convinced yet, take a look at this interactive demo.

Install

ss-search is available on npm. It can be installed with the following command:

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" }]

Yes. It is that simple, no need to configure anything, it works out of the box.

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 

Benchmark

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

npm.io

Developing

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

The following command will install lerna (and other depedencies) and install the depedencies of all the packages of the repository.

npm i && npx lerna bootstrap --hoist

Commit format

To make things easier for all contributors, I'm using commitizen to enforce compatible commit messages with semantic-release. Also, to make sure it is enforced, I'm using husky to easily add validation hooks. When you run git commit you will be prompted with an interactive CLI to help you with the formatting of your commit message.

TLDR: making a contribution is easy peasy and you cannot go wrong ;)

1.8.2

8 months ago

1.9.0

8 months ago

1.8.1

8 months ago

1.8.0

8 months ago

1.7.0

12 months ago

1.8.3

8 months ago

1.6.2

2 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.21

4 years ago

1.5.20

4 years ago

1.5.19

4 years ago

1.5.18

4 years ago

1.5.12

4 years ago

1.5.11

4 years ago

1.5.14

4 years ago

1.5.13

4 years ago

1.5.16

4 years ago

1.5.15

4 years ago

1.5.17

4 years ago

1.5.10

4 years ago

1.5.9

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.3

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.5.0

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.2.2

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago