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

c-format-stream

v0.0.21

Published

A Transform stream which formats C-like code.

Downloads

4

Readme

c-format-stream

A Transform stream to format C and C-like code. It's intended to work like clang-format, but it's a lot more opinionated (and, you'll find, somewhat dumber, although there are some cool benefits). It's mostly intended as a cleaning tool for preprocessors such as compp, but you'll find it also works well on its own if you need a standalone C formatter to plug into your other scripts. It scrubs the input with regex and then applies indentation and newlines as necessary.

Usage

Command-line

Install with npm install -g c-format-stream. The binary is named c-format.

$ c-format -h

  Usage: c-format INFILE [OUTFILE] [-hvni]

  INFILE should be "-" for stdin. OUTFILE defaults to stdout.

  -h show this help and exit
  -v show version number and exit
  -n number of newlines to preserve
  -i type of indentation string

  For the '-i' argument, strings of type 'sN', where N is some
  nonnegative integer, or 't' are accepted. The 'sN' type says
  to use N spaces for indentation, while 't' says to use tabs.

  Example: c-format test.c -n4 -is3

Node Module

var CFormatStream = require('c-format-stream');
var formattedStream = getReadableStreamSomehow().pipe(new CFormatStream({
  numNewlinesToPreserve: 3, // cuts off after this
                            // enter 0 to destroy all empty newlines
  indentationString: "\t"   // use tabs for indentation
}));

// fires when stream has no more data
formattedStream.on('end', function(){
  doSomethingWhenStreamIsDone();
});

// an error has occurred! >=(
formattedStream.on('error', function(err){
  doSomethingOnError(err);
});

As it inherits from the Transform stream interface, this stream can use both the standard readable and writable interfaces detailed in the node documentation.

Applications

This was written to help test compp, the preprocessor part of composter, a C compiler written in coffeescript. Both are in active development, so feel free to check out either of those two projects if you're interested in this one.

LICENSE

GPL v3