extractUrlAndGlobal.js 531 B

123456789101112131415161718
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Sam Chen @chenxsan
  4. */
  5. "use strict";
  6. /**
  7. * @param {string} urlAndGlobal the script request
  8. * @returns {string[]} script url and its global variable
  9. */
  10. module.exports = function extractUrlAndGlobal(urlAndGlobal) {
  11. const index = urlAndGlobal.indexOf("@");
  12. if (index <= 0 || index === urlAndGlobal.length - 1) {
  13. throw new Error(`Invalid request "${urlAndGlobal}"`);
  14. }
  15. return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)];
  16. };