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
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)
var rs = typeof riot === 'undefined' ?
'(riot undefined)' : JSON.stringify(riot.settings)
console.log('--- DEBUG' +
'\n riot.settings: ' + rs + '\n data: ' + JSON.stringify(data))
return _cache[str].call(data, logErr)
}
}
//#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) // eslint-disable-line no-unreachable
}
// end of _tmplAnd want this?
function _tmpl(str, data) {
if (!str) return str
return (_cache[str] || (_cache[str] = _create(str))).call(data, GLOBAL, 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:
This is work in progress, so please update jspreproc constantly, I hope that the first stable version does not take too long.
From version 0.2.1-beta.1 the location of jspp.js is the bin folder, and there's a new file jspp.cmd for Windows users can run jspp from the root folder of jspreproc, useful in local installations.
From version 0.2.0-beta.5 there's no default indentation for included files.
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).
Command-line
npm -g install jspreprocjspreproc 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 output is written to standard output of the system, so it can be redirected.
Learn about the options in the documentation.
node.js
npm install jspreprocvar 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, 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.
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
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)
- Jasmine by Pivotal Labs, my favorite testing framework, does not rely on other frameworks
- jasmine-spec-reporter by Bastien Caudan, pretty console spec reporter for jasmine
- istanbul by Krishnan Anantheswaran, for generating coverage information
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.
TODOs
Maybe some day...
- 100% coverage (almost done)
- Configuration from the file system.
.jspreproc.json? - jspreproc reconfiguration through comments
#emit? for generating output of expression values- Better documentation
Please note: the documentation is very much a work in progress. Contributions are welcome.