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

simple-snippet-search

v1.0.0

Published

A simple search service that allows you search for quick code snippets

Downloads

5

Readme

Simple Snippet Search!

travis build code coverage

A simple search service that allows searching for quick code snippets, along with optional description of how the
piece of snippet works.

At the moment, it contains just some sample docker image snippets.

Adding more data sources

To add more data sources, simply create either a

  • .json file OR
  • module> directory containing several JSON files, e.g /file1.json, file2.json, ...

inside the .data directory. (Support for other data formats may be added later).

For example, to create a PHP data source, you can create a php.json file or a php directory
containing JSON files for different aspects of PHP.

During the API calls for searching, if a .json file is found, it will be searched;
otherwise, files inside / directory will be searched instead.

API calls are made to two endpoints:

  • The /modules endpoint (host:[port]/modules) to list available modules (e.g: php, docker, jenkins, java, etc).
    The server reads and returns every available module based on .json and directories.
    Modules can be filtered by appending an optional filter query string to the /modules endpoint to return
    only modules that match a specified filter text.
    Examples:

    • /modules?filter=d: will return only modules that contain the letter d.
    • /modules?filter=docker: will return only the docker module.
  • The /search/ endpoint allows you search within a given module. It supports a query query string that specifies the search term within the given module:
    Examples:

    • /search/docker?query=del: will return every docker command containing the letters del.
    • /search/docker?query=delete image: will return every docker command relating to deleting images (including dangling images).
    • /search/docker?query=delete dangling images: will return docker commands relevant to deleting dangling images only.

Response formats

The response format is JSON.

When a request is made to the /modules endpoint, the response is an object containing a modules property
which is an array of available modules, as determined by the files or directories inside the .data/ directory:

{  
    "modules": [  
        "jenkins",  
        "docker",  
        ...  
    ]  
}

When a search is performed - /search/?query= - the response is an object with a commands property containing example snippets for achieving the searched functionality. Results, i.e, .json data files, can be encoded as an object holding any of the following:

  • an array of strings
  • an object with properties: command and description
  • an array of objects, with each object having properties: command and description
  • Any combination of the above 3 formats (an array of strings and objects):
{
      "delete image": [
          "docker image rm <image>",
          "docker rmi <image>"
      ],
     "list images": {
      "command": "docker image ls [OPTIONS] [REPOSITORY[:TAG]]",
      "description": [
        "[Available Options]\n",
        "--all --all, -a - Show all images, including intermediate images\n",
        "--digests - Show digests\n",
        "--filter, -f - Filter output based on provided conditions\n",
        "--format - Pretty-print images using a Go template\n",
        "--no-trunc - Don't truncate output\n",
        "--quiet, -q - Only show numeric IDs"
      ]
     },
     "delete dangling images": [
       "docker image prune",
       {
         "command": "docker rmi $(docker images --quiet --filter \"dangling=true\")",
         "description": "Can also be written as: docker rmi $(docker images -q -f dangling=true)"
       },
       {
         "command": "docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi",
         "description": "Short form: docker images -qf dangling=true | xargs docker rmi"
       }
     ]
}

Run

  • Run with npm start (or node index.js)

Using the GUI (browser) client

  • Run with npm start (or node index.js)
  • Navigate to http(s)://HOST[:PORT]. The host and port can be configured in the /lib/config.json file. The defaults are: host:localhost, ports (http, https):
    • production: 5000, 5001
    • staging: 3000, 3001
    • testing: 4000, 4001

Tests

Run with npm run test (or node tests)