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

boox-cli

v1.0.0

Published

A command-line interface (CLI) for training and searching Boox datasets.

Downloads

163

Readme

Boox CLI

A command-line interface (CLI) for training and searching Boox datasets.

Installation

Install boox-cli globally using npm or yarn:

npm install -g boox-cli

# Or

yarn global add boox-cli

Usage

Training

To train a Boox dataset, use the train command:

boox-cli train <source> [destination] [options]
  • <source>: The path to your dataset file (JSON format).
  • [destination]: (Optional) The path where the trained data will be saved. Defaults to the current directory.

Options:

  • -i, --id <field>: The field in your dataset objects that uniquely identifies each document (default: 'id').
  • -f, --features <fields...>: The fields to index for search (multiple fields can be specified).
  • -a, --attributes <fields...>: The fields to include as-is without indexing (multiple fields can be specified).
  • -d, --deflate: Compress the trained data as .dat file (default: false).
  • -c, --cwd <folder>: The working directory (default: current directory).
  • -r, --rcname <name>: The name of the Boox configuration file (default: 'boox').

Example:

boox-cli train data/products.json -f title description -a price

This command will train a Boox dataset from the data/products.json file, indexing the title and description fields for search and including the price field as-is. The trained data will be saved as a compressed .gz file.

Searching

To search a trained Boox dataset, use the search command:

boox-cli search <source> <query> [options]
  • <source>: The path to the trained dataset file (.dat or .gz).
  • <query>: The search query string.

Options:

  • -o, --offset <number>: The offset for pagination (default: '1').
  • -l, --length <number>: The number of results per page (default: '10').
  • -k, --context <field>: Display the context instead of paginated results object.
  • -a, --attrs <fields...>: Fields to display when --context is provided.
  • -d, --deflate: Assume the trained data is deflated as .dat file (default: false).
  • -c, --cwd <folder>: The working directory (default: current directory).
  • -r, --rcname <name>: The name of the Boox configuration file (default: 'boox').

Example:

boox-cli search data/products-trained.gz "shoes" -o 2 -l 20

This command will search the data/products-trained.gz dataset for documents containing the word "shoes", starting from the second page and displaying 20 results per page.

Using configuration file

You can create a Boox configuration file in your project's root directory to specify default options for the boox-cli train and boox-cli search commands:

  • .booxrc
  • .booxrc.json
  • .booxrc.{yaml,yml}
  • .boox.{mjs,cjs,js}
  • boox.config.{mjs,cjs,js}

Before using the example below, make sure to install the required libraries:

npm install -D double-metaphone stemmer stopword marked marked-plaintify

Here's an example of a Boox configuration file:

// boox.config.js
import { doubleMetaphone } from 'double-metaphone'
import { Marked } from 'marked'
import markedPlaintify from 'marked-plaintify'
import { stemmer } from 'stemmer'
import { removeStopwords } from 'stopword'

const marked = new Marked({ gfm: true }).use(markedPlaintify())
const wordRegexp = /\b\w+\b/g

/** @type {() => import('boox').BooxOptions} */
export default function defineBooxConfig() {
  return {
    id: 'customId',
    features: ['title', 'content', 'tags'],
    attributes: ['author', 'date'],
    modelOptions: {
      normalizer(input) {
        // Remove Markdown formatting
        return marked.parse(input)
      },
      tokenizer(input) {
        const tokens = Array.from(input.match(wordRegexp) || [])
        return removeStopwords(tokens)
      },
      stemmer: stemmer,
      phonetic: doubleMetaphone
    }
  }
}

The --rcname flag allows you to customize the name of the configuration file. For example, to use a configuration file named my-appname.config.js, you would run the following command:

boox-cli train src/dataset.json --rcname my-appname