Last active
March 27, 2016 21:12
-
-
Save YurySolovyov/d6395fb5fa811d722578 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
"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