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 🙏

© 2026 – Pkg Stats / Ryan Hefner

codematic

v0.2.0

Published

CLI Tools to handle smart QR and bar codes

Readme

Codematic

NPM

Purpose

Codematic is a tools that enables process automation by using barcodes or QR codes - or any type of code that can be entered through a scanning device.

Installation

Simply install via NPM:

npm install codematic

Usage

var options = {
  onInput: [
    {
      name: 'Test',
      input: '^X[0-9]+',
      action: {
        type: 'output',
        data: 'Sending code %CODE% to URL',
        then: {
          type: 'request',
          route: '/%CODE%',
          method: 'GET',
          200: {
            type: 'output',
            data: 'Success! Server response: %RESPONSE%'
            then: {
              type: 'myaction'
            }
          },
          500: {
            type: 'output',
            data: 'Ooops! Something went wrong here!'
          }
        }
      }
    }
  ],
  request: {
    url: 'http://testurl/'
  },
  log: {
    file: '/var/log/codematic.log'
  }
}

var codematic = new Codematic(options);

codematic.log = function(message) {
  // By overwriting the log function you can specify where you want to put your console output
  // Default is "console.log"
  console.log(message);
}

// Register the default actions (see documentation)
codematic.registerDefaultActions();

// Register a custom action
codematic.registerAction('myaction', function(action, callback) {
  this.log('This is a custom action');
  // If the callback is successful, the next "then" action will be called
  callback('success', action);

  // If something goes wrong, use the "error" callback to trigger the "error" action
  callback('error', action);
});

var code = 'X23434';

codematic.run(code, function() {
  console.log('Complete');
});

Options

Rules

As you can see in the example, it is very easy to define new rules. A rule consists of the following parameters:

  • A name to describe the rule
  • An input definition, which represents a regular expression that matches the expected code
  • An action sequence that will be executed when the code is entered

As you can see, an action sequence is chained through then and error callbacks. You can pass on parameters and substitute variables within strings.

Also, it is very easy to define your own action using the registerAction method.

Codematic ships with a set of default actions, documented below.

Log Setting

Defines the log settings. If log.file is set, all processed codes will be written to the specified log file including the date/time.

Request Settings

In order to make it easy to work with REST services, you can easily define a base URL as well as a standard username and password.

Events

onInput

Actions are executed on String input (e.g. when a barcode is scanned)

Parameters:

  • input: RegExp Regular expression to match against the input string

onFilechange

Watch files for changes

Parameters:

  • persistent: Boolean Indicates whether the process should continue to run as long as files are being watched. (default = true)
  • recursive: Boolean Indicates whether all subdirectories should be watched, or only the current directory. (default = false)
  • encoding: String File encoding (default = utf8)
  • filter: RegExp Return that matches the filter expression.
  • delay: Number, in ms Delay time of the callback function. (default = 100)
  • event: String Event type (update, remove, default = both)

onSchudule

Run actions in a specific interval

Parameters:

  • schedule: String Cron-like schedule syntax, see https://www.npmjs.com/package/node-schedule
*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (0 - 11)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

Default Actions

beep

Emits a "noise" through the default system speaker

Parameters:

  • count: Number of beeps (default: 1)
  • delay: Delay between beeps

store

Stores a value in a variable

Parameters:

  • var: Variable name
  • value: Variable value (default is the last code that has been scanned)

output

Writes a string to the console using the log method.

Parameters:

  • data: Output data
  • style: Output style (e.g. "danger", "success", "info")

writefile

Writes a file

Parameters:

  • filename: The filename
  • mode: "append" or "write" (default is "write")
  • data: The file data
  • var_source: Instead of using data, you can also specify a source variable

readfile

Reads a file and stores it to the local store

Parameters:

  • filename: The filename
  • var: Variable name (default is FILE)
  • encoding: File encoding (default is utf8)

clear

Clears a single slot or - if no variable is defined - all variable slots

Parameters:

  • var: Variable name

replace

Replace a string value

Parameters:

  • subject
  • pattern: Regular expression
  • replacement: Replacement value (default: "")
  • var: Variable name

exec

Executes an external program and stores the output to a variable

Parameters:

  • command: Command path
  • var: Variable name

request

Performs an HTTP request

Parameters:

  • url: The request URL
  • route: If you have configured a global base URL in the Codematic options, you can also define a single route instead of a full URL
  • method: GET, POST, PUT, DELETE (default is GET)
  • data: The form data object. Placeholders will be included for string values
  • var: The variable name for the response value (default is BODY)
  • filename: Optional sends response to a filename (e.g. for PDF documents)

There's also a special behavior for command chaining, since you can also use the response code to issue follow up commands (see sample config)

Sample Configuration

---
  ---
  request:
    url: https://cloud.zeyos.com/pepe/remotecall/barcodeapi
    username: ''
    password: ''
  log:
    error: log/error.log
    default: log/default.log
  onInput:
  - name: Test Request
    input: "^X[0-9]+"
    action:
      type: request
      route: "/"
      200:
        type: beep
        count: 5
        delay: 10
        then:
          type: output
          data: Value stored %testvar%
      500:
        type: output
        style: danger
        data: Request failed %BODY%
  - name: Store the barcode
    input: "^A[0-9]+"
    action:
      type: store
      var: testvar
      then:
        type: beep
        count: 5
        delay: 10
        then:
          type: output
          data: Value stored %testvar%
  - name: Scan new barcode for request
    input: "^R[0-9]+"
    action:
      type: writefile
      filename: test.txt
      mode: append
      data: Hallo %testvar%
      then:
        type: output
        data: File written
  - name: Check the wildcard
    input: ".*"
    action:
      type: store
      var: testvar
      then:
        type: output
        data: Value stored %testvar%
        then:
            type: request
            method: GET
            var: resp
            route: /%testvar%
            then:
              type: output
              data: Server response %resp%