JSPM

  • Created
  • Published
  • Downloads 46
  • Score
    100M100P100Q65150F
  • License MIT

Source file preprocessor and comments remover for JavaScript in JavaScript

Package Exports

  • jspreproc

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jspreproc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

License Build Status npm Version Downloads by Month

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

  //#if DEBUG
  var fn = _cache[str]

  if (data && data._debug_) {
    if (!fn) fn = _create(str, 1)
    data._debug_ = 0
    var rs = typeof riot === 'undefined' ?
      '(riot undefined)' : JSON.stringify(riot.settings)
    console.error('--- DEBUG' +     // eslint-disable-line no-console
      '\n riot.settings: ' + rs + '\n data: ' + JSON.stringify(data))
  }
  else if (!fn)
    fn = _create(str)
  return fn.call(data, GLOBAL, logErr)
  //#endif

  // The expressions in the template were replaced with markers pointing to
  // functions in _cache.
  // Alone expressions, returns raw values, templates returns str with the
  // markers replaced with a string (empty for falsy values, except zero).
  // Shorthand list are evaluated by shList() and returns text, too.

  return (_cache[str] || (_cache[str] = _create(str))).call(data, GLOBAL, logErr)  // eslint-disable-line no-unreachable
}
// end of _tmpl

And want this?

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

Me too, so I write jspreproc, a tiny C-style source file preprocessor in JavaScript for JavaScript, with duplicate empty lines and comments remover.

NOTE:
Version 0.2.0-beta is an important update.
It has corrections to the implementation of the returned stream and the program logic. This allows for asynchronous use and freedom in handling errors with stream.on("error") code.

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 bash shells).

node.js

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

Parameter files can be an array, options is an object with the same options from command-line, but replace dashed options with camelCase properties: eol-type with eolType, and empty-lines with emptyLines.
jspp return value is a stream.PassThrough instance.

There is a package for bower, too.

Command-line

npm -g install jspreproc

jspreproc name for command-line interface is jspp

jspp [options] file1 file2 ...

Documentation

Read the CHANGELOG for recent additions and fixes, and the OPTIONS and SYNTAX guides in the doc folder (WIP).

Tip:

Clone the [jspreproc repository](from http://github.com/aMarCruz/jspreproc) and run npm i && npm t. You will find more usage examples in spec/app-spec.js

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.

TODOs

  • Better docs and tests
  • Read configuration values from the file system.

If you wish and have time, help me improving this page... English is not my best friend.


Coverity Scan Build Status Code Climate Dependency Status devDependency Status