-
-
Save iqbmo04/002a075a2fa1c4c273c6f5da34348529 to your computer and use it in GitHub Desktop.
Javascript Function Annotations, can be used for anything. Enjoy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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