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

nomnoml-cli

v3.1.0

Published

Generates images from nomnoml diagram sources on the command line

Downloads

378

Readme

nomnoml-cli

Latest version Dependency status codecov Code Climate Codacy Badge

Generates images from nomnoml diagram sources on the command line and provides a library for a programmatic usage from NodeJS modules

Getting Started

Make sure that you have NodeJS >= 12 installed.

  1. Install pre-requisites of the node-canvas module depending on your operating system

  2. Install the command-line tool and generate a testing image:

npm install -g nomnoml-cli
echo '[nomnoml]is->[awesome]' | nomnoml > awesome.png

Read the documentation about the nomnoml source format

Command-Line Usage

The nomnoml script generates a png, jpg, svg or pdf image from the nomnoml source text. Both file names and standard input and output are supported as parameters. If generating the image fails, exit code 1 is returned to the caller.

$ nomnoml --help

  Usage: nomnoml [option]

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -i, --input <path>     file with nomnoml source to read from
    -o, --output <path>    file for the image output to write to
    -f, --format <format>  output format (png, jpg, svg, pdf)
    -w, --width <pixels>   width of the canvas to draw on
    -H, --height <pixels>  height of the canvas to draw on

  The default output format is png. The default canvas size is 640x480 pixels.
  If the input file is omitted, the source is read from the standard input.
  If the output file is omitted, the image is written to the standard output.

  Examples:

    $ echo '[nomnoml]is->[awesome]' | nomnoml > awesome.png
    $ nomnoml -i source.nomnoml -f svg -o target.svg

Programmatic Usage

The main module exports a function which generates the image:

const generateDiagram = require('nomnoml-cli');
const diagram = await generateDiagram(...);

The function returns a Promise to wait for a success or a failure.

The function expects a nomnoml source text as a string or an options object with the following supported properties:

  • input: source to read the nomnoml text from; either a Stream or a string with the actual nomnoml text
  • inputFile: source file path to read the nomnoml source from
  • output: target to write the image to; either a Stream or a string with the file path (undefined by default)
  • resultType: type of the object to resolve the promise with if the output parameter is not provided ('buffer' or 'stream'; the former is default)
  • format: output image format ('png', 'jpg', 'svg' or 'pdf'; the first is default)
  • width: canvas width in pixels (640 by default)
  • height: canvas height in pixels (480 by default)

Either input or inputFile has to be provided, otherwise the function fails. If output is not provided, the function resolves the promise with a Buffer containing the image. If output is provided, the function returns a promise resolved when the output has been written.

Code Samples

const generateDiagram = require('nomnoml-cli');

// Get Buffer with the image
const buffer = await generateDiagram('[nomnoml]is->[awesome]');

// Convert the standard input to standard output
await generateDiagram({
  input: process.stdin,
  output: process.stdout
});

// Create a PNG file from a nomnoml source file
await generateDiagram({
  inputFile: 'source.nomnoml',
  output: 'target.png'
});

Notes

Contents of other .nomnoml files can be imported to the input file using the #import directive. You can use it for sharing style definitions or parts of diagrams among multiple diagram sources.

#import: /usr/local/share/nomnoml/style.nomnoml
#import: shared/style.nomnoml
#import: ./sub-diagram.nomnoml

If the imported file path is relative and starts with ./ or ../, it will be appended to the path of the "parent" file, which the specified file is being imported to. Otherwise the relative path will be appended to the current (executing) directory.

File import directives are processed recursively. However, a single file can be imported only once. If imported once more, scond and other occurrences will be replaced by an empty string.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2015-2022 Ferdinand Prantl

Licensed under the MIT license.