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

ninprint

v0.0.3

Published

Finding those ninja characters: Utility for printing human-readable special characters

Downloads

8

Readme

What is it?

ninprint is a utility for printing human-readable special characters.

Are you ever working with binary or string data that contains special characters (NUL, CR, LF, etc)? Unfortunately standard print commands (echo, printf, console.log, etc) will not display special characters, making it difficult to determine exactly where they exist in a string. ninprint makes your life easy by printing out a human-readable form of each character.

Installation

ninprint requires NodeJS and NPM/Yarn.

NPM

npm install -g ninprint

Yarn

yarn global add ninprint

Examples

You can pipe output from other processes into ninprint:

$ printf "From pipe: \0\r\n" | ninprint

F r o m [SPACE] p i p e : [SPACE] [NUL] [CR] [LF]

Pipe in files:

$ printf "From file: \b\f\t" > test.bin
$ ninprint < test.bin

F r o m [SPACE] f i l e : [SPACE] [BS] [FF] [TAB]

Pass a string as an argument:

$ ninprint "Test"

T e s t

Bash requires $'abc' syntax for escape characters:

$ ninprint $'Test\r\n'

T e s t [CR] [LF]

Note: ninprint $'Test\0\r\n' will terminate after Test because of the \0 null character.

Options

  • -f, --format [type]:

    Set the output format. Format types are:

    • default:

      Print zero-width special characters and spaces using their abreviated form. Print all other characters as is.

      $ printf "Test \0\r\n" | ninprint -f default
      
      T e s t [SPACE] [NUL] [CR] [LF]
    • escape:

      Print common C-style escape sequences. Print all other characters as default.

      Supported escape sequence characters are: | Character | Escape | | --------- |--------| | [NUL] | \0 | | [BEL] | \a | | [BS] | \b | | [TAB] | \t | | [LF] | \n | | [VT] | \v | | [FF] | \f | | [CR] | \r | | [ESC] | \e |

      $ printf "Test \0\r\n" | ninprint -f escape
      
      T e s t [SPACE] \0 \r \n
    • octal-escape:

      Print all characters using their octal escape sequence.

      $ printf "Test \0\r\n" | ninprint -f octal-escape
      
      \124 \145 \163 \164 \40 \0 \15 \12
    • hex-escape:

      Print all characters using their hexadecimal escape sequence.

      $ printf "Test \0\r\n" | ninprint -f hex-escape
      
      \x54 \x65 \x73 \x74 \x20 \x0 \xD \xA
    • hex:

      Print all characters in hexadecimal.

      $ printf "Test \0\r\n" | ninprint -f hex
      
      54 65 73 74 20 00 0D 0A
    • octal:

      Print all characters in octal.

      $ printf "Test \0\r\n" | ninprint -f octal
      
      124 145 163 164 040 000 015 012
    • binary:

      Print all characters in binary.

      $ printf "Test \0\r\n" | ninprint -f binary
      
      01010100 01100101 01110011 01110100 00100000 00000000 00001101 00001010
  • -s, --separator [value]:

    Set the string that separates output values. Default is ' ' (space)

      $ printf "Test \0\r\n" | ninprint -s ...
    
      T...e...s...t...[SPACE]...[NUL]...[CR]...[LF]
      $ printf "Test \0\r\n" | ninprint -s $'\n'
    
      T
      e
      s
      t
      [SPACE]
      [NUL]
      [CR]
      [LF]
  • -S:

    Don't separate output values (equivalent to -s '')

      $ printf "Test \0\r\n" | ninprint -S
    
      Test[SPACE][NUL][CR][LF]
      $ printf "Test \0\r\n" | ninprint -f escape -S
    
      Test[SPACE]\0\r\n
      $ printf "Test \0\r\n" | ninprint -f hex -S
    
      5465737420000D0A

Node Module

You can also use ninprint as a Node/Webpack module.

NPM

npm install ninprint

Yarn

yarn add ninprint

Examples

You can print directly to the console:

const { print } = require("ninprint");

print("Hello world.");
// Output:
//     H e l l o [SPACE] w o r l d .

print("Line feed:\n");
// Output:
//     L i n e [SPACE] f e e d : [LF]

You can use convert to return a string:

const { convert } = require("ninprint");

const test1 = convert("Carriage return:\r");
console.log(test1);
// Output:
//     C a r r i a g e [SPACE] r e t u r n : [CR]

const test2 = convert("Null character:\0");
console.log(test2);
// Output:
//     N u l l [SPACE] c h a r a c t e r : [NUL]

You can also pass a Buffer to print/convert:


const { print, convert } = require("ninprint");

print(new Buffer([0x00, 0x01, 0x02, 0x03, 0x04, 0x05]));
// Output:
//     [NUL] [SOH] [STX] [ETX] [EOT] [ENQ]

const test3 = convert(new Buffer([0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B]));
console.log(test3);
// Output:
//     [ACK] [BEL] [BS] [TAB] [LF] [VT]

Options

print and convert both take an options object as a second parameter.

const { print, convert, Format } = require("ninprint");

print("Test\0\r\n", {
  format: Format.DEFAULT,
  separator: " "
});

const test1 = convert("Test\0\r\n", {
  format: Format.ESCAPE,
  separator: ""
});

Possible options are:

  • format:

    The output format. Possible format types are:

    • Format.DEFAULT
    • Format.ESCAPE
    • Format.OCTAL_ESCAPE
    • Format.HEX_ESCAPE
    • Format.HEX
    • Format.OCTAL
    • Format.BINARY

    Where: { Format } = require("ninprint")

    See format in the CLI options for explanations of each format type.

  • separator:

    The string that separates output values. Default is " " (space)

    See separator in the CLI options for examples.

License

MIT