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

hog-or

v1.3.1

Published

## Installation

Downloads

5

Readme

hog-or - primitive query parser and matcher

Installation

npm install --save hog-or
# OR
yarn add hog-or

What can I do with it?

  • You can write a field filter as path.to.field: value and it will match objects where string in path.to.field contains value
  • You can combine field filters by AND and OR (with standard operations order)
  • You can add NOT before a field name to match objects where field does not contains a value
  • You can use !@ as empty value alias, like path.to.field: !@ matches if path.to.field is empty (null, undefined, empty string, empty array)
  • You can have an object with array fields and it will be matched (see How to use)

Lower your expectations

  • hog-or creates RegExp to match, and hog-or does not encode input values (#1)
  • you can't escape empty value alias
  • hog-or does not support parentheses to change operations order
  • hog-or does not support Set and Map
  • Everything that is not a string will be converted to string by ${value}

How to use hog-or

import parseQuery from 'hog-or'

// we want to match objects where
// org.name contains 'google'
// OR
// list of tags includes tags with 'goo' and 'mind'
const query = parseQuery('org.name: google OR meta.tags.name: goo AND meta.tags.name: mind')
query.match({
  org: {
    name: 'Alphabet Inc.'
  },
  meta: {
    tags: [{ name: 'DeepMind' }, { name: 'Google' }] // yeah, nested array of objects
  }
}) // true, matched by tags

query.filter(listOfCompanies) // it returns IterableIterator
query.filterToArray(listOfCompanies) // it returns Array

// usage of NOT
const query2 = parseQuery('status: error AND NOT status: unknown')
query2.match({ status: 'error/data-parse' }) // true
query2.match({ status: 'error/timeout' }) // true
query2.match({ status: 'error/unknown' }) // false

Available options

caseSensitiveFields: boolean

Defines whether it should ignore case of field during getting value.

const organization = { orgName: 'Google Inc.' }
const caseSensitiveQuery = parseQuery('orgname: google', { caseSensitiveFields: true })
const caseInsensitiveQuery = parseQuery('orgname: google', { caseSensitiveFields: false })

caseSensitiveQuery.match(organization)   // false, because it requires field `orgname`,
                                         // but object has `orgName`
caseInsensitiveQuery.match(organization) // true

pathAliases: { [key: string]: string }

Defines aliases for paths.

const organization = { organization: { identity: { names: { title: Google Inc. } } } }
const simpleQuery = parseQuery('organization.identity.names.title: google')
const aliasedQuery = parseQuery('org: google', { pathAliases: { org: 'organization.identity.names.title' } })

For developers

Prerequisites

You need yarn at least v1.12.3. Well, you can use npm too, but all scripts bellow are for yarn.

Available scripts

# install dependencies
yarn

# run tests
yarn test

# run linter (with fix)
yarn lint

# build JS and type definitions
yarn build

VS code launch configuration

You may want to debug tests. Following launch configuration for VS code makes it possible

{
  "type": "node",
  "request": "launch",
  "name": "Mocha All",
  "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
  "args": [
    "-r",
    "ts-node/register",
    "--timeout",
    "999999",
    "--colors",
    "${workspaceFolder}/tests/**/*.spec.ts",
  ],
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "protocol": "inspector"
}