index.js 858 B

12345678910111213141516171819202122232425262728
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. function accesorString(value) {
  6. var childProperties = value.split(".");
  7. var length = childProperties.length;
  8. var propertyString = "global";
  9. var result = "";
  10. for(var i = 0; i < length; i++) {
  11. if(i > 0)
  12. result += "if(!" + propertyString + ") " + propertyString + " = {};\n";
  13. propertyString += "[" + JSON.stringify(childProperties[i]) + "]";
  14. }
  15. result += "module.exports = " + propertyString;
  16. return result;
  17. }
  18. module.exports = function() {};
  19. module.exports.pitch = function(remainingRequest) {
  20. this.cacheable && this.cacheable();
  21. if(!this.query) throw new Error("query parameter is missing");
  22. return accesorString(this.query.substr(1)) + " = " +
  23. "require(" + JSON.stringify("-!" + remainingRequest) + ");";
  24. };