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

homemade

v0.3.6

Published

C-like JS preprocessor

Downloads

39

Readme

homemade.js Homemade.js

Cozy C-like preprocessor. Implements include, exclude, define, put, if, elif, ifdef.

a. Use in console

node homemade.js path/to/source.js path/to/destination.js

b. Use with grunt ★

See grunt-homemade task.

API

Fully compatible with preprocessor.js syntax.

#exclude — removes fragments of code

Source:

//#exclude
console.log(a, b, c)
//#end

Result:

Useful when you want to remove supporting code from the build, like helper functions etc.

#include — inserts file

Source:

//#include ./c.js

c.js:

Hello world!

Result:

Hello world!

Files are inserted in a recursive way, so that inserted files will be handled also. The current directory . is taken one of the current file. The current file is that where the current #inline directive is.

#define — defines variable to use in preprocessor

Source:

//#define name = "Hello world"
//#define dictToArray = function(dict){ var result = []; for (var key in dict){ result.push(key + " " + dict[key]) }; return result; }

Defined variables can be used later in #put or #ifs.

#put — places variable source (uses tosource for serialization)

Source:

var projectName = //#put name
//#define a = {a:1, b:2, c:3}
//#put a;
//#put dictToArray(a);
//#put `var a = ` + projectName + `;`

Result:

var projectName = 'Hello world'
{a:1, b:2, c:3}
["a 1", "b 2", "c 3"]

To output raw code, use markdown inline code notation, like \raw code` + variable`

#if, #ifdef, #ifndef, #elif, #else

Source:

//#if DEV
	console.log("debug:", result)
//#else
	//#put "var projectName = '" + name + "'"
//#endif

Result with DEV === true:

	console.log("debug:", result)

Result with DEV === false:

	var projectName = 'Hello world'

For more examples see test/before.js.

jQuery/Zepto/vanilla plugin boilerplate

build.js:

(function($){
	//#ifndef pluginName
		var pluginName = "awesomePlugin"
	//#else
		/* #put `var pluginName = ` + pluginName */
	//#endif

	//#include "../src/utils.js"
	//#include "../src/AwesomePlugin.js"

	//jquery-plugin
	if ($){
		$['fn'][pluginName] = function (arg) {
			return this['each'](function(i,e){
				var $e = $(e);
				var instance = new AwesomePlugin($e[0], arg);
				$e.data(pluginName, instance);
			})
		};
	} else {
		window[pluginName] = AwesomePlugin;
	}
})(window['jQuery'] || window['Zepto']);

Motivation

This plugin was created as a fast replacement to preprocessor.js and alike, due to lack of necessary building features in them on that moment, like define, put etc.

For now homemade has some flaws:

  • Insecure − context is defined in global scope, so that you have to beware of variable names in #define
  • Nested conditions are not supported
  • No decent syntax errors detection

Projects which use homemade

License

Copyright Dmitry Ivanov. Written by Dmitry Ivanov. Licensed under the MIT license.