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

preprocessor

v1.4.0

Published

Preprocessor.js: A JavaScript source file preprocessor, e.g. to build different versions of a library.

Downloads

1,138

Readme

Preprocessor.js - A JavaScript preprocessor

Provides a JavaScript source file preprocessor, e.g. to build different versions of a library. It's for example used to build ProtoBuf.js (its build and main script are quite good examples).

Directives

  • Includes (always relative to the baseDirectory, defaults to "."):
...
// #include "path/to/file.js"
...
  • Static conditions:
// #ifdef FULL
console.log("Including extension");
// #include "path/to/extension.js"
// #else
console.log("Not including extension");
// #endif
  • Inverse static conditions:
// #ifndef FULL
console.log("Not including extension");
// #else
console.log("Including extension");
// #include "path/to/extension.js"
// #endif
  • Evaluable conditions:
// #if 1==2
console.log("1==2");
// #elif 2==2
console.log("2==2");
// #endif
  • Inline variables and functions:
// #define var PI=Math.PI
// #define function RADTODEG(x){return x*180/PI}
var angle = // #put RADTODEG(3)+";"
  • Writing the result of evaluated expressions:

    var version = // #put '"'+VERSION+'";"'
    var str = // #put "\"Hello world!\";"
    var onePlusOne = // #put (1+1)+";"

Features

  • CommonJS compatible
  • RequireJS/AMD compatible
  • Shim compatible (include the script, then use var ByteBuffer = dcodeIO.ByteBuffer;)
  • node.js compatible, also available via npm
  • Closure Compiler ADVANCED_OPTIMIZATIONS compatible (fully annotated, Preprocessor.min.js has been compiled this way, Preprocessor.min.map is the source map)
  • Fully documented using jsdoc3
  • Well tested through nodeunit
  • Zero production dependencies
  • Small footprint

Command line utility

Install via npm: npm -g install preprocessor

Command line

Usage: preprocess sourceFile [baseDirectory] [-myKey[=myValue], ...] [> outFile]

preprocess Source.js . -FULL=true > Source.full.js

API

The API is quite simple:

var result = new Preprocessor(
    mainFileSource,
    baseDirectoryOrIncludes
).process(defines);

with baseDirectoryOrIncludes being either a string containing the path to the base directory or an object of included sources by filename. When running in a browser, only the later is supported.

node.js / CommonJS

var Preprocessor = require("preprocessor");
var source = "..."; // e.g. through fs.readFile
var pp = new Preprocessor(source, ".");
console.log(pp.process({
    FULL: true
}));

RequireJS / AMD

require(["/path/to/Preprocessor.js"], function(Preprocessor) {
    var source = "..."; // e.g. through fs.readFile / $.ajax
    var pp = new Preprocessor(source, ".");
    console.log(pp.process({
        FULL: true
    }));
});

Browser / shim

Note: To use the #include directive in the browser, do not specify the base directory but an object of included sources by filename:

<script src="//raw.github.com/dcodeIO/Preprocessor.js/master/Preprocessor.min.js"></script>
var Preprocessor = dcodeIO.Preprocessor;
var source = "..."; // e.g. through. $.ajax
var pp = new Preprocessor(source, {
    "./includes/extension.js": "var myVar = 2;" // <- #include "includes/extension.js"
});
alert(pp.process({
    FULL: true
}));

Using includes instead of a base directory like shown in the example above is supported regardless of the platform you are on.

Downloads

Documentation

Tests (& Examples) Build Status

License

Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html