Skip to content

Instantly share code, notes, and snippets.

@YurySolovyov
Last active March 27, 2016 21:12
Show Gist options
  • Save YurySolovyov/d6395fb5fa811d722578 to your computer and use it in GitHub Desktop.
Save YurySolovyov/d6395fb5fa811d722578 to your computer and use it in GitHub Desktop.
"use strict";
var stringifyArray = function(array) {
return array.map(String).join(', ');
};
module.exports = function(firstArg) {
var key;
var localArgs;
var i;
// TODO: Add regex support
if (arguments.length === 1 || arguments.length === 0) {
key = String(firstArg);
} else {
localArgs = [];
for (i = 0; i < arguments.length; i++) {
localArgs.push(arguments[i]);
}
key = stringifyArray(localArgs);
}
return function(spec) {
var callable = typeof spec[key] === 'function' ? spec[key] : spec.default;
return callable ? callable() : undefined;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment