GithubHelp home page GithubHelp logo

andreashuetter / jspreproc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amarcruz/jspreproc

1.0 1.0 0.0 736 KB

C-Style source file preprocessor and comments remover for JavaScript in JavaScript

Home Page: http://amarcruz.github.io/jspreproc

License: MIT License

Makefile 0.09% JavaScript 99.91%

jspreproc's Introduction

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...

  • 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

jspreproc's People

Contributors

amarcruz avatar

Stargazers

Andreas Hütter avatar

Watchers

Andreas Hütter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.