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

jspreproc

v0.2.7

Published

C-Style source file preprocessor and comments remover for JavaScript

Downloads

135

Readme

Build Status Test Coverage npm Version Downloads by Month License

jspreproc

Do you have this?

/**
 * The exposed tmpl function returns the template value from the cache, render with data.
 * @param   {string} str  - Expression or template with zero or more expressions
 * @param   {Object} data - For setting the context
 * @returns {*} Raw expression value or template to render
 * @private
 */
function _tmpl(str, data) {
  if (!str) return str  // catch falsy values here

  //#if DEBUG
  if (data && data._debug_) {
    data._debug_ = 0
    if (!_cache[str]) {
      _cache[str] = _create(str, 1)  // request debug output
      var rs = typeof riot === 'undefined' ?
        '(riot undefined)' : JSON.stringify(riot.settings)
      console.log('--- DEBUG' +
        '\n riot.settings: ' + rs + '\n data: ' + JSON.stringify(data))
    }
  }
  //#endif

  // At this point, the expressions must have been parsed, it only remains to construct
  // the function (if it is not in the cache) and call it to replace expressions with
  // their values. data (`this`) is a Tag instance, logErr is the error handler.

  return (_cache[str] || (_cache[str] = _create(str))).call(data, logErr)
}
// end of _tmpl

And want this?

function _tmpl(str, data) {
  if (!str) return str
  return (_cache[str] || (_cache[str] = _create(str))).call(data, logErr)
}

Me too. This is why jspreproc, a tiny, C-Style source file preprocessor in JavaScript for JavaScript, with duplicate empty lines and comments remover.

Featuring many of the C preprocessor characteristics through JavaScript comments, jspreproc can be used in any source with a JavaScript-like syntax, even C# files with some limitations.

Important:

From version 0.2.1-beta.1 the location of jspp.js is the bin folder.

This is work in progress, so please update jspreproc constantly, I hope the first stable version does not take too long.

Install

You can install jspreproc with npm globally to use as the CLI tool, or locally for your project.
jspreproc works in node.js 0.10.0 or above (tested in Windows 7/8, cmd and sh shells).

Command-line

npm -g install jspreproc

jspreproc name for command-line interface is jspp

jspp [options] file1 file2 ...

Multiple files are concatenated into one, as if it had passed a file with multiple #include directives, one for each of the files listed.

If you don't list files, jspreproc reads from the standard input.
The result is written to the standard output, so it can be redirected.

Find more about the options in the documentation.

node.js

npm install jspreproc
var jspp = require('jspreproc')
var stream = jspp(files, options)

Parameter files can be an file name, an array of file names, or an instance of a readable stream. Options is an object with the same options from command-line.
jspp return value is a stream.PassThrough instance.

You can read about this API in the documentation.

There is a package for bower, too.

Documentation

This is a short example of basic syntax in files prepared for jspreproc:

//#include globals.inc
//#set DEBUG = 1

//#ifdef DEBUG
console.log(result)
//#endif

Find more in the Syntax guide.

Read the CHANGELOG for recent additions and fixes.
You can see jspreproc operation in the tests.

Please note: the documentation is very much a work in progress. Contributions are welcome.

Third-party tools & libraries

The following third-party tools and libraries are used by this project:

For regular use (dependencies installed by npm)

Development and code quality (devDependencies)

I'd like to thank all.

Known Issues

process.stdout fails (so jspreproc too) on console emulators for Windows, e.g. ConEmu and others, use clean Windows prompt or MSYS with mintty.

TODO

Maybe some day...

  • [x] ~~100% coverage (done)~~
  • [ ] Configuration from the file system. .jspreproc.json?
  • [ ] jspreproc reconfiguration through comments
  • [ ] #emit? for generating output of expression values
  • [ ] Better documentation
  • [ ] Explanatory error messages

Coverity Scan Build Status Code Climate Dependencies Development Dependencies