Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Last active September 22, 2022 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nijikokun/6850355 to your computer and use it in GitHub Desktop.
Save nijikokun/6850355 to your computer and use it in GitHub Desktop.
Javascript Function Annotations, can be used for anything. Enjoy.
/*
* Javascript Annotations
*
* Maybe I am ahead of my time, or behind the times (asm.js).
* Either way, this is how they work (or could work) if you aren't afraid of some simple RegExp magic.
*
* @author Nijiko Yonskai
* @license MIT (or whatever college/license/name you prefer ;)
* @copyright 2013
*/
var Command = function (callback) {
var name;
var options = {};
var matches = groups(new RegExp('(?:\n[\ ]+|\{\n)"([^";]+)', 'g'), callback.prototype.constructor.toString());
for (var i = 0; i < matches.length; i++) {
var match = matches[i];
var value = match[1];
if (!value) return;
// Incase we get something like: "use asm" or "use strict";
// If you want to parse your own use script this would be the place.
if (value.indexOf("use ") != -1) return;
if (value.indexOf(":") != -1) {
var details = value.split(":");
var key = details[0];
var items = [];
if (details[1].indexOf(" ") != -1) {
items = details[1].split(" ");
} else if (details[1]) {
items.push(details[1]);
}
options[key] = items;
continue;
}
name = value;
};
Command._[name] = {
invoke: callback,
options: options
};
// Used for Debugging Purposes.
console.log(Command._);
};
Command._ = {};
Command(function (options) {
"reddit";
"amount:perPage offset";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment