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

meilisearch-filters

v1.0.1

Published

Expression builder for Meilisearch filters.

Downloads

65

Readme

npm version CI Workflow License: MIT

MeiliSearch Filters

This library allows you to build Meilisearch filters in your Javascript/Typescript projects, using a simple and fluent interface.

Examples:

import { field } from 'meilisearch-filters'

const filter = field('first_name').equals("Donald")
  .and(field('hair_color').isIn(['blond', 'orange']))
  .and(field('password').notEquals('covfefe'))
  .and(field('brain').isNull())

console.log(filter.toString()) // first_name = 'Donald' AND hair_color IN ['blond', 'orange'] AND password != 'covfefe' AND brain IS NULL

Installation

npm install meilisearch-filters --save # If you're using NPM
yarn add meilisearch-filters # If you're using Yarn

Usage

Comparison Filters

import { field } from 'meilisearch-filters'

`${field('cat').equals("Berlioz")}` // cat = 'Berlioz'
`${field('cat').notEquals("O'Malley")}` // cat != 'O\\'Malley'
`${field('age').isGreaterThan(5)}` // age > '5'
`${field('age').isGreaterThan(5, true)}` // age >= '5'
`${field('age').isNotGreaterThan(5)}` // age <= '5'
`${field('age').isNotGreaterThan(5, true)}` // age < '5'
`${field('age').isLowerThan(10)}` // age < '10'
`${field('age').isLowerThan(10, true)}` // age <= '10'
`${field('age').isNotLowerThan(10)}` // age >= '10'
`${field('age').isNotLowerThan(10, true)}` // age > '10'

Between Filter

import { field } from 'meilisearch-filters'

`${field('age').isBetween(5, 10)}` // age '5' TO '10'
`${field('age').isNotBetween(5, 10)}` // NOT age '5' TO '10'
`${field('age').isBetween(5, 10, false)}` // age > '5' AND age < '10'
`${field('age').isNotBetween(5, 10, false)}` // NOT (age > '5' AND age < '10')

Exists Filter

import { field } from 'meilisearch-filters'

`${field('god').exists()}` // god EXISTS
`${field('god').doesNotExist()}` // god NOT EXISTS

Empty Filter

import { field } from 'meilisearch-filters'

`${field('glass').isEmpty()}` // glass IS EMPTY
`${field('glass').isNotEmpty()}` // glass IS NOT EMPTY

Null Filter

import { field } from 'meilisearch-filters'

`${field('nullish').isNull()}` // nullish IS NULL
`${field('nullish').isNotNull()}` // nullish IS NOT NULL

IN Filter

import { field } from 'meilisearch-filters'

const cat = field('cat')
`${cat.isIn(['Berlioz', "O'Malley"])}` // cat IN ['Berlioz', 'O\\'Malley']
`${cat.isNotIn(['Berlioz', "O'Malley"])}` // cat NOT IN ['Berlioz', 'O\\'Malley']

Geographic filters

import { withinGeoRadius, notWithinGeoRadius } from 'meilisearch-filters'

`${withinGeoRadius(50.35, 3.51, 3000)}` // _geoRadius(50.35, 3.51, 3000)
`${notWithinGeoRadius(50.35, 3.51, 3000)}` // NOT _geoRadius(50.35, 3.51, 3000)
import { withinGeoBoundingBox, notWithinGeoBoundingBox } from 'meilisearch-filters'

`${withinGeoBoundingBox([50.55, 3], [50.52, 3.08])}` // _geoBoundingBox([50.55, 3], [50.52, 3.08])
`${notWithinGeoBoundingBox([50.55, 3], [50.52, 3.08])}` // NOT _geoBoundingBox([50.55, 3], [50.52, 3.08])

Composite filters

import { field } from 'meilisearch-filters'

const cat = field('cat')
const color = field('color')
const age = field('age')
`${cat.equals("Berlioz").and(age.between(5, 10))}` // cat = 'Berlioz' AND age '5' TO '10'
`${cat.equals("Berlioz").or(age.between(5, 10))}` // cat = 'Berlioz' OR age '5' TO '10'

// Automatic grouping
`${color.equals('ginger').or(cat.equals("Berlioz").and(age.between(5, 10)))}` // color = 'ginger' OR (cat = 'Berlioz' AND age '5' TO '10')

NOT filter

import { field, not } from 'meilisearch-filters'

const color = field('ginger')
`${not(color.equals('ginger'))}` // NOT color = 'ginger' 

Adding parentheses

import { field, group } from 'meilisearch-filters'

const color = field('ginger')
`${group(color.equals('ginger'))}` // (color = 'ginger') 

Instantiation

Without any filter

import { filterBuilder } from 'meilisearch-filters'

let filters = filterBuilder()
`${filters}` // ''
filters = filters.and(field('foo').equals('bar'))
`${filters}` // foo = 'bar'

With existing filters

import { filterBuilder } from 'meilisearch-filters'

let filters = filterBuilder(
  field('foo').equals('bar'), 
  field('fruit').equals('banana'),
  field('vegetable').equals('potato'),
)
`${filters}` // foo = 'bar' AND fruit = 'banana' AND vegetable = 'POTATO'

Tests

npm run test # If you're using NPM
yarn test # If you're using Yarn

License

MIT.